views:

334

answers:

2

how do i find out which application dropped some content on my c# form? right now i'm doing some wild guesses, like

if (e.Data.GetDataPresent("UniformResourceLocatorW", true)) {
  // URL dropped from IExplorer
}

but what i'm really looking for is something like

if (isDroppedFrom("iexplorer")) {
  // URL dropped from IExplorer
}

any hints appreciated.

+1  A: 

As far as I know, there's no direct information in the drag drop structure that indicates the originating application.

http://msdn.microsoft.com/en-us/library/bb776902(VS.85).aspx

If you're only interested in finding out if it's a drop from IE, the presence of CFSTR_UNTRUSTEDDRAGDROP is a clue; AFAIK, only IE and Web Browser Controls will put this format on the clipboard.

EricLaw -MSFT-
thanks Eric, sounds good. still, i need to differentiate btw all major app type (ffox, ie, word, excel, email, ...). so right now i'm making my way through by sniffing some hints like UniformResourceLocatorW and the like, but i was hoping for a more generic and solid approach...
Renaud
A: 

ok, this is what i ended up doing, for those interested..

            // FIREFOX //
            if (e.Data.GetDataPresent("text/x-moz-url", true)) {
                HandleFirefoxUrl(e);
            } else if (e.Data.GetDataPresent("text/_moz_htmlcontext", true)) {
                HandleFirefoxSnippet(e);

                // IE //
            } else if (e.Data.GetDataPresent("UntrustedDragDrop", false)) {
                HandleIELink(e);
            } else if (e.Data.GetDataPresent("UniformResourceLocatorW", false)) {
                HandleIEPage(e);

            } else if (e.Data.GetDataPresent(DataFormats.FileDrop, true)) { //FILES
                Array droppedFiles = (Array)e.Data.GetData(DataFormats.FileDrop);
                HandleFiles(droppedFiles);

            } else if (e.Data.GetDataPresent(DataFormats.Bitmap, true)) { // BITMAP
                Bitmap image = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);
                HandleBitmap(image);

            } else if (e.Data.GetDataPresent(DataFormats.Html, true)) { // HTML
                String pastedHtml = (string)e.Data.GetData(DataFormats.Html);
                HandleHtml(pastedHtml);

            } else if (e.Data.GetDataPresent(DataFormats.CommaSeparatedValue, true)) { // CSV
                MemoryStream memstr = (MemoryStream)e.Data.GetData("Csv");
                StreamReader streamreader = new StreamReader(memstr);
                String pastedCSV = streamreader.ReadToEnd();
                HandleCSV(pastedCSV);

                //  } else if (e.Data.GetDataPresent(DataFormats.Tiff, true)) {
                //  } else if (e.Data.GetDataPresent(DataFormats.WaveAudio, true)) {

            } else if (e.Data.GetDataPresent(DataFormats.Text, true)) { //TEXT
                String droppedText = e.Data.GetData(DataFormats.Text).ToString();
                HandleText(droppedText);

            [else if .....]

            } else { // UNKNOWN
                Debug.WriteLine("unknown dropped format");
            }
Renaud