473,386 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Copying a File To The Clipboard

Hi folks,

I know how to place text into the user's clipboard:
Clipboard.SetDataObject("My Copied Text");
but how do I place a file in there?

So, if I have a file C:\test.txt, how can I place that file into the user's
clipboard so that they can later paste it into explorer?

Thanks!!!
Nov 17 '05 #1
8 16136
Hello John,

I dont remember the author who wrote pretty nice about clipboard, but the
general idea is u can specify the format
for Clipboard and describe how to treat and save some types of data. For
example copy/paste of picture performing directly through clipboad.
But files use in other way. U just keep a path to file and when pasting u
perform copying

JS> I know how to place text into the user's clipboard:
JS> Clipboard.SetDataObject("My Copied Text");
JS> but how do I place a file in there?
JS> So, if I have a file C:\test.txt, how can I place that file into the
JS> user's clipboard so that they can later paste it into explorer?
JS>
JS> Thanks!!!
JS>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/members/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Nov 17 '05 #2
Thanks, but I'm looking for some sample code because I've been trying to get
this working for a while now and did a bunch of searching on the topic all
with no success.

Does anyone have any sample code for how to copy the file C:\test.txt into
the user's clipboard? I need to support multiple filetypes (like pdf, doc,
zip...).

"Michael Nemtsev" <ne*****@msn.com> wrote in message
news:43***************************@msnews.microsof t.com...
Hello John,

I dont remember the author who wrote pretty nice about clipboard, but the
general idea is u can specify the format
for Clipboard and describe how to treat and save some types of data. For
example copy/paste of picture performing directly through clipboad.
But files use in other way. U just keep a path to file and when pasting u
perform copying

JS> I know how to place text into the user's clipboard:
JS> Clipboard.SetDataObject("My Copied Text");
JS> but how do I place a file in there?
JS> So, if I have a file C:\test.txt, how can I place that file into the
JS> user's clipboard so that they can later paste it into explorer?
JS>
JS> Thanks!!!
JS>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/members/laflour

"At times one remains faithful to a cause only because its opponents do not cease to be insipid." (c) Friedrich Nietzsche

Nov 17 '05 #3
John Smith wrote:
Does anyone have any sample code for how to copy the file C:\test.txt into
the user's clipboard? I need to support multiple filetypes (like pdf, doc,
zip...).


You don't really copy the file to the clipboard, but rather a reference to
it in the form of a PIDL (a Windows Shell id). You also need to adhere to
a specific format called "Shell IDList Array". I searched Google for it
and found a nice CodeProject article that shows something quite similar in
VB.NET. Here it is: http://www.codeproject.com/useritems...eeDragDrop.asp
Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)
Nov 17 '05 #4
Sorry....no go. I need a real sample of copying a file to the clipboard.
Seems like the only file that's easy to copy is a bitmap image.
Anyone got one? It seems like it's never been done before. I've been
researching it for hours.
"Oliver Sturm" <ol****@sturmnet.org> wrote in message
news:xn****************@msnews.microsoft.com...
John Smith wrote:
Does anyone have any sample code for how to copy the file C:\test.txt intothe user's clipboard? I need to support multiple filetypes (like pdf, doc,zip...).
You don't really copy the file to the clipboard, but rather a reference to
it in the form of a PIDL (a Windows Shell id). You also need to adhere to
a specific format called "Shell IDList Array". I searched Google for it
and found a nice CodeProject article that shows something quite similar in
VB.NET. Here it is:

http://www.codeproject.com/useritems...eeDragDrop.asp

Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)

Nov 17 '05 #5
Finally got it and it's pretty easy. I was trying this earlier and it
wasn't working, but that's because I didn't have the file name as an array
(how annoying!):

DataObject objData = new DataObject();
string []filename = new string[1];
filename[0] = "c:\\testFile.exe";
objData.SetData(DataFormats.FileDrop, true, filename);
Clipboard.SetDataObject(objData, true);

"John Smith" <m@ty.com> wrote in message
news:uI**************@TK2MSFTNGP15.phx.gbl...
Sorry....no go. I need a real sample of copying a file to the clipboard.
Seems like the only file that's easy to copy is a bitmap image.
Anyone got one? It seems like it's never been done before. I've been
researching it for hours.
"Oliver Sturm" <ol****@sturmnet.org> wrote in message
news:xn****************@msnews.microsoft.com...
John Smith wrote:
Does anyone have any sample code for how to copy the file C:\test.txt intothe user's clipboard? I need to support multiple filetypes (like pdf, doc,zip...).


You don't really copy the file to the clipboard, but rather a reference to it in the form of a PIDL (a Windows Shell id). You also need to adhere to a specific format called "Shell IDList Array". I searched Google for it
and found a nice CodeProject article that shows something quite similar in VB.NET. Here it is:

http://www.codeproject.com/useritems...eeDragDrop.asp


Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)


Nov 17 '05 #6
Smith,
Similar problem i am facing, thanks for your code snippet for file
copying to clipboard.
Now, how do I get back that file from clipboard or paste in some other
location.

Thanks,
Dhans

"John Smith" wrote:
Finally got it and it's pretty easy. I was trying this earlier and it
wasn't working, but that's because I didn't have the file name as an array
(how annoying!):

DataObject objData = new DataObject();
string []filename = new string[1];
filename[0] = "c:\\testFile.exe";
objData.SetData(DataFormats.FileDrop, true, filename);
Clipboard.SetDataObject(objData, true);

"John Smith" <m@ty.com> wrote in message
news:uI**************@TK2MSFTNGP15.phx.gbl...
Sorry....no go. I need a real sample of copying a file to the clipboard.
Seems like the only file that's easy to copy is a bitmap image.
Anyone got one? It seems like it's never been done before. I've been
researching it for hours.
"Oliver Sturm" <ol****@sturmnet.org> wrote in message
news:xn****************@msnews.microsoft.com...
John Smith wrote:

>Does anyone have any sample code for how to copy the file C:\test.txt

into
>the user's clipboard? I need to support multiple filetypes (like pdf,

doc,
>zip...).

You don't really copy the file to the clipboard, but rather a reference to it in the form of a PIDL (a Windows Shell id). You also need to adhere to a specific format called "Shell IDList Array". I searched Google for it
and found a nice CodeProject article that shows something quite similar in VB.NET. Here it is:

http://www.codeproject.com/useritems...eeDragDrop.asp


Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)



Nov 17 '05 #7
I haven't actually done it because it's not in my project scope, but it
shouldn't be too hard from what I've seen. You basically just do the
reverse. This is completely untested code, and will just get you started,
but it should go a little something like this:

IDataObject objData2 = Clipboard.GetDataObject();
if(objData2.GetDataPresent(DataFormats.FileDrop, true)) // Check to see if
the data is in the clipboard
{
//Create file using something like:
//myFile = objData2.GetData(DataFormats.FileDrop, true);
//and then write it out using the System.IO namespace classes
}

When you figure it out, post it here for the future frustrated programmer to
see :)


"Dhans" <Dh***@discussions.microsoft.com> wrote in message
news:8D**********************************@microsof t.com...
Smith,
Similar problem i am facing, thanks for your code snippet for file
copying to clipboard.
Now, how do I get back that file from clipboard or paste in some other
location.

Thanks,
Dhans

"John Smith" wrote:
Finally got it and it's pretty easy. I was trying this earlier and it
wasn't working, but that's because I didn't have the file name as an array (how annoying!):

DataObject objData = new DataObject();
string []filename = new string[1];
filename[0] = "c:\\testFile.exe";
objData.SetData(DataFormats.FileDrop, true, filename);
Clipboard.SetDataObject(objData, true);

"John Smith" <m@ty.com> wrote in message
news:uI**************@TK2MSFTNGP15.phx.gbl...
Sorry....no go. I need a real sample of copying a file to the clipboard. Seems like the only file that's easy to copy is a bitmap image.
Anyone got one? It seems like it's never been done before. I've been
researching it for hours.
"Oliver Sturm" <ol****@sturmnet.org> wrote in message
news:xn****************@msnews.microsoft.com...
> John Smith wrote:
>
> >Does anyone have any sample code for how to copy the file C:\test.txt into
> >the user's clipboard? I need to support multiple filetypes (like pdf, doc,
> >zip...).
>
> You don't really copy the file to the clipboard, but rather a reference
to
> it in the form of a PIDL (a Windows Shell id). You also need to
adhere to
> a specific format called "Shell IDList Array". I searched Google for
it > and found a nice CodeProject article that shows something quite

similar in
> VB.NET. Here it is:
http://www.codeproject.com/useritems...eeDragDrop.asp
>
>
> Oliver Sturm
> --
> Expert programming and consulting services available
> See http://www.sturmnet.org (try /blog as well)


Nov 17 '05 #8
Thanks Smith,
I can get the name of the files which are copied into clipboard, here is the
code snippet. May be its not 100% correct code... but it works for me

object fromClipboard;
IDataObject fileData = Clipboard.GetDataObject();
if( fileData.GetDataPresent(DataFormats.FileDrop, true) )
{
//it returning array of filenames present inside clipboard
fromClipboard = fileData.GetData(DataFormats.FileDrop, true);

foreach( string sourceFileName in (Array)fromClipboard)
MessageBox.Show(sourceFileName);
}
else
MessageBox.Show(this, "File not present in clipboard");

Nov 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gey-Hong Gweon | last post by:
Is there a way to copy a PIL image to windows clipboard (as a dib image or a bitmap, I suppose)? What I would like to accomplish is to do a fast copy and paste of images from my python...
0
by: Ata | last post by:
Hello, I am trying to copy the contents of the output of SQL Reporting Services to a PowerPoint slide. For this, I am using SQL Reporting Services to obtain an IMAGE stream, which I paste to the...
16
by: DataBard007 | last post by:
I have an Access97 application whose form contains many text boxes. What do I have to do in order to copy the contents of one of these text boxes to the clipboard? I want to do this so I can then...
9
by: Christian Blackburn | last post by:
Hi Gang, I don't know what to make of all of this, but I'm having nothing, but trouble copying data to the clipboard which should be the easiest thing in the world. The only systems I can get...
4
by: fred | last post by:
I am trying to copy a file onto the clipboard but I am not having any success. Perhaps someone can help me out. I have the full file name from my application and to put it onto the clipboard I...
4
by: gordon | last post by:
Hi I hav e a smallish app that has a datagridview. A user can select some columns in the datagrid, and i have a button that i would like to use to copy the rows that are selected to the...
19
by: Jeff | last post by:
....working with visualweb.net 2005 and vb. ....trying to simply copy the contents from a textbox to the clipboard. I've looked at a large number of places on line and they give me various...
0
by: MathewJose | last post by:
Hi, I have a DatagridView in windows form.It has got a column which has some names that are populated from master table in database.Now i need to copy a set of data against these names. I...
3
vdraceil
by: vdraceil | last post by:
Does anyone know how to copy a file to the clipboard using vb6?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.