下载附件代码
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/octet-stream ; Charset=UTF8";
Response.CacheControl = "public";
string realFileName = fileName.IndexOf('_') > 0 ? fileName.Remove(0, fileName.IndexOf('_') + 1) : fileName;
Response.AddHeader("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode(realFileName, System.Text.Encoding.GetEncoding("UTF-8")) + "\"");
Response.AddHeader("Content-Length", fileSize.ToString());
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.Filter.Close();
#region
// int everySize =Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["EverySize"].ToString()); //每次读取配置文件中分块下载的大小
// byte[] buffers=new byte[everySize];
//// System.IO.FileStream istream = System.IO.File.OpenRead(fileInfo.FullName);
// using (System.IO.FileStream istream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.Read))
// {
// long dataLenghtRead = istream.Length;
// while (dataLenghtRead > 0 && Response.IsClientConnected)
// {
// int readLength = istream.Read(buffers, 0, everySize);
// Response.OutputStream.Write(buffers, 0, readLength);
// Response.Flush();
// dataLenghtRead = dataLenghtRead - readLength;
// }
// }
/////Response.WriteFile(fileInfo.FullName);
//istream.Close();
//istream.Dispose();
#endregion