I have read many methods
It seems that all of them are converted by response.
Code
Public Void Open ()
{
String Fullfilename = "" ;
// ASP. NET File Download (the save file dialog box is displayed)
// Fileurl is the full name of the file with a path.
/*
String fileurl = URL;
System. Io. fileinfo = new system. Io. fileinfo (fileurl );
Response. Clear ();
Response. addheader ("content-disposition", "attachment; filename =" + server. urlencode (fileinfo. Name. tostring ()));
Response. addheader ("Content-Length", fileinfo. length. tostring ());
Response. contenttype = "application/octet-stream ";
Response. contentencoding = system. Text. encoding. default;
Response. writefile (fileurl );
*/
// No wrong version:
Try
{
String Filename = " . // Path // name of the book " ;
Filename = " . // Path // file name. Extension " ;
Fullfilename = Server. mappath (filename );
// Filename -- name of the file to be downloaded
Fileinfo downloadfile = New Fileinfo (fullfilename );
If (Downloadfile. exists)
{
Response. Clear ();
Response. clearheaders ();
Response. Buffer = False ;
Response. contenttype = " Application/octet-stream " ;
Response. appendheader ( " Content-Disposition " , " Attachment; filename = " + Httputility. urlencode (downloadfile. fullname, system. Text. encoding. ASCII ));
Response. appendheader ( " Content-Length " , Downloadfile. length. tostring ());
Response. writefile (downloadfile. fullname );
Response. Flush ();
Response. End ();
}
Else
{
// File does not exist
}
}
Catch
{
// An exception occurred while opening.
}
}