通用文件下载

 string strFileName = Request.QueryString["upFileName"];

 //得到文件路径
 string strPath = Server.MapPath("~/UpdateSoft/")+strFileName;
 if(File.Exists(strPath))
 {
    FileStream fsUpload = new FileStream(strPath, FileMode.Open);
    byte [] bytesUpload=new byte[(int)fsUpload.Length];
    fsUpload.Read(bytesUpload, 0, bytesUpload.Length);
    fsUpload.Close();
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition", "attachment;    filename="+HttpUtility.UrlEncode (strFileName,System.Text.Encoding.UTF8));
   Response.BinaryWrite(bytesUpload);
   Response.Flush();
   Response.End();
  }
   else 
   {
    Response.Write("<script language=javascript>alert('文件已经不存在!')</script>");
    }

你可能感兴趣的:(String,byte)