使用自定义名称从 http 处理程序下载文件
Download File from http handler with custom name
我在上传文件夹中有不同的文件,包括 .doc、.docx、.pdf、.xls 等,我想在点击图片时下载文件。我正在从 jquery 调用 http 通用处理程序,值已正确传递但无法正常工作
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
HttpContext.Current.Response.AppendHeader("Content-Length", fileInfo.Length.ToString());
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.TransmitFile(fileInfo.FullName);
HttpContext.Current.Response.Flush();
尝试这样的事情:
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(fileInfo.FullName);
Response.End();
应该可以!
我在上传文件夹中有不同的文件,包括 .doc、.docx、.pdf、.xls 等,我想在点击图片时下载文件。我正在从 jquery 调用 http 通用处理程序,值已正确传递但无法正常工作
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
HttpContext.Current.Response.AppendHeader("Content-Length", fileInfo.Length.ToString());
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.TransmitFile(fileInfo.FullName);
HttpContext.Current.Response.Flush();
尝试这样的事情:
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(fileInfo.FullName);
Response.End();
应该可以!