Windows Develop Bookmark and Share   
 index > Windows Forms General > Copying a File/Application Shortcut from the Desktop to the Office Clipboard
 

Copying a File/Application Shortcut from the Desktop to the Office Clipboard

I currently have an application which is used to replace all my old redundant links, however i want to be able to use my application to copy the shortcut to a file from the desktop to the office clipboard! I have tried the following code but it does not add the required shortcut to the clipboard, it comes back saying format not supported by clipboard. I would be grateful for any help and any sample code. Any questions please ask. My code is as follows:

System.Collections.Specialized.StringCollection files = new System.Collections.Specialized.StringCollection();
files.Add(my file here);
Clipboard.SetFileDropList(files);
SuperSav144  Monday, September 14, 2009 7:28 PM
Following code is working fine for me :
string[] files = System.IO.Directory.GetFiles(@"D:\Music\English");
            StringCollection scoll = new StringCollection();
            foreach (string s in files)
                scoll.Add(s);
            System.Windows.Forms.Clipboard.SetFileDropList(scoll);
can you tell me the exact exception that you are getting..

Paras
paras kumar  Monday, September 14, 2009 10:19 PM
Hi SuperSav,

The extension name for a shortcut is "lnk".
For example,
System.Collections.Specialized.StringCollection stringCollection = new System.Collections.Specialized.StringCollection();
stringCollection.Add(@"D:\a.lnk ");
Clipboard.SetFileDropList(stringCollection);

If you use
System.Collections.Specialized.StringCollection stringCollection = new System.Collections.Specialized.StringCollection();
stringCollection.Add(@"D:\a ");
Clipboard.SetFileDropList(stringCollection);

No error will popup, but the set Clipboard action is failed. You cannot paste that shortcut file.

Hope this give you some light.

If you have any question, please feel free to tell me.

Sincerely,
Kira Qian
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!
Kira Qian  Thursday, September 17, 2009 7:04 AM
Following code is working fine for me :
string[] files = System.IO.Directory.GetFiles(@"D:\Music\English");
            StringCollection scoll = new StringCollection();
            foreach (string s in files)
                scoll.Add(s);
            System.Windows.Forms.Clipboard.SetFileDropList(scoll);
can you tell me the exact exception that you are getting..

Paras
paras kumar  Monday, September 14, 2009 10:19 PM
I don't get an actual error when running theapplication, the application runsbut an error comes up from the clipboard saying 'Item not collected: Format not supported by office clipboard'.
SuperSav144  Tuesday, September 15, 2009 8:13 AM
Hi SuperSav,

The extension name for a shortcut is "lnk".
For example,
System.Collections.Specialized.StringCollection stringCollection = new System.Collections.Specialized.StringCollection();
stringCollection.Add(@"D:\a.lnk ");
Clipboard.SetFileDropList(stringCollection);

If you use
System.Collections.Specialized.StringCollection stringCollection = new System.Collections.Specialized.StringCollection();
stringCollection.Add(@"D:\a ");
Clipboard.SetFileDropList(stringCollection);

No error will popup, but the set Clipboard action is failed. You cannot paste that shortcut file.

Hope this give you some light.

If you have any question, please feel free to tell me.

Sincerely,
Kira Qian
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!
Kira Qian  Thursday, September 17, 2009 7:04 AM

You can use google to search for other answers

Custom Search

More Threads

• Strange RichTextBox.Select(0,x) Problem / Bug?
• how to check whether particular form is active or not
• Using DrawToDC with .NET 2.0 WebBrowser Control
• DataGridView -- Dynamic Cell Style Change
• microsoft visual Studio help needed please
• set flag to listbox item that retrieved from registry
• Problem with Icon on Child Form
• How to make controls appearance independed from windows theme
• C# 2005 Sort ListView by column
• outlook express 6 help need to close