在 Outlook 中,名为 pdf 文件没有来源。我收到错误,请尝试再次删除此文件,我该如何解决它
我正在编写一个 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}
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您的 RPC 通道已经用完了。避免使用多点表示法(尤其是在循环中),并在使用完所有对象后立即释放它们。请改用 for 循环:
如果您在联机模式下使用 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:
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.