1:
<A href = ".../images/0008011731.jpg"> download the image </a> <a href =" .txt "> download TXT </a>
These two download methods are non-pop-up box. They can only open files through IE, rather than reminding users whether to save the file type.
2: the pop-up dialog box prompts you whether to save the file. There are two ways: ashx and Method
Public void processrequest (httpcontext context)
{
String name = "d :\\ abc.txt ";
// System. Io. fileinfo afile = new system. Io. fileinfo (name );
// String NA = path. getfilename (name );
// Context. response. Clear ();
// Context. response. clearheaders ();
// Context. response. bufferoutput = false;
// Context. response. contenttype = "application/octet-stream ";
Context. response. appendheader ("content-disposition", "attachment?filename=abc.txt ");
// Context. response. appendheader ("content-disposition", "attachment; filename =" + httputility. urlencode (Na, system. Text. encoding. utf8 ));
// Context. response. addheader ("Content-Length", afile. length. tostring ());
Context. response. writefile (name );
// Context. response. Flush ();
// Context. response. End ();
}
Public bool isreusable
{
Get
{
Return false;
}
}
Private void outputfile (string filepath)
{
Filestream FS = file. openread (server. mappath (filepath ));
Binaryreader BR = new binaryreader (FS );
Byte [] filedata = new byte [fs. Length];
BR. Read (filedata, 0, filedata. Length );
Response. Clear ();
Response. clearheaders ();
Response. bufferoutput = false;
Response. contenttype = "application/force-download ";
Response. addheader ("content-Disposition:", "attachment; filename =" + httputility. urlencode (path. getfilename (filepath), system. Text. encoding. utf8 ));
Response. addheader ("Content-Length", filedata. length. tostring ());
Response. binarywrite (filedata );
Response. Flush ();
BR. Close ();
FS. Close ();
Response. End ();
}