title: Attachment.SaveAsFile Method (Outlook) - Error: Cannot Save the Attachment. Cannot Find This File. Verify the Path and File Name are Correct
body: <p>I am working with an Outlook AddIn which has the functionality to save an email and its attachments to a network drive.</p>
  
  <p>For one of the users of the application, when saving 10 pdfs of about 1MB in a row, the application crashes with the following error message:</p>
  
  <pre><code>Cannot Save the Attachment. Cannot Find This File. Verify the Path and File Name are Correct.
  </code></pre>
  
  <p>The user did three tests and the issue happened twice on the same pdf and once on another.</p>
  
  <p>Here is the snippet of code in question:</p>
  
  <pre><code>For myCount As Integer = 1 To inMailItem.Attachments.Count
      If inMailItem.Attachments(myCount).Type &lt;&gt; 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 &lt;= 50 chars
          Dim tmpFileName = IO.Path.GetFileNameWithoutExtension(thisFileName.Substring(0, Math.Min(thisFileName.Length, charsAvailable))) + GetRandomChars(4) + thisExt
          fileName = EscapeSqlInput(tmpFileName)
          attachmentFilePath = myDirectoryName &amp; "\" &amp; 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
  </code></pre>
  
  <p>On the network drive I can see a .tmp file containing the exact same number of bytes as the original file. If I switch the .tmp extension to .pdf I can open the file using adobe reader. I see another .pdf file on the same drive, this one containing 0 bytes.</p>
  
  <p>I am assuming the empty pdf file and the tmp files are related to the SaveAsFile method process.</p>
  
  <p>Three users tested the issue. Two in San Diego, CA and one in New York, NY. The person in New York had the failure and the two people in San Diego didn't encounter the issue.</p>
  
  <p>Would somebody have an idea of what could be the cause of this issue?</p>