How to COPY and PASTE an outlook email on to C#.Net windows form?
<p>I am trying to Copy outlook email and paste it onto form. Whenever I perform paste operation outlook mail (MSG file) should get saved to some directory and I have implemented some code as shown below.</p>

<pre><code>private void OutlookMailCopyPaste_KeyDown(object sender, KeyEventArgs e)
{
  if (e.Control &amp;&amp; e.KeyCode == Keys.V)
  {
    if (Clipboard.ContainsData("FileGroupDescriptor"))
    {
      if (Clipboard.ContainsData("FileGroupDescriptorW"))
      {
        Stream fileStream = (Stream)Clipboard.GetData("FileGroupDescriptor");
        byte[] fileGroupDescriptor = new byte[fileStream.Length];
        fileStream.Read(fileGroupDescriptor, 0, fileGroupDescriptor.Length);
        fileStream.Close();
        System.Text.StringBuilder fileName = new System.Text.StringBuilder("");
        for (int i = 76; i &lt; fileGroupDescriptor.Length; i++)
        {
          fileName.Append(Convert.ToChar(fileGroupDescriptor[i]));
        }

        //fileGroupDescriptor = Encoding.Convert(Encoding.GetEncoding("iso-8859-1"), Encoding.UTF8, fileGroupDescriptor);
        //string tempString = Encoding.UTF8.GetString(fileGroupDescriptor, 0, fileGroupDescriptor.Length);
        string tempString = fileName.ToString().Substring(fileName.ToString().IndexOf('.'));
        if (tempString.ToUpper().StartsWith(".MSG"))
        {
          if (Clipboard.ContainsData("FileContents"))
          {
            MemoryStream[] filestreams = (MemoryStream[])Clipboard.GetData("FileContents");
            if (filestreams != null &amp;&amp; filestreams.Length &gt; 0)
            {
              MemoryStream filestream = filestreams[0];
              //save the file stream using its name to the application path
              FileStream outputStream = File.Create(fileName.ToString());
              filestream.WriteTo(outputStream);
              outputStream.Close();
            }
          }
        }
        else
        {
          MessageBox.Show("Please copy and paste MSG file only.");
        }
      }
    }
  }
}
</code></pre>

<p>When ever I am reading clipboard data into memory stream I'm getting an exception like "Insufficient memory to continue the execution of the program." at line </p>

<blockquote>
  <p>MemoryStream[] filestreams =
  (MemoryStream[])Clipboard.GetData("FileContents");</p>
</blockquote>

<p>moreover Clipboard.GetData("FileContents") having null though i am checking whether it has some data or not prior to this line </p>

<blockquote>
  <p>if (Clipboard.ContainsData("FileContents"))</p>
</blockquote>

<p>Thanks and Regards,
Ramesh Morasa</p>
