Hi,
I need to implement downloading files in ASP.NET. My prototype is very
simple. I have a document "C:\FAQ.doc". I need to allow user to download
this file through browser. Below is a portion of my trial code:
private void Button1_Click(object sender, System.EventArgs e)
{
string filename = "FAQ.doc";
string filepath = "C:" + Path.DirectorySeparatorChar + filename;
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename="
+ filename);
Response.WriteFile(filepath);
Response.End();
}
The above code seems to be working. The download dialog or message box
(with Open, Save, Cancel button) does appear. I can save the document
successfully.
But when I try to open the document, I am running into an annoying
problem. If I click the "Open" button the first time, a second download
message box appears (the first disappears, or maybe it is the same one,
who knows). I have to click the "Open" button again. This time I can
really open the document. In short, I have to click the "Open" button
twice to open the document.
I have tested the code on both W2K and XP with .NET 1.1 on each. Same
thing happens.
Is this correct behavior? Is it something related to my code or the
browser setting (Actually I am giving very low security level for
intranet)?
I would really appreciate it if someone can give me a hand.
Michael
===================================
This list is hosted by DevelopMentor� http://www.develop.com
Some .NET courses you may be interested in:
Essential .NET: building applications and components with CSharp
August 30 - September 3, in Los Angeles
http://www.develop.com/courses/edotnet
View archives and manage your subscription(s) at http://discuss.develop.com