Dan R

Dan R

  • NA
  • 1
  • 2.9k

Outlook RTF format image attachment copy/paste problem

Nov 6 2011 6:43 PM
I have an image editing app, and the problem is with paste functionality. It's working fine if I copy paste from Paint, Windows Explorer, Outlook 2007, Outlook 2010... Drag and drop also works fine, but if I try to copy/paste from Outlook 2010 and mail is in RTF it doesn't work. So it works on 2007 when in RTF, or 2007 and 2010 when in other formats, but in 2010 it doesn't. I've tried it on another computer also Outlook 2010 RTF and it does work there. So the problem is two Outlook 2010 don't behave the same. When I try pasting I get an icon of the image and image name. Same thing happens in Paint. So to sum up: Outlook 2007 - all mail formats copy/paste working Outlook 2010 14.0.5128.5000 - all mail formats copy/paste working Outlook 2010 14.0.6106.5005 - RTF attachments copy/paste and drag and drop not working.

For the part of my pasting functionality (for Outlook) I've used this code http://www.codeproject.com/KB/office...rop_in_cs.aspx and modified it (fixed errors etc.).

Could it be that one version of Outlook has a bug(because same thing happens when pasting to Paint)?

Does someone have a code that 100% works so I can test if it's a version bug?

edit: Here's the two files attached: http://www.sendspace.com/file/s7iyns here's the code that handles pasting(openMimage opens a file array, and open Bmp opens a bitmap data object):

private void doPaste()
{
try
{
if (Clipboard.ContainsFileDropList())
{
System.Collections.Specialized.StringCollection returnList = Clipboard.GetFileDropList();
string[] mFiles = new string[returnList.Count];
int i = 0;
foreach (string file in returnList)
{
mFiles[i++] = file;
}
openMImages(mFiles, true);
}
else if (Clipboard.ContainsImage())
{
try
{
Bitmap clipBmp = new Bitmap((Bitmap)Clipboard.GetImage());
openBmp(clipBmp);
}
catch (Exception extExp)
{
MessageBox.Show("External exception: " + extExp.Message);
}

}
else
{
OutlookDataObject dataObject = new OutlookDataObject(Clipboard.GetDataObject());
if (dataObject != null)
{
string[] filenames = (string[])dataObject.GetData("FileGroupDescriptorW");
MemoryStream[] filestreams = (MemoryStream[])dataObject.GetData("FileContents");
int countFiles = 0;
String debug_data = "";
for (int fileIndex = 0; fileIndex < filenames.Length; fileIndex++)
{
debug_data += filenames[fileIndex];
string filename = filenames[fileIndex];
if (Path.GetExtension(filename) == ".jpg" || Path.GetExtension(filename) == ".JPG"
|| Path.GetExtension(filename) == ".png" || Path.GetExtension(filename) == ".PNG"
|| Path.GetExtension(filename) == ".gif" || Path.GetExtension(filename) == ".GIF"
|| Path.GetExtension(filename) == ".tif" || Path.GetExtension(filename) == ".tif"
|| Path.GetExtension(filename) == ".tiff" || Path.GetExtension(filename) == ".tiff"
|| Path.GetExtension(filename) == ".bmp" || Path.GetExtension(filename) == ".BMP")
{
countFiles++;
}
}
string[] mFiles = new string[countFiles];


if (filenames.Length <= 0)
{
MessageBox.Show("You can only copy/paste images.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
int i = 0;
for (int fileIndex = 0; fileIndex < filenames.Length; fileIndex++)
{
//use the fileindex to get the name and data stream
string filename = filenames[fileIndex];
if (Path.GetExtension(filename) == ".jpg" || Path.GetExtension(filename) == ".JPG"
|| Path.GetExtension(filename) == ".png" || Path.GetExtension(filename) == ".PNG"
|| Path.GetExtension(filename) == ".gif" || Path.GetExtension(filename) == ".GIF"
|| Path.GetExtension(filename) == ".tif" || Path.GetExtension(filename) == ".tif"
|| Path.GetExtension(filename) == ".tiff" || Path.GetExtension(filename) == ".tiff"
|| Path.GetExtension(filename) == ".bmp" || Path.GetExtension(filename) == ".BMP")
{
if (countFiles == 1)
{
Bitmap clipBmp = new Bitmap(filestreams[fileIndex]);
openBmp(clipBmp);
}
else
{
Bitmap tempForSave = new Bitmap(filestreams[fileIndex]);
string tempPathForSave = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
ImageEditor.saveJpeg(tempPathForSave + "\\" + Path.GetFileNameWithoutExtension(filename) + ".jpg", tempForSave, 100);
mFiles[i++] = tempPathForSave + "\\" + Path.GetFileNameWithoutExtension(filename) + ".jpg";
}
}
}
if (countFiles > 1)
{
openMImages(mFiles, true);
}
}
}
else
{
MessageBox.Show("You can only copy/paste images.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}

}
catch (Exception exp)
{
MessageBox.Show("Exception : " + exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}

Answers (1)