Programmatically filling the clipboard fails

Class library usage, coding and language questions.
surszer
Posts: 8
Joined: Mon Jun 27, 2011 8:26 am

Programmatically filling the clipboard fails

Post by surszer » Mon Jul 04, 2011 8:55 am

Hello,

I fail to copy files programmatically to the clipboard using c# in Ranorex. The code does work perfectly in Visual Studio but whenever I use it within a Ranorex Code-Module the clipboard stays empty.
The code:
public static void FillClipboard(List<string> paths)
{
   if (paths.Count > 0)
   {
      System.Collections.Specialized.StringCollection col = new System.Collections.Specialized.StringCollection();
      foreach (string s in paths)
         col.Add(s);
      System.Windows.Forms.DataObject data = new System.Windows.Forms.DataObject();
      data.SetFileDropList(col);
      Clipboard.SetDataObject(data);
   }
}
Can you please help me with that?

Regards,

Surs

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Programmatically filling the clipboard fails

Post by Support Team » Mon Jul 04, 2011 5:44 pm

Are the file paths in the "paths" argument relative or absolute? If they are relative, the working directory could be different when running the test module and thus the paths could be invalid.

Is the test suite still running when you try to paste the files? If not, try to specify "true" as the second parameter of the "SetDataObject" call in order to place a persistent copy of the data onto the clipboard:
Clipboard.SetDataObject(data, true);
Regards,
Alex
Ranorex Team

surszer
Posts: 8
Joined: Mon Jun 27, 2011 8:26 am

Re: Programmatically filling the clipboard fails

Post by surszer » Tue Jul 05, 2011 7:54 am

Hello Support Team,

setting the 2nd parameter "true" did the trick.

Thanks

Surs