Feb 23, 2012, 3:13 PM
[CLOSED] How to download a file in DirectEvent?
Hi,
I have a question that probably has to do with the recently closed thread at http://forums.ext.net/showthread.php...ng-BADRESPONSE.
Here's the fragments of my code:
Thanks,
Vadym
I have a question that probably has to do with the recently closed thread at http://forums.ext.net/showthread.php...ng-BADRESPONSE.
Here's the fragments of my code:
<ext:Button ID="ButtonView" runat="server" Text="View">
<DirectEvents>
<Click OnEvent="ButtonView_Click" IsUpload="true">
<EventMask ShowMask="true" />
<ExtraParams>
<ext:Parameter Name="Id" Value="#{GridPanel1}.getSelectionModel().getSelected().get('Id')"
Mode="Raw">
</ext:Parameter>
</ExtraParams>
</Click>
</DirectEvents>
</ext:Button>
protected void ButtonView_Click(object sender, DirectEventArgs e)
{
int id = Convert.ToInt32(e.ExtraParams["Id"]);
//Obtain the byte array from the database based on the document Id
byte[] docData=GetDocumentData();
string docName="Test.docx";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ContentType = "application/msword";
HttpContext.Current.Response.AddHeader("Accept-Ranges", "bytes");
HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}", docName));
HttpContext.Current.Response.AddHeader("Content-Length", docData.Length.ToString());
HttpContext.Current.Response.OutputStream.Write(docData, 0, docData.Length);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
I'm able to download and open the document OK. However, the event mask never disappears and I'm not sure overall whether clearing, flushing and ending the Response is the correct approach for the purpose. Please advise the best practice.Thanks,
Vadym
Last edited by Daniil; Feb 23, 2012 at 3:53 PM.
Reason: [CLOSED]