Showing posts with label file. Show all posts
Showing posts with label file. Show all posts

Thursday, March 29, 2012

Office 2007 documents to database, dynamically generate on demand

Hello, I am currently adding some document management functionality to a .Net 2.0 Web app (VB) where I take a file in, save the file to a SQL 2000 database (image datatype), and then allow users to browse and download these files.

This works great for most files my users use -- with the exception of Office 2k7 files

I am able to upload a file, read the file into a binary array and insert into a new record in the database.

However, when I retrieve the binary array and attempt to output the file, there is a problem.

The user is prompted to open or save the file per-usual, however when Word 2007 tries to open the file, there is an error message that says:

"The Office Open XML file Test.docx cannot be opened because there are problems with the contents"

Under "Details" it says:

"The file is corrupt and cannot be opened"

If I click "OK", I am asked whether I want to have Word recover the contents of the document.

If I click "Yes" my document opens and all of the original content is there.

I have been doing some reading, and I know that the new Office 2007 files are really .zip files with XML files that contain formatting and content information.

What I would like to know is, is there a reason why I can't save these files to the database as I have been, and if so, is there a "right" way to do this?

Hi,

Based on my understanding, the users upload the word 2007 files into database and download them with your asp.net application. When you try to open the file that is downloaded, you get the error message above. If I have misunderstood you, please feel free to let me know.

To better understand your issue, could you please confirm the following information:

When we write the file to the client, we should make sure that file doesn't contain HTML-tag. We can add Response.End() right after writing and stop further processing of the ASP.NET page. For more information, seehttp://blog.benday.com/archive/2005/08/09/2705.aspx.


Yes, you have summarized what I am doing correctly.

I have been looking into this in more detail, and after using Hex Workshop, I compared the original file and the streamed file. The streamed file contained 1 extra byte.

I reviewed my code and found that the size of the file in the database was the same as the original, so I reviewed my code in the download.aspx code-behind (the file that streams the requested document).

I had read about this earlier, so I knew not to have any HTML in the aspx.

However, it seems that the Content-Length of the file is zero-based, so when I was setting Content-Length to equal the value I had in the database, an extra byte was being added.

When I set Content-Length to equal the size of the file (in bytes) - 1, I no longer received the error.

Ex:

Dim File As New EO.Library.File(CInt(Request("file")))
Dim _BinaryLength = (CInt(File.Binary.Length) - 1)

Response.Clear()
Response.Buffer = True
Response.AddHeader("Content-Disposition", "attachment;filename=" & File.Name)
Response.AddHeader("Content-Length", CInt(_BinaryLength))
Response.ContentType = File.ContentType
Response.BinaryWrite(File.Binary)
Response.End()

Office Toolbar Css

Does anyone know where I download a css file which mimics Office style
toolbars etc. I'm rubbish at webdesign and I just want my pages to look
professional. Regards, Chris.I googled toolbar controls, got back a few thousand.

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-----------------

"Chris" <nospam@.btinternet.com> wrote in message
news:Ow30ukfeGHA.3888@.TK2MSFTNGP02.phx.gbl...
> Does anyone know where I download a css file which mimics Office style
> toolbars etc. I'm rubbish at webdesign and I just want my pages to look
> professional. Regards, Chris.
I wasn't thinking of an actual control just if had some css files to format
things like buttons and menu bars that come with .net 2. Make them look a
bit more professional.

"Alvin Bruney" <www.lulu.com/owc> wrote in message
news:eTE4ZDneGHA.3996@.TK2MSFTNGP04.phx.gbl...
>I googled toolbar controls, got back a few thousand.
> --
> ________________________
> Warm regards,
> Alvin Bruney [MVP ASP.NET]
> [Shameless Author plug]
> Professional VSTO.NET - Wrox/Wiley
> The O.W.C. Black Book with .NET
> www.lulu.com/owc, Amazon
> Blog: http://www.msmvps.com/blogs/alvin
> -----------------
> "Chris" <nospam@.btinternet.com> wrote in message
> news:Ow30ukfeGHA.3888@.TK2MSFTNGP02.phx.gbl...
>> Does anyone know where I download a css file which mimics Office style
>> toolbars etc. I'm rubbish at webdesign and I just want my pages to look
>> professional. Regards, Chris.
>>

Office Toolbar Css

Does anyone know where I download a css file which mimics Office style
toolbars etc. I'm rubbish at webdesign and I just want my pages to look
professional. Regards, Chris.I googled toolbar controls, got back a few thousand.
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
----
"Chris" <nospam@.btinternet.com> wrote in message
news:Ow30ukfeGHA.3888@.TK2MSFTNGP02.phx.gbl...
> Does anyone know where I download a css file which mimics Office style
> toolbars etc. I'm rubbish at webdesign and I just want my pages to look
> professional. Regards, Chris.
>
I wasn't thinking of an actual control just if had some css files to format
things like buttons and menu bars that come with .net 2. Make them look a
bit more professional.
"Alvin Bruney" <www.lulu.com/owc> wrote in message
news:eTE4ZDneGHA.3996@.TK2MSFTNGP04.phx.gbl...
>I googled toolbar controls, got back a few thousand.
> --
> ________________________
> Warm regards,
> Alvin Bruney [MVP ASP.NET]
> [Shameless Author plug]
> Professional VSTO.NET - Wrox/Wiley
> The O.W.C. Black Book with .NET
> www.lulu.com/owc, Amazon
> Blog: http://www.msmvps.com/blogs/alvin
> ----
> "Chris" <nospam@.btinternet.com> wrote in message
> news:Ow30ukfeGHA.3888@.TK2MSFTNGP02.phx.gbl...
>

Monday, March 26, 2012

ok to use file upload in showModalDialog page?

I am using the javascript showModalDialog function to open a file upload
window. The function opens a page which contains a usercontrol housing the
file upload stuff. The control works fine when tested independently, but
when called through showModalDialog on submit, another window is opened (a
fullsize version of the page passed to showModalDialog).

Is this a bug, by design, or have I made some sort of error?

thanksThis is by design. The work around is to use IFRAME.

Instead of directly calling your fileupload aspx page from main page, you
will need to create an HTML /ASPX page with an IFRAME and set the IFRAME
source as fileupload aspx page

<IFRAME width='100%' height='100%' NAME="framHostUpload" src="http://pics.10026.com/?src=fileupload.aspx"
</IFRAME
"Sarah" wrote:

> I am using the javascript showModalDialog function to open a file upload
> window. The function opens a page which contains a usercontrol housing the
> file upload stuff. The control works fine when tested independently, but
> when called through showModalDialog on submit, another window is opened (a
> fullsize version of the page passed to showModalDialog).
> Is this a bug, by design, or have I made some sort of error?
> thanks
>
since no one answered so far,

There is a bug/design feature of this function which means the
postback(submit) launches a new window of the calling page. There is a
workaround for it though. I don't have the detailss, but I think google for
"showModalDialog postback" should turn it up.

"Sarah" <Sarah.Cloud@.nospam.hotmail.com> wrote in message
news:OBjNepx0FHA.1264@.tk2msftngp13.phx.gbl...
> I am using the javascript showModalDialog function to open a file upload
> window. The function opens a page which contains a usercontrol housing the
> file upload stuff. The control works fine when tested independently, but
> when called through showModalDialog on submit, another window is opened (a
> fullsize version of the page passed to showModalDialog).
> Is this a bug, by design, or have I made some sort of error?
> thanks

ok to use file upload in showModalDialog page?

I am using the javascript showModalDialog function to open a file upload
window. The function opens a page which contains a usercontrol housing the
file upload stuff. The control works fine when tested independently, but
when called through showModalDialog on submit, another window is opened (a
fullsize version of the page passed to showModalDialog).
Is this a bug, by design, or have I made some sort of error?
thanksThis is by design. The work around is to use IFRAME.
Instead of directly calling your fileupload aspx page from main page, you
will need to create an HTML /ASPX page with an IFRAME and set the IFRAME
source as fileupload aspx page
<IFRAME width='100%' height='100%' NAME="framHostUpload" src="http://pics.10026.com/?src=fileupload.asp
x"
</IFRAME>
"Sarah" wrote:

> I am using the javascript showModalDialog function to open a file upload
> window. The function opens a page which contains a usercontrol housing the
> file upload stuff. The control works fine when tested independently, but
> when called through showModalDialog on submit, another window is opened (a
> fullsize version of the page passed to showModalDialog).
> Is this a bug, by design, or have I made some sort of error?
> thanks
>
>
since no one answered so far,
There is a bug/design feature of this function which means the
postback(submit) launches a new window of the calling page. There is a
workaround for it though. I don't have the detailss, but I think google for
"showModalDialog postback" should turn it up.
"Sarah" <Sarah.Cloud@.nospam.hotmail.com> wrote in message
news:OBjNepx0FHA.1264@.tk2msftngp13.phx.gbl...
> I am using the javascript showModalDialog function to open a file upload
> window. The function opens a page which contains a usercontrol housing the
> file upload stuff. The control works fine when tested independently, but
> when called through showModalDialog on submit, another window is opened (a
> fullsize version of the page passed to showModalDialog).
> Is this a bug, by design, or have I made some sort of error?
> thanks
>

ok, now it's working. the question is if what i did is correct

I added to the ascx file the following line:
Protected WithEvents cls1 As cls1
where cls1 is the class name of the aspx page and in the
ascx Page_Init i wrote:
cls1 = MyBase.Page
It works fine but - is it the correct way?
Thanks

>--Original Message--
>I have a user control inside an aspx page. I was able to
>create a Public property inside the ascx file and call it
>from the aspx but whatever I do, I can't find the way to
>cause an event from inside the ascx file to call any
>function/sub/property etc. The error I'm getting
>is "Reference to a non-shared member required an object
>reference".
>
>.
>Check out: http://www.openmymind.net/communication/index.html
it takes about communication between a page and a user control including how
to do it via events.
Karl
MY ASP.Net tutorials
http://www.openmymind.net/
"comp" <nice_guy@.inter.net.il> wrote in message
news:95ee01c4d348$81edfc20$a601280a@.phx.gbl...
> I added to the ascx file the following line:
> Protected WithEvents cls1 As cls1
> where cls1 is the class name of the aspx page and in the
> ascx Page_Init i wrote:
> cls1 = MyBase.Page
> It works fine but - is it the correct way?
> Thanks
>

Saturday, March 24, 2012

Old code file used when debugging web application

I am developing using VS 2005 SP1. The problem i faced is when debugging is, the debugger seem to be getting the old javascript file even after i clean the solution, rebuild it, restart the computer.Sad

What more do i need to do?
Anyone encounter this problem before?
or is there any place i can delete the file? cause i don't know where the files is resided.

Thanks...

Delete browser cache, temporary internet files from your browser.

Thanks


Dear e_screw,

you were right on...
i have did that before, and did not realized it was the solution.. because i did a few other things as well..

thanks for saving my days...

Thursday, March 22, 2012

OleDbConnection - cannot read Excel file

I have the following code in an asp.net page:

System.Data.OleDb.OleDbConnection cn = new
System.Data.OleDb.OleDbConnection();
cn.ConnectionString = @dotnet.itags.org."Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=\\myservername\ExcelTemp\Temp.xls;Extended Properties=Excel
8.0";
cn.Open();
cn.Close();

My IIS site (on localhost) is set to not allow anonymous users,
integrated security. My web.config has the following for impersonation:

<identity impersonate="true" userName="mydomain\workerprocess"
password="mypassword" /
When running this page, I get the helpful
System.Data.OleDb.OleDbException: Unspecified error. There is no record
in the security Event Log of MyServerName that access was attempted.

When I change web.config to:
<identity impersonate="true" /
I get: System.Data.OleDb.OleDbException: The Microsoft Jet database
engine cannot open the file '\\myservername\ExcelTemp\Temp.xls'. It is
already opened exclusively by another user, or you need permission to
view its data.

The security event log records four back-to-back login success audits
coming from my computer, but the user is ANONYMOUS LOGIN. For example:

Event Type:Success Audit
Event Source:Security
Event Category:Logon/Logoff
Event ID:540
Date:5/12/2006
Time:1:43:31 PM
User:NT AUTHORITY\ANONYMOUS LOGON
Computer:MYSERVERNAME
Description:
Successful Network Logon:
User Name:
Domain:
Logon ID:(0x0,0xA685FE4E)
Logon Type:3
Logon Process:NtLmSsp
Authentication Package:NTLM
Workstation Name:MYCOMPUTERNAME
Logon GUID:-
Caller User Name:-
Caller Domain:-
Caller Logon ID:-
Caller Process ID: -
Transited Services: -
Source Network Address:10.0.100.100
Source Port:0

Any ideas how to actually pass the identity being impersonated through
the OleDbConnection? This application reads several SQL Server
databases and everything is working just fine. But I need to read an
Excel file and can't get it to work. Any help would be greatly
appreciated.As with Access databases, a TEMP directory being used. The account under
which the web site is running will probably need full access to the "TEMP"
directory being used. It may be the one under "documents and
settings"\<machinename>\ASPNET\"Local Settings"\Temp...

--
Brad

"Software is like melted pudding..."
Brad, your suggestion worked. Thank you so much for your help.

Talk about misleading error messages...

Dave

OleDbConnection - cannot read Excel file

I have the following code in an asp.net page:
System.Data.OleDb.OleDbConnection cn = new
System.Data.OleDb.OleDbConnection();
cn.ConnectionString = @dotnet.itags.org."Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=\\myservername\ExcelTemp\Temp.xls;Extended Properties=Excel
8.0";
cn.Open();
cn.Close();
My IIS site (on localhost) is set to not allow anonymous users,
integrated security. My web.config has the following for impersonation:
<identity impersonate="true" userName="mydomain\workerprocess"
password="mypassword" />
When running this page, I get the helpful
System.Data.OleDb.OleDbException: Unspecified error. There is no record
in the security Event Log of MyServerName that access was attempted.
When I change web.config to:
<identity impersonate="true" />
I get: System.Data.OleDb.OleDbException: The Microsoft Jet database
engine cannot open the file '\\myservername\ExcelTemp\Temp.xls'. It is
already opened exclusively by another user, or you need permission to
view its data.
The security event log records four back-to-back login success audits
coming from my computer, but the user is ANONYMOUS LOGIN. For example:
Event Type: Success Audit
Event Source: Security
Event Category: Logon/Logoff
Event ID: 540
Date: 5/12/2006
Time: 1:43:31 PM
User: NT AUTHORITY\ANONYMOUS LOGON
Computer: MYSERVERNAME
Description:
Successful Network Logon:
User Name:
Domain:
Logon ID: (0x0,0xA685FE4E)
Logon Type: 3
Logon Process: NtLmSsp
Authentication Package: NTLM
Workstation Name: MYCOMPUTERNAME
Logon GUID: -
Caller User Name: -
Caller Domain: -
Caller Logon ID: -
Caller Process ID: -
Transited Services: -
Source Network Address: 10.0.100.100
Source Port: 0
Any ideas how to actually pass the identity being impersonated through
the OleDbConnection? This application reads several SQL Server
databases and everything is working just fine. But I need to read an
Excel file and can't get it to work. Any help would be greatly
appreciated.As with Access databases, a TEMP directory being used. The account under
which the web site is running will probably need full access to the "TEMP"
directory being used. It may be the one under "documents and
settings"\<machinename>\ASPNET\"Local Settings"\Temp...
Brad
"Software is like melted pudding..."
Brad, your suggestion worked. Thank you so much for your help.
Talk about misleading error messages...
Dave

Friday, March 16, 2012

On download, how to open .XSD file in its XML format instead Schema?

Hi,
I have one download link in my webform. On click, i have specified .XSD file to open. But it opens in Microsoft .Net Environment, and in Schema format.
My prob is, i want to open that .XSD file's Xml in Browser (Internet Explorer).
Thanx in advance.

I noticed you asked this in the Web Forms threadhttp://forums.asp.net/988565/ShowPost.aspx.
Have you tried that solution?