Programmatically filling the clipboard fails : Automation API

Programmatically filling the clipboard fails

Class library usage, coding and language questions.

Programmatically filling the clipboard fails

Postby surszer » Mon Jul 04, 2011 9: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
surszer
 
Posts: 8
Joined: Mon Jun 27, 2011 9:26 am

Re: Programmatically filling the clipboard fails

Postby Support Team » Mon Jul 04, 2011 6: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
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: Programmatically filling the clipboard fails

Postby surszer » Tue Jul 05, 2011 8:54 am

Hello Support Team,

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

Thanks

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


Return to Automation API

Who is online

Users browsing this forum: No registered users and 0 guests