try
{
iStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
long dataToRead = iStream.Length;
HttpContext.Current.Response.ContentType = ContentType;
//HttpContext.Current.Response.ClearHeaders();
//HttpContext.Current.Response.AppendHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
//HttpContext.Current.Response.AppendHeader("Pragma", "public");
//HttpContext.Current.Response.AppendHeader("Cache-Control", "public");
//HttpContext.Current.Response.Expires = 0;
//HttpContext.Current.Response.CacheControl = "public";
//HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddMinutes(30));
//HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public); //在IE下重编码fileName,在火狐下就不用了!
if (Request.UserAgent.IndexOf("MSIE") > -1)
{
HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", this.Server.UrlPathEncode(fileName + ".xls"), Path.GetExtension(filePath))); }
else
{
HttpContext.Current.Response.AddHeader("Content-Disposition", string.Concat("attachment; filename=", fileName, Path.GetExtension(filePath)));
}
while (dataToRead > 0)
{
if (HttpContext.Current.Response.IsClientConnected)
{
int length = iStream.Read(buffer, 0, buffersize);
HttpContext.Current.Response.OutputStream.Write(buffer, 0, length);
HttpContext.Current.Response.Flush(); buffer = new Byte[buffersize];
dataToRead = dataToRead - length;
}
else
{
dataToRead = -1;
}
}
}
catch (Exception)
{
SetAlertMessage("文件下载时出现错误!");
}
{
iStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
long dataToRead = iStream.Length;
HttpContext.Current.Response.ContentType = ContentType;
//HttpContext.Current.Response.ClearHeaders();
//HttpContext.Current.Response.AppendHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
//HttpContext.Current.Response.AppendHeader("Pragma", "public");
//HttpContext.Current.Response.AppendHeader("Cache-Control", "public");
//HttpContext.Current.Response.Expires = 0;
//HttpContext.Current.Response.CacheControl = "public";
//HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddMinutes(30));
//HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public); //在IE下重编码fileName,在火狐下就不用了!
if (Request.UserAgent.IndexOf("MSIE") > -1)
{
HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", this.Server.UrlPathEncode(fileName + ".xls"), Path.GetExtension(filePath))); }
else
{
HttpContext.Current.Response.AddHeader("Content-Disposition", string.Concat("attachment; filename=", fileName, Path.GetExtension(filePath)));
}
while (dataToRead > 0)
{
if (HttpContext.Current.Response.IsClientConnected)
{
int length = iStream.Read(buffer, 0, buffersize);
HttpContext.Current.Response.OutputStream.Write(buffer, 0, length);
HttpContext.Current.Response.Flush(); buffer = new Byte[buffersize];
dataToRead = dataToRead - length;
}
else
{
dataToRead = -1;
}
}
}
catch (Exception)
{
SetAlertMessage("文件下载时出现错误!");
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货