I have done quite a few research, but there were no fruits so far...
The only links that I found are somewhat similar to my situation don't even work either:
- Simple drag and drop example
- How can I tell a shortcut from a file in a C# drag and drop operation?
- Drag and Drop Files with C#
- drag and drop file into textbox
- e.Data.GetDataPresent not working in WinForms drag-and-drop handler?
Basically, first of all, I want the code to be able to recognize that the file is of a ".url" extension, or rather, an internet shortcut, most typically employed by Google Chrome, as well as Mozilla Firefox, and most likely, all other web browsers which I did not extensively test.
In case you do not know what type of shortcut I am referring to, I mean something like in the picture below.
Below is the current code that I am using in the DragDrop event handler of a textbox, and it doesn't seem to work:
string file = (string)(e.Data.GetData(DataFormats.FileDrop, false));
if (Path.GetExtension(file) == ".url")
{
//Do Stuff Here
}
Apparently, the code can't even get the supposed file name of the shortcut. This shortcut is the kind that has already been dragged and dropped to the desktop from a browser. Thus, in this case, that shortcut is the one being dragged and dropped for the code to process.
(Not sure if this will make any difference, but I tried substituting "DataFormats.FileDrop" with "DataFormats.Serialization" as well as "DataFormats.Html" with no postitive effects.)
Also, for some weird reason, the program immediately breaks off at the very first line of the code block above. (It also happens to be the very first line in my DragDrop event)
My question is: How can the code be corrected or modified (to any extent, even if completely changing the code) so that it can recognize the internet shortcut file of .url extension, then proceed to treat it like a normal file.
Also, why is the execution of the code immediately stopping right after executing the first line, even though breakpoints have been set for the few lines after the first line (as in skipping the if statement completely)?
And if it is not too much, how to only let the line below:
e.Effect = DragDropEffects.Link;
work when the file is only of the internet shortcut type, ".url", in the DragEnter event handler, or is that impossible?
I know that Notepad++ is able to open and read the contents and even edit the internet shortcut files. Although if I can get the code to recognize the shortcut, I think I will then be able to read from it like a normal file.
I would prefer an answer with working code, if possible. Sorry for the long question, as I wanted to try to be as precise as possible with my question.