When downloading, if the downloaded file is a RAR compressed package, we usually only make one link, and the link address points to this compressed package. However, if you download an image file, this method won't work. Use the following sectionCodeYou can download images, Word documents, and other files.
Try
{
String Fullfilename = Server. mappath ( @" /Images/imgname.jpg " ); // Filename -- name of the file to be downloaded
System. Io. fileinfo downloadfile = New System. Io. 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. Name, 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
{
// File does not exist
}