Dec 14, 2010, 2:33 PM
Problem in downloading a PDF file with Response
I create w PDF file and I want user to be allowed to download it. PDF is correct, because it works when I save it with FileStream.
But when I use following method
Status Code: 200 Status Text: BADRESPONSE
I have DirectEvents enabled in web.config
The method is invoked in button click
But when I use following method
// Save the document...
MemoryStream stream = new MemoryStream();
renderer.PdfDocument.Save(stream, false);
byte[] biteArray = new byte[stream.Length];
//Set pointer to the beginning of the stream
stream.Position = 0;
//Read the entire stream
stream.Read(biteArray, 0, (int)stream.Length);
Response.Clear();
Response.ClearHeaders();
//Send the file to the output stream
Response.Buffer = true;
Response.AddHeader("Content-Length", biteArray.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment; filename= " + Server.HtmlEncode("test.pdf"));
//Set the output stream to the correct content type (PDF).
Response.ContentType = "application/pdf";
//Output the file
Response.BinaryWrite(biteArray);
//Flushing the Response to display the serialized data
//to the client browser.
Response.Flush();
Response.End();
I receive an Request Failure:Status Code: 200 Status Text: BADRESPONSE
I have DirectEvents enabled in web.config
<httpModules>
<add name="DirectRequestModule" type="Ext.Net.DirectRequestModule, Ext.Net" />
</httpModules>
When I used exactly the same code in pure ASP .NET without ext, everything works fine.The method is invoked in button click
<ext:Button ID="m_btGenerate" runat="server" Text="Generate">
<DirectEvents>
<Click OnEvent="m_btGenerate_Click" Before="if(#{PdfFormPanel}.getForm().isValid()){return true;}else{Ext.Msg.show({icon: Ext.MessageBox.ERROR, msg: 'Nie wybrano daty.', buttons:Ext.Msg.OK}); return false;}" >
<EventMask ShowMask="true" />
</Click>
</DirectEvents>
</ext:Button>
Last edited by reiben; Dec 14, 2010 at 2:44 PM.