我在Visual Studio 2010中运行了我的代码。当我发布我的应用程序时,它工作正常。
在Windows Server 2003 IIS6.0中,我遇到异常。
消息过滤器指示应用程序正忙。 (来自HRESULT的异常:0x8001010A(RPC_E_SERVERCALL_RETRYLATER))asp.net mvc
我的代码在这里:
public ActionResult Getfile(int id)
{
Candidate candidate = IcandidateRepository.GetCandidate(id);
if (candidate.FilePath != null)
{
string Filename = Path.GetFileName(candidate.FilePath);
//string[] filename = candidate.FilePath.Split('\\');
//foreach (var file in filename)
//{
// Filename = file;
//}
Microsoft.Office.Interop.Word.Application wordApplication = new Microsoft.Office.Interop.Word.Application();
object nullobj = System.Reflection.Missing.Value;
object filepath = candidate.FilePath;
object ofalse = false;
object isvisible = false;
Microsoft.Office.Interop.Word.Document doc = wordApplication.Documents.Open(ref filepath,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref isvisible,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj);
wordApplication.Visible = false;
string newfilename = Filename.Replace(".doc", ".html");
object onewfilename = @"D:\\clg\\" + newfilename;
object encoded = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
object encodending = Microsoft.Office.Interop.Word.WdLineEndingType.wdCRLF;
object oformat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML;
doc.SaveAs(ref onewfilename, ref oformat, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref encoded, ref nullobj,
ref nullobj, ref encodending, ref nullobj);
doc.Close(ref ofalse, ref nullobj, ref nullobj);
wordApplication.Quit(ref nullobj, ref nullobj, ref nullobj);
string newfile = onewfilename.ToString();
if (Filename != null)
{
dynamic cmd = System.Diagnostics.Process.Start(newfile);
return RedirectToAction("CandidateDetails", new { id = candidate.CandidateID });
}
}
return View("FileNotFound");
}
答案 0 :(得分:3)
您可能会发现Word正在显示一个对话框。使其可见,以便您可以看到对话框是什么。
wordApp.DisplayAlerts := wdAlertsNone;
还有助于抑制警告对话框
doc.Saved = true;
将阻止它在您关闭文档时提示您保存更改。