Click here to Skip to main content
15,749,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to drag a link from a browser to my application and pick up both the url and the title/name associated with it.
I can read the url easily enough:
object o = data.GetData(typeof(string));
if (o != null)
    if (data.GetDataPresent(DataFormats.Html, true))
       String htmlsnippet = (string)data.GetData(DataFormats.Html);
       processHtml(htmlsnippet); // test code that looks at the html contents
       pasteText((String)o);     // pastes the url into my app - want title too!

The problem is that the html rarely contains the title.
For example
drag this into my app and I see the url
and the htmp snippet is:

<a href=\"\"></a><!--EndFragment-->

However if I drag this link from my browser to my desk top the short-cut is
called 'BBC News - Home'

Similarly try and the shortcut is labelled ' International -
Breaking, World ...'

Can anyone help me find the title information? I don't want to retrieve the page as this will slow down the drag and drop, and anyway drag to desktop doesn't do this since it works if you go off-line and then drag a link from the browser to desktop.

[Modified: added pre tags...learn to use them, they are your friend!]
Updated 15-Sep-10 6:22am

1 solution

MemoryStream fgdStream = (MemoryStream)e.Data.GetData("FileGroupDescriptor");
byte[] fgdBytes = new byte[fgdStream.Length];
fgdStream.Read(fgdBytes, 0, fgdBytes.Length);

StringBuilder fileName = new StringBuilder();

for (int i = 76; i < fgdBytes.Length; i++)
    if (fgdBytes[i] != 0)
MessageBox.Show(fileName.Remove(fileName.Length - 4,4).ToString());

(the Remove part is because the name ends in ".URL")
Share this answer
Chrysogon 15-Sep-10 13:26pm    
That works great. Thank you so much!
Chrysogon 16-Sep-10 2:33am    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900