I have several applications that can successfully display ‘standard’ documents via a browser. I use the normal way that most samples on the internet uses in order to display documents, i.e.
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ClearContent();
response.ClearHeaders();
response.Buffer = true;
response.ContentType = "application/pdf";
response.AddHeader("Content-Disposition", "attachment;filename=file.pdf";
response.BinaryWrite(SomeBinaryArrayObject);
response.Flush();
response.End();
However, on my current application, this is being called from an UpdatePanel and this seems to cause an AJAX error (as I found out googling as well):
Check here for the error message I received
I would like to know if there is any OTHER way to call up documents from a browser, other than using Response.write, or is there any way around the AJAX/Response.Write issue? I would prefer them opening in the browser, but if they opened in an associated application, that would be fine too, most if not all our clients have things like Adobe and MS Office installed in any case.
Any help would be welcome!
There isn’t any other way to call up documents in the browser (otherwise it would be a huge security issue). The only way around is to add your download control as an UpdatePanel Postback trigger. That causes a full postback and allows the browser to download and/or activate the associated application.
Another solution might be to use flash or java applets.
Update: In case you your postback control in inside a gridview, you don’t need to cause a full post back on all controls in the grid, you can always trigger only on the control that you need it on. On the rowdatabound event, search for the control and add it to the triggers as follows: