C# C Outlook Attachment.SaveAsFile在.msg文件类型上失败

C# C Outlook Attachment.SaveAsFile在.msg文件类型上失败,c#,outlook,attachment,msg,C#,Outlook,Attachment,Msg,因此,我有以下代码,它从驻留在共享文件夹中的联系人项目中提取所有附件: Outlook._Application objOutlook; //declare Outlook application objOutlook = new Outlook.Application(); //create it Outlook._NameSpace objNS = objOutlook.Session; //create new ses

因此,我有以下代码,它从驻留在共享文件夹中的联系人项目中提取所有附件:

            Outlook._Application objOutlook; //declare Outlook application
            objOutlook = new Outlook.Application(); //create it
            Outlook._NameSpace objNS = objOutlook.Session; //create new session
            Outlook.MAPIFolder oAllPublicFolders; //what it says on the tin
            Outlook.MAPIFolder oPublicFolders; // as above
            Outlook.MAPIFolder objContacts; //as above
            Outlook.Items itmsFiltered; //the filtered items list
            oPublicFolders = objNS.Folders["Public Folders"];
            oAllPublicFolders = oPublicFolders.Folders["All Public Folders"];
            objContacts = oAllPublicFolders.Folders["Global Contacts"];

            itmsFiltered = objContacts.Items.Restrict(strFilter);//restrict the search to our filter terms

            for (int i = 1; i <= itmsFiltered.Count; i++) //loop through filtered items
            {
                var item = itmsFiltered[i];

                Contact ctctNew = new Contact(); //create new contact

                foreach (Outlook.Attachment oa in item.Attachments)
                { ctctNew.ImportedAttachments.Add(oa); }

                lstContacts.Add(ctctNew); // add to the list that will be displayed in the OLV
            }

            return lstContacts;
最后一位适用于非.msg的文件类型,也就是说,它适用于.pdf文件等;如果是.msg文件,则会出现以下异常:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in Event Management System.exe

Additional information: Cannot save the attachment. Could not complete the operation. One or more parameter values are not valid.
有人能解释一下吗

谢谢

更新:我发现只有一些.msg文件无法保存;其中一些很好用。某些用户附加的文件似乎有效,而其他用户附加的文件无效;我猜这可能与他们如何连接有关


此外,尽管引发了异常,代码似乎还是保存了文件,但它似乎已损坏-相关文件夹中会出现一个3Kb.msg文件。Outlook不会打开它,我只是收到一个无法读取该项目的提示。如果我尝试打开该文件,请使用Outlook中的messagebox。

作为猜测,msg附件的o.FileName值是多少?它可能不是有效的文件名。

它是有效的。例如,X:\Quotence.msg导致了异常,但X:\Quotence.pdf没有。是否有异常的错误号?还是内部异常?不,没有;只是我发的信息,真奇怪。我在Outlook中看到的每个COMException都有一个COM错误号或HRESULT。如果没有,恐怕你会被卡住。除非VS2013中有一些设置,否则我需要更改才能看到所述错误号。我看不到任何有帮助的内容,没有。更新:。xlsx文件也不是问题,肯定只有.msg文件引发此异常。是否所有嵌入的邮件附件都会发生这种情况?或者只是一些?据我所知,它发生在所有的.msg附件上。我的意思是,在不同联系人的20-30次尝试中,我还没有成功地获得一个.msg附件,但其他文件类型工作正常attachment.Type属性的值是多少?attachment.Type是5
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in Event Management System.exe

Additional information: Cannot save the attachment. Could not complete the operation. One or more parameter values are not valid.