ASP.NET下载诸如word,txt,图片等

try
   {
   FullFileName
= Server.MapPath(FileName);  //FileName--要下载的文件名
   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
{
    
//文件不存在
   }

   }

catch {
  
//文件不存在
}

你可能感兴趣的:(职场,it,word,Office,休闲)