从剪贴板中获取复制的电子邮件

3
我有一个列表视图,用于显示目录的内容。我启用了拖放功能,使用户可以将Windows资源管理器中的文件拖放到列表视图中。然后,我将这些文件复制到列表视图中显示的目录中。
如果您从Outlook拖动电子邮件并将其放入桌面或Windows资源管理器中的文件夹中,则会创建一个.msg文件来存储该电子邮件。现在,用户想要从Outlook中拖动电子邮件并将其放入列表视图中。
当将电子邮件拖动到列表视图上时,它不会被视为有效的拖放对象。光标是带有一条线的圆圈,而不是拖放事件光标。
在listView1_DragEnter事件中,我有:
        if (e.Data.GetDataPresent(DataFormats.FileDrop))
        {
            e.Effect = DragDropEffects.All;
        }
        else
        {
            e.Effect = DragDropEffects.None;
        }

我尝试了 DataFormats.HTML,但是它也不会放弃任何东西。有什么想法吗?
这些电子邮件是从 Outlook 的列表部分拖出来的。 enter image description here
1个回答

2
在列表视图的DragEnter事件中,返回以下DragDropEffects:
private void listView_DragEnter(object sender, DragEventArgs e)
{
    e.Effect = DragDropEffects.All;
}

为了在DragDrop事件中提取和阅读Outlook消息,我建议使用这个库。它非常易于使用。
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();
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接