在 Outlook 中,名为 pdf 文件没有来源。我收到错误,请尝试再次删除此文件,我该如何解决它

发布于 2025-01-14 00:01:54 字数 4221 浏览 3 评论 0原文

我正在编写一个 Outlook 加载项。 在此插件中,我在 SDK 的帮助下上传附件。有时它执行上传过程没有任何问题,但有时代码会出现错误。我不明白为什么会出现这个问题。我该如何解决这个问题。

    {"ClassName":"System.IO.FileLoadException","Message":"Cannot save the attachment.","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":"   at Microsoft.Office.Interop.Outlook.Attachment.SaveAsFile(String Path)\r\n   at  OutlookAddIn.BusinessLayer.ThisAddin.ThisAddinMethod.LinkCollection(MailItem MailItemObj) in C:\\Users\\MYPC\\Desktop\\OfficeAddin\\OfficeAddins\\OutlookAddIn\\BusinessLayer\\ThisAddin\\ThisAddinMethod.cs:line 171","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":"8\nSaveAsFile\nOutlookAddIn, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null\nMicrosoft.Office.Interop.Outlook.Attachment\nVoid SaveAsFile(System.String)","HResult":-2147024864,"Source":"Microsoft Outlook","WatsonBuckets":null,"FileLoad_FileName":null,"FileLoad_FusionLog":null}

输入图片此处描述

    foreach (Attachment attach in MailItemObj.Attachments)
            {
                i = i + 1;
                string get = attach.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E");
                if (!html.Contains("cid:" + attach.DisplayName) && (string.IsNullOrEmpty(get) || !html.Contains("cid:" + get)))
                {
                    var name = attach.DisplayName;
                    try
                    {
                        var index = attachmentInfoList.FirstOrDefault(f=>f.Id==attach.Index);

                        string filePath = Path.Combine(tempPath, attach.DisplayName);
                        string mainDirectoryPath = Path.GetDirectoryName(filePath);
                        string extension = Path.GetExtension(filePath);
                        string fileName = Path.GetFileNameWithoutExtension(filePath);
                        var number = oldFileList.Count(y => y == name);
                        string customFilePath = string.Empty;
                        string newFileName = string.Empty;
                        string fullFileName = string.Empty;
                        if (index!=null)
                        {
                            if (index.NewFileName!=null)
                            {

                         
                            
                            customFilePath = Path.Combine(mainDirectoryPath, index.NewFileName);
                            fullFileName = Path.GetFileName(customFilePath);
                            
                             newFileName = Path.GetDirectoryName(customFilePath);
                             fullFileName = Path.GetFileName(customFilePath);
                            attach.SaveAsFile(customFilePath);
                            linkFileCollection.Add(new SDK.V2.OutlookDTO.LinkFile(ExtensionTask.GetStreamFromUrl(customFilePath), fullFileName) { Path = customFilePath });
                            }

                        }
                        else
                        {
                           
                            customFilePath = Path.Combine(mainDirectoryPath, fullFileName);
                            fullFileName = Path.GetFileName(customFilePath);
                      
                             newFileName = Path.GetDirectoryName(customFilePath);
                            //string fullFileName = Path.GetFileName(customFilePath);
                            attach.SaveAsFile(customFilePath);
                            linkFileCollection.Add(new SDK.V2.OutlookDTO.LinkFile(ExtensionTask.GetStreamFromUrl(customFilePath), fullFileName) { Path = customFilePath });

                        }



                    }
                    catch (System.Exception ex)
                    {
                        BusinessLayer.Logger.LogWriter.WriteLog(JsonConvert.SerializeObject(ex));
                        throw new System.InvalidOperationException("FileAttach: " + name + " " + lang.FileAttachError);
                    }
                }

            }

我有一个错误日志,该日志在顶部崩溃

I'm writing an Outlook add-in.
In this plugin, I am uploading the attachments with the help of SDK. Sometimes it performs the upload process without any problems, but sometimes the code gives an error. I couldn't understand why the problem is. how can i solve this problem.

    {"ClassName":"System.IO.FileLoadException","Message":"Cannot save the attachment.","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":"   at Microsoft.Office.Interop.Outlook.Attachment.SaveAsFile(String Path)\r\n   at  OutlookAddIn.BusinessLayer.ThisAddin.ThisAddinMethod.LinkCollection(MailItem MailItemObj) in C:\\Users\\MYPC\\Desktop\\OfficeAddin\\OfficeAddins\\OutlookAddIn\\BusinessLayer\\ThisAddin\\ThisAddinMethod.cs:line 171","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":"8\nSaveAsFile\nOutlookAddIn, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null\nMicrosoft.Office.Interop.Outlook.Attachment\nVoid SaveAsFile(System.String)","HResult":-2147024864,"Source":"Microsoft Outlook","WatsonBuckets":null,"FileLoad_FileName":null,"FileLoad_FusionLog":null}

enter image description here

    foreach (Attachment attach in MailItemObj.Attachments)
            {
                i = i + 1;
                string get = attach.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E");
                if (!html.Contains("cid:" + attach.DisplayName) && (string.IsNullOrEmpty(get) || !html.Contains("cid:" + get)))
                {
                    var name = attach.DisplayName;
                    try
                    {
                        var index = attachmentInfoList.FirstOrDefault(f=>f.Id==attach.Index);

                        string filePath = Path.Combine(tempPath, attach.DisplayName);
                        string mainDirectoryPath = Path.GetDirectoryName(filePath);
                        string extension = Path.GetExtension(filePath);
                        string fileName = Path.GetFileNameWithoutExtension(filePath);
                        var number = oldFileList.Count(y => y == name);
                        string customFilePath = string.Empty;
                        string newFileName = string.Empty;
                        string fullFileName = string.Empty;
                        if (index!=null)
                        {
                            if (index.NewFileName!=null)
                            {

                         
                            
                            customFilePath = Path.Combine(mainDirectoryPath, index.NewFileName);
                            fullFileName = Path.GetFileName(customFilePath);
                            
                             newFileName = Path.GetDirectoryName(customFilePath);
                             fullFileName = Path.GetFileName(customFilePath);
                            attach.SaveAsFile(customFilePath);
                            linkFileCollection.Add(new SDK.V2.OutlookDTO.LinkFile(ExtensionTask.GetStreamFromUrl(customFilePath), fullFileName) { Path = customFilePath });
                            }

                        }
                        else
                        {
                           
                            customFilePath = Path.Combine(mainDirectoryPath, fullFileName);
                            fullFileName = Path.GetFileName(customFilePath);
                      
                             newFileName = Path.GetDirectoryName(customFilePath);
                            //string fullFileName = Path.GetFileName(customFilePath);
                            attach.SaveAsFile(customFilePath);
                            linkFileCollection.Add(new SDK.V2.OutlookDTO.LinkFile(ExtensionTask.GetStreamFromUrl(customFilePath), fullFileName) { Path = customFilePath });

                        }



                    }
                    catch (System.Exception ex)
                    {
                        BusinessLayer.Logger.LogWriter.WriteLog(JsonConvert.SerializeObject(ex));
                        throw new System.InvalidOperationException("FileAttach: " + name + " " + lang.FileAttachError);
                    }
                }

            }

I have an error log that crashes at the top

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

俯瞰星空 2025-01-21 00:01:54

听起来您的 RPC 通道已经用完了。避免使用多点表示法(尤其是在循环中),并在使用完所有对象后立即释放它们。请改用 for 循环:

Attachments attachments = inMailItem.Attachments;
for (int myCount = 1; myCount <= attachments.Count; myCount++)
{
  Attachment attach = attachments.Item(myCount);
  attach.SaveAsFile(attachmentFilePath);

  // release the attachment COM object after
  Marshal.ReleaseComObject(attach);
  attach = null;
}
Marshal.ReleaseComObject(attachments);

如果您在联机模式下使用 Exchange 存储,您可能会看到此类问题。 Exchange 服务器在每个对象级别跟踪每个客户端使用的 RPC 通道数。

It sounds like you are running out of RPC channels. Avoid using multiple dot notation (especially in a loop) and release all object as soon as you are done with them. Use the for loop instead:

Attachments attachments = inMailItem.Attachments;
for (int myCount = 1; myCount <= attachments.Count; myCount++)
{
  Attachment attach = attachments.Item(myCount);
  attach.SaveAsFile(attachmentFilePath);

  // release the attachment COM object after
  Marshal.ReleaseComObject(attach);
  attach = null;
}
Marshal.ReleaseComObject(attachments);

You can see such kind of problems if you are using Exchange store in the online mode. Exchange server tracks the number of RPC channels used by each client on the per-object level.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文