我查了百度 下载的办法是
FileInfo fileInfo = new FileInfo(@"F:\1111\WebApplication1\WebApplication1\Upload\RedGate.Licensing.rar");
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=" + Server.UrlEncode(fileInfo.Name.ToString()));
Response.AddHeader("content-length", fileInfo.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = Encoding.Default;
Response.WriteFile(@"F:\1111\WebApplication1\WebApplication1\Upload\RedGate.Licensing.rar");
但是我现在是以Ajax请求的方式去下载这个文件 这样写对不对呢
context.Response.ContentType = "text/plain";
try
{
string id = context.Request["id"].ToString();
Model.File mf = new Model.File();
BLL.NRBLL bn = new NRBLL();
Guid guid = new Guid(id);
mf.Fileid = guid;
if (bn.FN_SerchResPath(mf) != null)
{
FileInfo fileInfo = new FileInfo(bn.FN_SerchResPath(mf).Tables["t_file"].Rows[0]["FilePath"].ToString());
context.Response.Clear();
context.Response.AddHeader("content-disposition", "attachment;filename=" + context.Server.UrlEncode(fileInfo.Name.ToString()));
context.Response.AddHeader("content-length", fileInfo.Length.ToString());
context.Response.ContentType = "application/octet-stream";
context.Response.ContentEncoding = Encoding.Default;
context.Response.WriteFile(bn.FN_SerchResPath(mf).Tables["t_file"].Rows[0]["FilePath"].ToString());
context.Response.Write("0");
}
else
{
context.Response.Write("1");
}
}
catch (Exception)
{ throw;
}
下载失败了 还是说我这个办法实现不了HTTP的下载
FileInfo fileInfo = new FileInfo(@"F:\1111\WebApplication1\WebApplication1\Upload\RedGate.Licensing.rar");
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=" + Server.UrlEncode(fileInfo.Name.ToString()));
Response.AddHeader("content-length", fileInfo.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = Encoding.Default;
Response.WriteFile(@"F:\1111\WebApplication1\WebApplication1\Upload\RedGate.Licensing.rar");
但是我现在是以Ajax请求的方式去下载这个文件 这样写对不对呢
context.Response.ContentType = "text/plain";
try
{
string id = context.Request["id"].ToString();
Model.File mf = new Model.File();
BLL.NRBLL bn = new NRBLL();
Guid guid = new Guid(id);
mf.Fileid = guid;
if (bn.FN_SerchResPath(mf) != null)
{
FileInfo fileInfo = new FileInfo(bn.FN_SerchResPath(mf).Tables["t_file"].Rows[0]["FilePath"].ToString());
context.Response.Clear();
context.Response.AddHeader("content-disposition", "attachment;filename=" + context.Server.UrlEncode(fileInfo.Name.ToString()));
context.Response.AddHeader("content-length", fileInfo.Length.ToString());
context.Response.ContentType = "application/octet-stream";
context.Response.ContentEncoding = Encoding.Default;
context.Response.WriteFile(bn.FN_SerchResPath(mf).Tables["t_file"].Rows[0]["FilePath"].ToString());
context.Response.Write("0");
}
else
{
context.Response.Write("1");
}
}
catch (Exception)
{ throw;
}
下载失败了 还是说我这个办法实现不了HTTP的下载
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货