asp.net| download did not straightened for a long time, there are many cases on the Internet are the same: IE supported files will be opened directly, and other files such as zip and other documents do not recognize, will pop up to download or open the dialog box.
Suddenly think is not what the problem of file screening, sure enough to write the file before the filter can be used as an attachment.
VB.net:
Dim filename as String = "A.txt"
If filename <> "" Then
Dim path as String = Server.MapPath (filename)
Dim file as System.IO.FileInfo = New System.IO.FileInfo (path)
If file. Exists Then
Response.Clear ()
Response.AddHeader ("Content-disposition", "attachment; Filename= "+ file. Name)
Response.AddHeader ("Content-length", file. Length.tostring ())
Response.ContentType = "Application/octet-stream"
Response.Filter.Close ()
Response.WriteFile (file. FullName)
Response.End ()
Else
Response.Write ("This file does not exist.")
End If
End If
----------------------------------------------------------------
C#:
string filename = "A.txt";
if (filename!= "")
{
String path = Server.MapPath (filename);
System.IO.FileInfo file = new System.IO.FileInfo (path);
if (file. Exists)
{
Response.Clear ();
Response.AddHeader ("Content-disposition", "attachment; Filename= "+ file. Name);
Response.AddHeader ("Content-length", file. Length.tostring ());
Response.ContentType = "Application/octet-stream";
Response.Filter.Close ();
Response.WriteFile (file. FullName);
Response.End ();
}
Else
{
Response.Write ("This file does not exist.");
}
}