Reputation: 6801
I have a listview that is showing the contents of a directory. I have enabled drag and drop into the listview so users can drag a file from Windows Explorer and drop it into the listview. I then copy those files to the directory that is being displayed in the listview.
If you drag an email from outlook onto the desktop or into a folder in Windows explorer it creates a .msg file of the email. The users now want to drag emails from outlook and drop them into the listview.
When an email is drug over the listview, it doesn't see it as a valid drag/drop object. The cursor is a circle with a line through it instead of the drop event cursor.
In the listView1_DragEnter
event I have
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.All;
}
else
{
e.Effect = DragDropEffects.None;
}
I have tried DataFormats.HTML
but that doesn't see anything to drop either. Any ideas?
The email are dragged from the list section in Outlook.
Upvotes: 3
Views: 1028
Reputation: 3959
In the listview's DragEnter
Event, return the following DragDropEffects
:
private void listView_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
To extract and read the Outlook message(s) within the DragDrop
event, I recommend using this library. It is very easy to use:
private void listView_DragDrop(object sender, DragEventArgs e)
{
OutlookDataObject dataObject = new OutlookDataObject(e.Data);
//get the names and data streams of the files dropped
string[] filenames = (string[])dataObject.GetData("FileGroupDescriptor");
MemoryStream[] filestreams = (MemoryStream[])dataObject.GetData("FileContents");
for (int fileIndex = 0; fileIndex < filenames.Length; fileIndex++)
{
string filename = filenames[fileIndex];
MemoryStream filestream = filestreams[fileIndex];
OutlookStorage.Message message = new OutlookStorage.Message(filestream);
// do whatever you want with "message"
message.Dispose();
}
}
Upvotes: 2