title: Lotus Notes - Saving Corrupt Attachment Programmatically - NotesEmbeddedObject
body: <p>I have an <code>NSF</code> that contains an email message with two attachments. One of the attachments is corrupt, and if I attempt to save it, Notes displays this message <code>The attachment may be corrupted. Would you like to continue with the available data?</code></p>
  
  <p>If I click Yes, Notes saves the corrupt attachment to the directory I specify. This is good.</p>
  
  <p>I would like to do the same thing using the object model in C#. If I run <code>NotesEmbeddedObject.ExtractFile()</code>, I receive this exception message: <code>Notes error: Encoded Data Checksum Mismatch - Attachment may be corrupted</code>. No version of the file is written to the directory I specify.</p>
  
  <p>I would like for the code to write the corrupted version to a directory. How can I do this?</p>
  
  <p>Existing Code: </p>
  
  <pre><code>//BEGIN Extract Attachment
  //nItem is a NotesItem
  if (nItem.type == IT_TYPE.ATTACHMENT)
  {
      try
      {
          string pAttachment = ((object[])nItem.Values)[0].ToString();
          NotesDocument NDoc =  NotesConnectionDatabase.AllDocuments.GetNthDocument(i);
          NotesEmbeddedObject Neo = NDoc.GetAttachment(pAttachment);
          NDoc.GetAttachment(pAttachment).ExtractFile(@"D:\projects\xxx\Attach\" + pAttachment);
      }
      catch (Exception e)
      {
          string eMessage = e.Message;
          Console.WriteLine(eMessage);
      }
  }
  //END Extract Attachment
  </code></pre>