簡體   English   中英

在 Outlook pdf 中命名的文件沒有來源。 我收到錯誤請嘗試再次刪除此文件我該如何解決

[英]In Outlook pdf file named has no source. i am getting error please try removing this file again how can i solve it

我正在編寫一個 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);
                    }
                }

            }

我有一個在頂部崩潰的錯誤日志

聽起來您的 RPC 通道用完了。 避免使用多個點符號(尤其是在循環中)並在完成后立即釋放所有 object。 請改用 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 通道數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM