Error while providing file download in webpage

A

ashish_basran

Hello



I have to provide download of files in ASP.NET 2.0
I am using following lines of code.

try
{
Byte [] bytes = this.ContentController.GetFileContents(filePath);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=File" +
_fileExtension);
Response.AddHeader("Content-Length", bytes.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Buffer = true;
Response.BinaryWrite(bytes);
Response.Flush();
}
catch(FileNotFoundException fnfe)
{
this.ShowErrorMessage(this.GetErrorString(ResourceIdentifiers.DOCUMENT_FILE_NOT_FOUND_ERROR));
}
catch(Exception ex)
{
this.ShowErrorMessage(this.GetErrorString(ResourceIdentifiers.DOCUMENT_UNEXPECTED_ERROR));
}


Using above code, when one clicks on file link, a default download box
of IE appears. If user clicks on Save, the file gets saved on disk and
user can open that file. If user clicks on Open, it opens registered
application with file type and says, file not found. Using same code I
am able to open Word file but I cannot open Excel, PDF files.

Note: My application used Master pages, UIP Application Blocks. The
code written above is inside a user control which gets loaded on view
(webform) dynamically based on configration(xml) file.

Please can anyone suggest what could be going wrong in the piece of
code because of which I am not able to open Excel/PDF files.

Apprciate your help.

Thanks and regards,
Ashsih Basran
 
R

Ray Booysen

What do you mean you are "not able to open Excel/PDF files."

Is there an exception thrown, is the file saved incorrectly? Its
difficult to help out when we don't know the details.

Regards
Ray
 
A

ashish

When I click in open, it starts Excel, and shows message saying -
c:\documents.....\Temporary Internet
files\Content.IE5\OBFADGE\Test[1].xls could not be found.

The same code workd if I download .doc file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top