i have page list can download xml files, there server of company below xml file page's html together. xml on download code works on servers application installed except server. method downloading file follows:
public void streamfiletobrowser(string sfilename, byte[] filebytes, string ext) { httpcontext context = httpcontext.current; context.response.buffer = false; context.response.clear(); context.response.clearheaders(); context.response.clearcontent(); context.response.appendheader("content-length", filebytes.length.tostring()); context.response.contenttype = "application/octet-stream";//string.format("application/{0}", ext); context.response.appendheader("content-disposition", "attachment; filename=" + sfilename); context.response.binarywrite(filebytes); }
any alternative way force file download?
edit
this method called when user click on download button.
after write file output. should end response calling:
context.applicationinstance.completerequest();
this prevents further being written response. isn't necessary if separate out xml download logic separate handler. when have logic both, can run issues.
Comments
Post a Comment