Error while providing file download in webpage
-
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, Ashish
-
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, Ashish
Response.ContentType = "application/vnd.ms-excel" Response.ContentType = "application/pdf"
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06
-
Response.ContentType = "application/vnd.ms-excel" Response.ContentType = "application/pdf"
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06
ToddHileHoffer, thanks for your help. I am still the same problem. Could anything else you can think of to getrid of this problem
- ashish
-
ToddHileHoffer, thanks for your help. I am still the same problem. Could anything else you can think of to getrid of this problem
- ashish
VB.NEt code that works from my old application. ' The following code writes the pdf file to the Client’s browser. Response.ClearContent() Response.ClearHeaders() Response.ContentType = "application/pdf" Response.WriteFile(Fname) 'String location of the file Response.Flush() Response.Close() 'delete the exported file from disk System.IO.File.Delete(Fname)
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06
-
VB.NEt code that works from my old application. ' The following code writes the pdf file to the Client’s browser. Response.ClearContent() Response.ClearHeaders() Response.ContentType = "application/pdf" Response.WriteFile(Fname) 'String location of the file Response.Flush() Response.Close() 'delete the exported file from disk System.IO.File.Delete(Fname)
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06
Seems I get the problem when I use UIPAB. Otherwise the same code works fine. Any idea what UIPAB does different.
- ashish