472,352 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,352 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 15808
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...
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...
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...
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...
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...
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...
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...
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...
3
vdraceil
by: vdraceil | last post by:
Does anyone know how to copy a file to the clipboard using vb6?
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

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.