title: Exchange Web Services - convert emailitem attachment from Base64 string to Byte gives error
body: <p>I am trying to read an email item attachment using EWS and save it to disk as a text file so it can be used later on.</p>
  
  <p>I am getting an error:</p>
  
  <pre><code>"The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters. "
  </code></pre>
  
  <p>here is my code:</p>
  
  <pre><code>Directory.CreateDirectory(emailAttachmentsPath);
  
  // Put attachment contents into a stream. C:\Dev\EWSHelloWorld
  emailAttachmentsPath = emailAttachmentsPath + "\\" + sEmailSubject+".txt";
  
  //save to disk 
  using (Stream FileToDisk = new FileStream(emailAttachmentsPath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
  {
      byte[] ContentBytes = System.Convert.FromBase64String(itemAttachment.ToString());
  
      FileToDisk.Write(ContentBytes, 0,ContentBytes.Length);
      FileToDisk.Flush();
      FileToDisk.Close();
  } 
  </code></pre>
  
  <p>what is the best way to do this please?</p>
  
  <p>I basically want the text of the email in a text file, and any attachments in that email would be saved to disk as well (I can do that part I think using FileStream.</p>