C# 在mvc中使用WordprocessingDocument打开文档
我正在使用WordprocessingDocument打开一个文档文件。 但若文件并没有损坏,它仍然会进入catch部分。。 代码如下:C# 在mvc中使用WordprocessingDocument打开文档,c#,asp.net-mvc,C#,Asp.net Mvc,我正在使用WordprocessingDocument打开一个文档文件。 但若文件并没有损坏,它仍然会进入catch部分。。 代码如下: bool savedSuccesfully = false; if (System.IO.File.Exists(path[0])) //path[0] is doc file path { try { using (WordprocessingDocument wordprocessingDocument = Wordproc
bool savedSuccesfully = false;
if (System.IO.File.Exists(path[0])) //path[0] is doc file path
{
try
{
using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(path[0], true)) //FROM this line it goes to catch part
{
savedSuccesfully = true;
}
}
catch (Exception ex)
{
savedSuccesfully = false;
}
问题是什么?您遇到了什么异常?@Manolete
文件已损坏
。我曾经遇到过这样的情况:即使通过资源管理器双击打开文件在Word中也可以正常打开,但通过File->open打开文件会告诉我文件已损坏。试试看。如果文件已损坏,则您需要完成一项艰巨的任务,找出如何修复它。通过执行file>open
,可以正确打开Doc文件。@Ric