How can I get my code to NOT display two "Open/Save/Cancel/More Info" dialog boxes when using the "Response.WriteFile" method to download a file to IE
I've asked about this before and didn't get a satisfactory answer (check your browser) so now that I've had the time to set up a reasonable little test that I can post somewhere, I'll try again.
The app I've written has three ASPX pages. One is a combined page which writes a little text file to the "LocalApplicationData" directory in the "Page_Load" method and then when you click a "Download" button, it uses the inherited Response object to write the file. The other two pages work together. The first page of that pair writes the text file and contains two "Download" buttons. One button is part of a form which uses old HTML technology to Post to the second page which does the download and the other button does a "Response.Redirect" to go to the other page to do the download. The other page has no HTML--just code in its Page_Load method to figure out the name of the file it is supposed to download and then it calls a "Download" method to use the Response object to write the file
Essentially, the pages try three methods for doing the download. Only one works properly (the last one mentioned, above--using the Response.Redirect from one page to get to the other.) The other methods give the double-open dialog
I've submitted a zip file to the "GotDotNet" website and got the message that it will take 72 hours for me to find out if they've accepted it. I can also email it or post it somewhere else (suggestions?)
Oh yeah. One more thing. I thought of doing it these different ways when I noticed that some earlier VB code I'd written had worked the way I wanted. It turns out it was using the last method. So i did an experiment. I wrote the code in C# using the three methods and then did it again in VB. I get the same results with both languages (as I would have expected.
Any ideas on getting the other methods to work properly
The "download" part of the code looks like the following (in C#)
protected void Download(
string sNameOnly
sNameOnly = sFullPath.Substring(sFullPath.LastIndexOf('\\') + 1)
System.IO.FileInfo fi = new System.IO.FileInfo(sFullPath)
String sFileLength = fi.Length.ToString()
Response.ClearHeaders()
Response.Clear()
Response.ContentType = "text/plain"
Response.Charset = ""
Response.AddHeader("Content-Disposition", "attachment;filename=" + sFileName)
Response.AddHeader("Content-Length", sFileLength)
Response.WriteFile(sFullPath)
Response.Flush()
Response.Close()
}