Attachment.SaveAsFile方法(Outlook)-错误:无法保存附件。找不到此文件。验证路径和文件名是否正确

Attachment.SaveAsFile方法(Outlook)-错误:无法保存附件。找不到此文件。验证路径和文件名是否正确,outlook,save,add-in,attachment,Outlook,Save,Add In,Attachment,我正在使用Outlook加载项,该加载项具有将电子邮件及其附件保存到网络驱动器的功能 对于应用程序的其中一个用户,当连续保存约1MB的10个PDF时,应用程序崩溃并显示以下错误消息: Cannot Save the Attachment. Cannot Find This File. Verify the Path and File Name are Correct. 用户做了三次测试,问题在同一个pdf上发生了两次,在另一个pdf上发生了一次 下面是有问题的代码片段: For myCount

我正在使用Outlook加载项,该加载项具有将电子邮件及其附件保存到网络驱动器的功能

对于应用程序的其中一个用户,当连续保存约1MB的10个PDF时,应用程序崩溃并显示以下错误消息:

Cannot Save the Attachment. Cannot Find This File. Verify the Path and File Name are Correct.
用户做了三次测试,问题在同一个pdf上发生了两次,在另一个pdf上发生了一次

下面是有问题的代码片段:

For myCount As Integer = 1 To inMailItem.Attachments.Count
    If inMailItem.Attachments(myCount).Type <> Outlook.OlAttachmentType.olOLE Then

        Dim thisFileName = IO.Path.GetFileName(inMailItem.Attachments(myCount).FileName)
        Dim thisExt = IO.Path.GetExtension(thisFileName)

        Dim charsAvailable = 46 - thisExt.Length ' [filename][random].ext <= 50 chars
        Dim tmpFileName = IO.Path.GetFileNameWithoutExtension(thisFileName.Substring(0, Math.Min(thisFileName.Length, charsAvailable))) + GetRandomChars(4) + thisExt
        fileName = EscapeSqlInput(tmpFileName)
        attachmentFilePath = myDirectoryName & "\" & fileName
        fileInfo = New IO.FileInfo(attachmentFilePath)
        isValidFileType = "1"
        isEmailBody = "0"
        sortOrder += 1
        inMailItem.Attachments(myCount).SaveAsFile(attachmentFilePath)
        attachmentFileSize = fileInfo.Length

        sb = New StringBuilder()
        sb.Append("INSERT INTO EmailDocuments (EmailFileID, DirectoryPath, FileName, IsValidFileType, AttachmentFileSize, IsEmailBody, SortOrder) ")
        sb.AppendFormat("VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')",
                        emailFileId,
                        directoryPath,
                        fileName,
                        isValidFileType,
                        attachmentFileSize,
                        isEmailBody,
                        sortOrder)
        SqlHelper.SqlExecuteNonQuery(sb.ToString())
    End If
Next
对于mailitem.Attachments.Count,myCount为整数=1
如果在mailitem.Attachments(myCount)中,请键入Outlook.OlAttachmentType.olOLE,然后
Dim thisFileName=IO.Path.GetFileName(在mailitem.Attachments(myCount.FileName)中)
Dim thisExt=IO.Path.GetExtension(thisFileName)

Dim charsavaailable=46-thisExt.Length'[filename][random].ext听起来你的RPC频道肯定快用完了。避免使用多点表示法(特别是在循环中),并在使用完它们后立即释放所有对象

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

for(int myCount=1;myCount感谢您的快速回答!我添加了更多代码以防万一。我的同事和我无法在我们这方面复制该问题(即使尝试了几次)。有问题的用户位于不同的办公室并尝试了三次。每次应用程序为他失败。我不熟悉RPC通道。RPC通道的可用性是如何决定的?如果您在联机中使用Exchange store(而不是缓存),您将看到该问题模式。Exchange server跟踪每个对象级别上每个客户端使用的RPC通道数。如果我没有弄错,附件的限制为100(请参阅)