By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,033 Members | 1,285 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,033 IT Pros & Developers. It's quick & easy.

Clipboard - How to determine file is cut or copied ?

P: n/a

Hi all,
I encountered a serious problem while working with
clipboard class in VB.NET.
I want to simulate cut-copy-paste operation with
my application and Windows Explorer.
User can copy files from Explorer and paste it into
my application & vice-a-versa.
My question is-
How can I determine if user has copied or cut the files
from Windows Explorer? I want to differentiate cut & copy.
I am using clipboard class to handle all this.

Please help,

Thanks in advance,

-Regards,
Dinesh

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Unfortunately, you can't, because the Clipboard object just carries the
data, it's explorer that decides whether or not to move the file, or copy
the file.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Chaos, Panic, Disorder, my work here is done"
"Dinesh Jain" <di*******@hotmail.com> wrote in message
news:ed*************@TK2MSFTNGP09.phx.gbl...
:
: Hi all,
: I encountered a serious problem while working with
: clipboard class in VB.NET.
: I want to simulate cut-copy-paste operation with
: my application and Windows Explorer.
: User can copy files from Explorer and paste it into
: my application & vice-a-versa.
: My question is-
: How can I determine if user has copied or cut the files
: from Windows Explorer? I want to differentiate cut & copy.
: I am using clipboard class to handle all this.
:
: Please help,
:
: Thanks in advance,
:
: -Regards,
: Dinesh
:
:
:
: *** Sent via Developersdex http://www.developersdex.com ***
: Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #2

P: n/a
Hi Tom,
Thnaks for the reply.
I searched under MSDN and came to know that when
we cut files from explorer and paste inside our
application, we need to send some confirmation to the
explorer about the paste opartion is completed or not.
But I am not able to find how to implement it in VB.NET.
Pls. search for "Handling Shell Data Transfer Scenarios"
in MSDN.

Please help,

Thanks in advance,

-Regards,
Dinesh
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #3

P: n/a

All experts,
No Answer for this question ?
I want to programatically cut a file from VB.NET.
Please help,

Thanks in advance,

-Regards,
Dinesh

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #4

P: n/a
Cor
Hi,
Therefore you need no expert,
You can try it yourself.
Copy files from explorer.
Open the notepad and try to paste.
Nothing there I think.
So it seems if the clipboard is not used

That means for me that it looks if Explorer uses the following system.
When you copy, it clears the clipboard.
It saves the data somewhere (inclusive a copy or cut parameter)
When you paste on another place I think it does the following.
If the parameter is "cut it starts using the "file move" method and else
when it is "copy" it uses the "file copy" method

So when you want to do something to simulate that, I think you need the
whole process.
(And not such a big job to do with vb.net)

When you want to know where explorer saves this data, that is another
question, but I don't believe that is VB.net language, more a Windows
question. It can be for every version different (although you only have to
know it of course for systems that use the framework).

I hope this helps you further on the route.

Cor

Nov 20 '05 #5

P: n/a
Hi Cor,

No. Unfortunately you are wrong. The Clipboard *is* used. You can't paste
anything into notepad because it's not text in the clipboard, it's another
form of data. Also, Windows just doesn't copy the contents of the file into
the clipboard, it copies the location of the file and what it needs to do to
it there, and when the operation is completed, e.g. what Dinesh is trying to
do (tell explorer that the operation has completed), then explorer will
either A. Copy the file to the new location, B. Move the file to the new
location.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Chaos, Panic, Disorder, my work here is done"
"Cor" <no*@non.com> wrote in message
news:3f***********************@reader20.wxs.nl...
: Hi,
: Therefore you need no expert,
: You can try it yourself.
: Copy files from explorer.
: Open the notepad and try to paste.
: Nothing there I think.
: So it seems if the clipboard is not used
:
: That means for me that it looks if Explorer uses the following system.
: When you copy, it clears the clipboard.
: It saves the data somewhere (inclusive a copy or cut parameter)
: When you paste on another place I think it does the following.
: If the parameter is "cut it starts using the "file move" method and else
: when it is "copy" it uses the "file copy" method
:
: So when you want to do something to simulate that, I think you need the
: whole process.
: (And not such a big job to do with vb.net)
:
: When you want to know where explorer saves this data, that is another
: question, but I don't believe that is VB.net language, more a Windows
: question. It can be for every version different (although you only have to
: know it of course for systems that use the framework).
:
: I hope this helps you further on the route.
:
: Cor
:
:
:
Nov 20 '05 #6

P: n/a
Cor
Tom,

You are totally right.
My explanation was written in a popular way and even with fundamental
errors.

Because of your message I did really investigate it and as deep as I can go.
(That is not so deep). The results do not change in my opinion.

It seems if explorer does the entire thing intern and does not even save
things.
I did try the following things:
- What is happening if I copy and cut (that we know)
- What is happening when I cut and close all explores open an explorer and
paste on another place. The result is that there are two files.
- What happens if I cut in one explorer, open another, close the first, and
paste in the second.
My result was that I had one file.

So my conclusion is that explorer not even saves the information about a
"cut", it is in a public part of the explorer.exe program itself when it is
running.

I've never seen some automation on it so you really have to know everything
of all versions to realize what is asked I think.

I tested what happened when I did a cut in explorer and then a copy from the
clipboard
The files which were cut where not thrown away or brought to the trash bin.

So the conclusion stays the same, now maybe something more professional.

My test program is beneath, with that you can copy files from the clipboard.

\\\\\
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim iData As IDataObject = Clipboard.GetDataObject()
If iData.GetDataPresent(DataFormats.FileDrop) Then
Dim tom As String() =
DirectCast(iData.GetData(DataFormats.FileDrop), String())
Dim i As Integer
Me.FolderBrowserDialog1.ShowDialog()
For i = 0 To tom.Length - 1
If
System.IO.File.Exists(Me.FolderBrowserDialog1.Sele ctedPath &
tom(i).Substring(tom(i).LastIndexOf("\"))) Then
System.IO.File.Move(Me.FolderBrowserDialog1.Select edPath
& tom(i).Substring(tom(i).LastIndexOf("\")), _
Me.FolderBrowserDialog1.SelectedPath &
"temptemptemp.temp")
End If
System.IO.File.Copy(tom(i),
Me.FolderBrowserDialog1.SelectedPath &
tom(i).Substring(tom(i).LastIndexOf("\")))
If
System.IO.File.Exists(Me.FolderBrowserDialog1.Sele ctedPath &
"temptemptemp.temp") Then

System.IO.File.Delete(Me.FolderBrowserDialog1.Sele ctedPath &
"temptemptemp.temp")
End If
Next
End If
End Sub
//////////

Again a nice test
Cor


Nov 20 '05 #7

P: n/a
Hi Tom,

I've stayed quiet on this one because I don't have a solution - still
researching - but now I must speak, at least as far as I understand this
stuff.

Explorer sends the file names or a list of file names. It <does> give an
indication of whether it's a move (cut) or copy operation. It's up to the
receiving application to actually do the job with the files - not Explorer. If
the job is a copy then the receiving app copies the file(s) and the job's
done. If it's a move operation, the receiving app copies the file(s) and then
sends a message <back> to Explorer to say that the copies were made. Explorer
then does the <delete>.

The problem for Dinesh is that the .NET Clipboard doesn't (as far as I can
work out) send <back> to the sending application. It's possible to tell that a
move is required but not to tell Explorer that it's been done. The
documentation is, as usual :-(, full of trivial inter-app examples (how to
send text), but doesn't show the hard stuff - copying files to/from Explorer.

It's possible to do what Dinesh wants by ignoring the Clipboard class
(perhaps) and getting into the API (certainly). The 'how' is still beyond me.
:-(

Regards,
Fergus
Nov 20 '05 #8

P: n/a
Cor
Fergus,
I dont believe that explorer sends a message that it has a cut/copy.
It keeps it for itself as long as it is alive in memory, and then it is
flushed I think.
Explorer is an exe no dll.
Try it yourself what I was experimenting.
Cor
Nov 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.