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
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