System.IO.FileInfo DownloadFile = new System.IO.FileInfo(fileName);
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.ClearHeaders();
System.Web.HttpContext.Current.Response.Buffer=false;
System.Web.HttpContext.Current.Response.ContentType="application/octet-stream";
System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=" +System.Web.HttpUtility.UrlEncode(DownloadFile.FullName,System.Text.Encoding.UTF8));
System.Web.HttpContext.Current.Response.AppendHeader("Content-Length",DownloadFile.Length.ToString());
System.Web.HttpContext.Current.Response.WriteFile(DownloadFile.FullName);
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.End();
7 个解决方案
#1
up
#2
#3
public static void DownloadFile(string physicalFilePath)
{
FileStream stream=null;
stream = new FileStream(physicalFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
int bufSize = (int)stream.Length;
byte[] buf = new byte[bufSize];
int bytesRead = stream.Read(buf, 0, bufSize);
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename="+System.IO.Path.GetFileName(physicalFilePath));
HttpContext.Current.Response.OutputStream.Write(buf, 0, bytesRead);
HttpContext.Current.Response.End();
}
{
FileStream stream=null;
stream = new FileStream(physicalFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
int bufSize = (int)stream.Length;
byte[] buf = new byte[bufSize];
int bytesRead = stream.Read(buf, 0, bufSize);
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename="+System.IO.Path.GetFileName(physicalFilePath));
HttpContext.Current.Response.OutputStream.Write(buf, 0, bytesRead);
HttpContext.Current.Response.End();
}
#4
if(!IsPostBack)
{
string s = Request.QueryString["filename"];
string filename = Server.MapPath("../uploadfile/" + s);
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + Request.QueryString["filename"]);
Response.WriteFile(filename);
Response.End();
DataBind();
}
#5
做个标记,关注
#6
点击这个:http://lhq96.bj02.host.35.com/xiazai.aspx看看那个下载会是哪儿出错了?
#7
THYZM() ,你给的链接在我这里可以下载。
我也遇到过类似的情况,有的IE可以实现下载功能有的就不行。个人认为使用你这种方法可能还要考虑IE的具体设置
我也遇到过类似的情况,有的IE可以实现下载功能有的就不行。个人认为使用你这种方法可能还要考虑IE的具体设置
#1
up
#2
#3
public static void DownloadFile(string physicalFilePath)
{
FileStream stream=null;
stream = new FileStream(physicalFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
int bufSize = (int)stream.Length;
byte[] buf = new byte[bufSize];
int bytesRead = stream.Read(buf, 0, bufSize);
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename="+System.IO.Path.GetFileName(physicalFilePath));
HttpContext.Current.Response.OutputStream.Write(buf, 0, bytesRead);
HttpContext.Current.Response.End();
}
{
FileStream stream=null;
stream = new FileStream(physicalFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
int bufSize = (int)stream.Length;
byte[] buf = new byte[bufSize];
int bytesRead = stream.Read(buf, 0, bufSize);
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename="+System.IO.Path.GetFileName(physicalFilePath));
HttpContext.Current.Response.OutputStream.Write(buf, 0, bytesRead);
HttpContext.Current.Response.End();
}
#4
if(!IsPostBack)
{
string s = Request.QueryString["filename"];
string filename = Server.MapPath("../uploadfile/" + s);
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + Request.QueryString["filename"]);
Response.WriteFile(filename);
Response.End();
DataBind();
}
#5
做个标记,关注
#6
点击这个:http://lhq96.bj02.host.35.com/xiazai.aspx看看那个下载会是哪儿出错了?
#7
THYZM() ,你给的链接在我这里可以下载。
我也遇到过类似的情况,有的IE可以实现下载功能有的就不行。个人认为使用你这种方法可能还要考虑IE的具体设置
我也遇到过类似的情况,有的IE可以实现下载功能有的就不行。个人认为使用你这种方法可能还要考虑IE的具体设置