代码之家  ›  专栏  ›  技术社区  ›  Xion

System.Runtime.InteropServices.com异常(0x80004004):操作已中止

  •  0
  • Xion  · 技术社区  · 6 年前

    在我的项目中,我想提取附加在msg文件中的附件。当我在开发项目中进行测试时,它是有效的,但是一旦我把它放到服务器上,我就会遇到这个错误。”System.Runtime.InteropServices.COMException(0x80004004):操作已中止”。

    下面是我提取msg文件的代码。

     var outlook = new Microsoft.Office.Interop.Outlook.Application();
     MailItem item = (MailItem)outlook.CreateItemFromTemplate(file.fullPath, Type.Missing);
    
     for (int i = 1; i <= item.Attachments.Count; i++)
     {
          FileInfo fzip = null;
          if (Path.GetExtension(item.Attachments[i].FileName).ToLower().EndsWith(".zip"))
          {
               fzip = new FileInfo(SavePath + item.Attachments[i].FileName);
               string attpath = strSavePath + item.Attachments[i].FileName;
               item.Attachments[i].SaveAsFile(attpath);
               ..process zip...
           }
    

    0 回复  |  直到 6 年前