I have an application that creates an audio file. I need to provide a link that brings up the save dialog when cicked for users to save the file.
I have the download button setup as a link button. From my research it appears that to be able to force bringing up the save dialog, I need to add the following code:
Response.ContentType = "audio/wav";
Response.AppendHeader("Content-Disposition", "attachment; filename=blah.wav");
Response.WriteFile(@"blah.wav");
Response.End();
When I add this to the event handler of the link button, I get the error:
"Line: 4723
Error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near 'RIFF?WAVEfmt '."
So, I decided to try it out by creating an intermediate page that facilitates the download. On the Download linkbutton event handler, I added a Respose.Redirect
to this intermediate page and on the Page_Load of the page, I added the code snippet above. When setup this way, IE, blocks the download by saying:
"To help protect your security, Internet Explorer blocked his site from downloading files to your computer. Click here for options"
When I click and select "Download file", I do not get the Save dialog.
My questions: 1. Can I eliminate the intermediate page? 2. If I can't how do I not have IE prompt the user for action?