Csharp Copy File Clipboard

Give More Feedback

Copying and pasting text is relatively straightforward. See Copy and paste text to and from the clipboard C#.) When you copy files, the data copied is actually an. This article shows how to copy contents to the clipboard in the client side using jQuery. How can the answer be improved?

Just a quick note if you happen to revisit this thread, but why does that code put it into an array when you only use the first string value in that array? Also, shouldn't need to clearn the clipboar as when something gets set it replaces all existing previous clipboard data. Dim DataObject As New DataObject Dim file As String = 'C: Path' DataObject.SetData( DataFormats.FileDrop, True, file) Clipboard.SetDataObject(DataObject) Cheers ~Ace If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful ~ 'The universe is an intelligence test.' - Timothy Leary ~. You can use System.Io.File.ReadAllBytes() to get the array of byte data for the file. This is the 'file itself'.

Now to put it on the clipboard you will have to make some decisions. If you want the string path and the byte array together on the clipboard you'll want to either create a custom data structure and use Clipboard.SetDataObject() or use two calls to SetData() passing two different formats. Anjuta Ide For Windows Download on this page. Just keep in mind that setting complex data on the clipboard can get, well, complex.;) Be sure to read up on the Clipboard documentation and try to get an understanding of how IDataObject is used. Reed Kimble - 'When you do things right, people won't be sure you've done anything at all'. ' but I would like to be able to actually attach the file itself to the clipboard so it could be pasted as an attachment to an email or something like that.'

I don't think reading the bytes of the file anyways will help you attach it to an email, otherwise Reed Kimble has the correct answer for you. If you want to copy the filepath, then it's as simple as just putting that filepath itself to the clipboard Clipboard.SetText( 'FILEPATH or VARIABLE of filepath here') Otherwise, setting the inner contents of the file, if it's just a text file. Dim sr As New StreamReader( 'C:Filepath Here') Clipboard.SetText(sr.ReadToEnd) sr. Wiz Khalifa Blacc Hollywood Zip File Free. Close() sr.Dispose() However, you may come across a max limit of text that the clipboard will allow you to hold and it might raise exceptions if you try to copy files with too much data.

I've never tried before, but in that event, a simple try catch should work for you, and just pose an error message (messagebox) on the exception event. If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful ~ 'The universe is an intelligence test.'

- Timothy Leary ~. Just a quick note if you happen to revisit this thread, but why does that code put it into an array when you only use the first string value in that array? Also, shouldn't need to clearn the clipboar as when something gets set it replaces all existing previous clipboard data. Dim DataObject As New DataObject Dim file As String = 'C: Path' DataObject.SetData( DataFormats.FileDrop, True, file) Clipboard. Download Neobux Money Adder Software Informer. SetDataObject(DataObject) Cheers ~Ace If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful ~ 'The universe is an intelligence test.' - Timothy Leary ~.