【发布时间】:2011-06-06 10:19:20
【问题描述】:
我的应用程序遇到问题。 我在应用程序中有一些部分,用户可以从其中下载 excel 文件中的数据。代码在本地工作得非常好,意味着文件在每个浏览器中都可以在本地正确下载。但是当我们从测试或实时服务器下载文件时,它会显示一个带有以下错误的弹出窗口
"C:\Users\PHT~1.AMI\AppData\Local\Temp\hXybMbIw.xlsx.part 无法保存,因为源 无法读取文件。再试一次 稍后,或联系服务器 管理员。”
仅适用于 firefox 浏览器。
我正在使用以下代码进行文件下载
function ExportToExcel(isJdl) {
var url = '/Product/ExportToExcel?isJdl=' + isJdl
+ "&projID=" + _projID
+ "&PlanPages=" + escape($("#PlanPages").val())
+ "&SpecSections=" + escape($("#SpecSections").val())
+ "&Addenda=" + escape($("#Addenda").val())
+ "&HighLite=" + $("#chkHighLite").attr("checked");
Download(url);
}
function Download(url) {
var win = window.open(url, "DownloadWin", "resizable=0,status=0,toolbar=0,width=600px,height=300px");
win.focus();
win.moveTo(100, 100);
}
控制器代码如下:-
public void ExportToExcel(bool isJdl, string projID, string planPages, string specSections, string addenda, string HighLite)
{
int pID = int.Parse(projID.Decrypt());
bool HightLiteVal = false;
if (!string.IsNullOrEmpty(HighLite))
HightLiteVal = Convert.ToBoolean(HighLite);
Highmark.BLL.Models.Project proj = Highmark.BLL.Services.ProjectService.GetByID(pID);
if (proj != null)
{
proj.PlanPages = planPages;
proj.SpecSections = specSections;
proj.Addenda = addenda;
proj.HighLite = HightLiteVal;
using (OfficeOpenXml.ExcelPackage pck = new OfficeOpenXml.ExcelPackage())
{
OfficeOpenXml.ExcelPackage pck1 = Highmark.BLL.Services.ProjectService.GetExcelFile(isJdl, pck, pID, proj, planPages, specSections, addenda);
string name = string.Format("{0}", proj.ProjectName);
if (pck1.Workbook.Worksheets.Count > 0)
{
//Write it back to the client
Response.ContentType = "Application/vnd.ms-Excel";
//Remove Invalid Character from File Name
name = name.RemoveInvalidCharFromFileName();
Response.AddHeader("content-disposition", "attachment; filename=\"" + name + "_HighEST.xlsx\"");
Response.BinaryWrite(pck1.GetAsByteArray());
}
}
}
else
Response.Write("Error: Invalid request, please try again");
}
感谢任何帮助。 谢谢
【问题讨论】:
标签: javascript asp.net-mvc model-view-controller