Downloading documents from an ASP.NET 2.0 page
-
Hello, I have following code for providing download of file. byte[] bytes = this.ContentController.GetFileContents(_filePath); Response.Clear(); Response.AddHeader("Content-Disposition", "attachment;filename=Document.pdf" ); Response.AddHeader("Content-Length", bytes.Length.ToString()); Response.ContentType = "*/*"; Response.BinaryWrite(bytes); This provides a messagebox on browser with Open/Save/Cancel button. When I click on save, this saves the document on the disk, and I can open that. But when I click on Open, this does not open the document. A prompt from PDF reader says, file not found. How can I getrid of this problem. Any help is appreciated. Thanks in advance.:)
- ashish
-
Hello, I have following code for providing download of file. byte[] bytes = this.ContentController.GetFileContents(_filePath); Response.Clear(); Response.AddHeader("Content-Disposition", "attachment;filename=Document.pdf" ); Response.AddHeader("Content-Length", bytes.Length.ToString()); Response.ContentType = "*/*"; Response.BinaryWrite(bytes); This provides a messagebox on browser with Open/Save/Cancel button. When I click on save, this saves the document on the disk, and I can open that. But when I click on Open, this does not open the document. A prompt from PDF reader says, file not found. How can I getrid of this problem. Any help is appreciated. Thanks in advance.:)
- ashish
You could try putting a Response.Flush() at the end of your code there.
-
You could try putting a Response.Flush() at the end of your code there.
Even after adding Response.Flush() I am getting the same problem. Additionally, I am haiving this eventhandller written in User control which is placed on a view (Web form). I am also using Masterpage and UIP Application Blocks.
- ashish