Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->try
{
string FullFileName = Server.MapPath(@"/images/imgname.jpg"); //FileName--要下载的文件名
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
{
//文件不存在
}
}
catch
{
//文件不存在
}