I want to paste files copied to clipboard to a specific folder using the below vb.net code
but i keep on getting clipboard is not a member of system.windows.forms. I have imported the system.windows.forms. Does any one know how to reasolve the issue.
Dim destinationFolder As String = “C:\Users--”
’ Get the list of file paths from the clipboard
Dim filePaths As StringCollection = System.Windows.Forms.Clipboard.GetFileDropList()
Dim list As IEnumerable(Of String) = filePaths.Cast(Of String)()
’ Copy each file from the clipboard to the destination folder
For Each filePath As String In filePaths
Dim fileName As String = Path.GetFileName(filePath)
Dim destinationPath As String = Path.Combine(destinationFolder, fileName)
File.Copy(filePath, destinationPath)
Next
Give a try at:
Result | DataType: Object = System.Windows.Clipboard.GetData(DataFormats.FileDrop)
Then we can cast it to StringCollection by: DirectCast(Result, System.Collections.Specialized.StringCollection)
Similar to your code line above for preparing the loop we can do:
BTW: When possible we do avoid Automations doing mimics like copy / paste when dealing with files from file system and do using API / Activities for this actions instead
Thanks for the help this worked.
I added assign statment above the invoke code System.Windows.Clipboard.GetData(DataFormats.FileDrop) and assigned it to a temp varible. this fixed the issue with clipboard not available error.
The reason i’m using this is actually because im connecting to a remort desktop which is has very strict rules. this prevent me from any other option. Not a huge fan of using open application for explorer and then pasting.