我开发了MVC4应用程序并托管在IIS服务器上。 在应用程序中,我创建了用于PPT和Word下载的模板。 它在本地完美工作,但在IIS服务器托管后,我无法下载它。 请向我提供解决方案&,这需要在服务器的组件服务或其他东西上进行设置。 我的代码是: 控制器:不从IIS服务器下载PPT/Word文件
public ActionResult DownloadFile(GlobalDashboardModel objGlobalDashboard)
{
//string contentType = "application/doc";
objBSS = new BSS_Repository();
var currentDate = Convert.ToDateTime(DateTime.Now).ToString("ddMMyyyyhhmmss");
object temporaryFileName = Server.MapPath(_tempPathOnServer) + "GloablDashboard" + "-" + currentDate + ".doc";
string tempPathOnClient = _tempPathOnClient + "GloablDashboard" + "-" + currentDate + ".doc";
MSWord.Document document = null;
try
{
// processing for word document
object missing = Missing.Value;
MSWord.Application wordApp = new MSWord.Application();
string templateFile = Server.MapPath(_globalDashboardTemplateFilePath);
// copy from template file to temporary file
System.IO.File.Copy(templateFile, (string)temporaryFileName, true);
if (System.IO.File.Exists(temporaryFileName.ToString()))
{
object readOnly = false;
object isVisible = false;
document = wordApp.Documents.Open(ref temporaryFileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);
document.Activate();
//// Call FindAndReplace()function for each change
this.FindAndReplace(document, "<bsc>", objGlobalDashboard.bscCount);
this.FindAndReplace(document, "<bts>", objGlobalDashboard.btsCount);
this.FindAndReplace(document, "<nw>", objGlobalDashboard.networkAvailability);
//// save temp.doc after modified
document.Save();
}
return Json(new { path = tempPathOnClient }, JsonRequestBehavior.AllowGet);
}
catch
{
ModelState.AddModelError(string.Empty, "File does not exist !!!");
}
finally
{
if (document != null)
{
((Microsoft.Office.Interop.Word._Document)document).Close(true, Type.Missing, Type.Missing);
}
}
return Json(new { path = tempPathOnClient }, JsonRequestBehavior.AllowGet);
}
你的代码看起来如何?什么是实际的错误?你有什么尝试? – bstenzel 2014-09-24 09:08:17
我在我的应用程序中有一个表单,我希望它在word文件中,因为我已经创建了一个模板,并使用interop.word库在模板中写入值,并通过loation.href.Now在iis服务器上托管应用程序进行下载。此功能不起作用。 – coder 2014-09-24 09:16:57
你需要发布一些代码! 'location.href'的价值是什么? – 2014-09-24 09:23:33