A friend asked me how to write a prompt box for download, as shown below:
Prompt box appears
String strfile = "F: \ a.doc"; // The Path depends on the actual situation
If (! System. Io. file. exists (strfile ))
{
Response. Write ("<script language = 'javascript '> alert ('Sorry, the file does not exist! '); </SCRIPT> ");
Return;
}
Response. Clear ();
Response. clearheaders ();
Response. charset = "gb2312 ";
Response. contentencoding = system. Text. encoding. utf8;
Response. contenttype = "application/octet-stream ";
Fileinfo Fi = new fileinfo (strfile );
Response. addheader ("content-disposition", "attachment; filename =" + httputility. urlencode (Fi. Name ));
Response. addheader ("Content-Length", Fi. length. tostring ());
Byte [] tmpbyte = new byte [1024*8];
Filestream FS = Fi. openread ();
Int count;
While (COUNT = FS. Read (tmpbyte, 0, tmpbyte. Length)> 0)
{
Response. binarywrite (tmpbyte );
Response. Flush ();
}
FS. Close ();
Response. End ();
open
string strfile = "F: \ a.doc" directly in the browser; // The Path depends on the actual situation
response. clear ();
response. clearheaders ();
response. charset = "gb2312";
response. contentencoding = system. text. encoding. utf8;
response. contenttype = "application/MSWord";
response. writefile (strfile);