copying to a different computer using File.Copy()

  • Thread starter Thread starter Ram Baruch
  • Start date Start date
R

Ram Baruch

Hi,
I'm trying to use the File.Copy() function. It works well when the
desenation file is local (Like: C:\dest\dest.exe). The problem is that when
I'm trying to copy to a destenation that starts with '\\' it doesnt work and
exception is thrown (for example: \\MyComputer\DestDirectory). Even if the
first and the second directories are actually the same- the File.Copy()
doesn't work. Is there any way to copy a file to a different computer?
Regards,
Ram.
 
Hi Ram,

1) Does the account under which teh application is runnng have access to the share \\Computer\share?

2) You can try to map the drive and the n try?

3) What is teh Exception that is thrown?

~
 
Hi Ram,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you were unable to copy a file to a
shared folder on another machine on the network. If there is any
misunderstanding, please feel free to let me know.

Based on my research, we can copy a file to a shared folder on the network
using File.Copy() method. However, we have to check for permission of the
destination folder. Make sure that you have write permission to that
folder, or a System.UnauthorizedAccessException will be thrown. If that
still doesn't work, could you please show us the exception message?

HTH. If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
NewBie said:
Hi Ram,

1) Does the account under which teh application is runnng have access to the share \\Computer\share?
My test was simple: I tried to reach a local directory (Like C:\DestDir)
and then tried to reach the SAME directory through the network neighbourhood
(like \\Computer1\c\destdir).
the first one was ok, the second didn't work (although they are the same
directories).


2) You can try to map the drive and the n try?
Yes, I tried- after I map it- its ok (but it should work also
without mapping it).
3) What is teh Exception that is thrown?
the exception is "access to path ..... is denied.





Does it help???

Ram.
 
Hi,
The exception I got was "Access to path .... is denied", although I tried in
my test to reach a LOCAL directory through the network neighbourhood. When I
specified the local path (like C:\destdir) it worked ok, so its not an
authorization problem.
From what I tested, it looks that File.Copy() has problem when the
destenation path begin with "\\" . is it possible?

Regards,
Ram.
 
Hi,
The exception IS UnauthorizedAccessException but it is really strange since
I'm trying to access my own computer (and if i'm specify the local folder as
is- its ok).
What can cause this exception to be raised?

Ram.
 
Hi,
The funny thing is that if I'm trying to copy to a location on a differnet
computer- IT WORKS!!!! and if I'm trying to copy to MY computer through the
network- it doesn't work.
Well, its not a problem anymore since when my customers will use the pass
that begins with '\\' only when copying to a different computer so they
won't have the problem I had.
Anhyhow, it looks like a bug in the File.Copy(), or somewhere deeper (I
think).
Thanks,
Ram.
 
Hi Ram,

The file can be copied to the remote computer, because you have write
permission to that shared folder. Even the shared folder is on your local
computer, you might not have permission to write to it. So, please check
permission setting for that shared folder to grant write access to it. HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top