2

我有一个用 C# 编写的文档控制系统。从 Outlook拖放到 C# 已经有一段时间了现在很多文件都在 C# 应用程序中,用户自然希望能够从我的文档控制系统向另一个方向 拖放Outlook。

由于文件存储在文件系统中(而不是作为 SQL 数据库中的 blob),我让它们打开文件夹视图并从那里拖放。但是,这允许绕过文档管理系统的版本控制。

是否有我可以构建的拖放消息将通知 Outlook 我要删除的文件名和路径?我怀疑这已经完成了,但是我的搜索被相反方向的响应数量所淹没。

4

2 回答 2

3

从这里:

http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/f57ffd5d-0fe3-4f64-bfd6-428f58998603/

//put the file path is a string array
string[] files = new String[1];
files[0] = @"C:\out.txt";

//create a dataobject holding this array as a filedrop
DataObject data = new DataObject(DataFormats.FileDrop, files);

//also add the selection as textdata
data.SetData(DataFormats.StringFormat, files[0]);

//do the dragdrop
DoDragDrop(data, DragDropEffects.Copy);
于 2012-05-10T19:49:26.307 回答
0

您必须遵循一系列步骤

  1. 选择Allow Drop要成为的属性true

  2. 添加事件侦听器 ( DragEnter& DragDrop)

  3. 将此代码添加到您的 cs 文件中

    private void splitContainer1_Panel2_DragEnter(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent("FileDrop", false))
            e.Effect = DragDropEffects.Copy;
        else
            e.Effect = DragDropEffects.None;
    }
    
    private void splitContainer1_Panel2_DragDrop(object sender, DragEventArgs e)
    {
        string[] files = new String[1];
        files[0] = @"C:\out.txt";
        //create a dataobject holding this array as a filedrop
        DataObject data = new DataObject(DataFormats.FileDrop, files);
        //also add the selection as textdata
        data.SetData(DataFormats.StringFormat, files[0]);
        //do the dragdrop
        DoDragDrop(data, DragDropEffects.Copy);
        if (e.Data.GetDataPresent("FileDrop", false))
        {
            string[] paths = (string[])(e.Data.GetData("FileDrop", false));
            foreach (string path in paths)
            {
                 // in this line you can have the paths to add attachements to the email
                Console.WriteLine(path);
            }
        }
    }
    
于 2018-03-15T11:02:04.723 回答