2
votes

I have a document control system that is written in C#. Drag and drop from Outlook to C# has been done for some time. Now that many of the files are in the C# application, the users naturally want to be able to drag and drop in the other direction from my document control system to Outlook.

Since the files are stored in a file system (and not as blobs in the SQL database) I have had them open the folder view and drag and drop from there. However, this allows for the bypassing of the document management system's version control.

Is there a drag and drop message I can construct that will notify Outlook of the filename and path I'm dropping? I suspect this has been done, but my searches are being overwhelmed by the number of responses going the other direction.

2

2 Answers

3
votes

From here:

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);
0
votes

There is a sequence of steps you have to follow

  1. Choose the Allow Drop property to be true

  2. Add event listeners (DragEnter & DragDrop)

  3. Add this code to your cs file

    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);
            }
        }
    }