473,847 Members | 1,459 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

copying to a different computer using File.Copy()

Hi,
I'm trying to use the File.Copy() function. It works well when the
desenation file is local (Like: C:\dest\dest.ex e). 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\De stDirectory). 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.
Nov 16 '05 #1
8 17047
Hi Ram,

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

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

3) What is teh Exception that is thrown?

~

"Ram Baruch" wrote:
Hi,
I'm trying to use the File.Copy() function. It works well when the
desenation file is local (Like: C:\dest\dest.ex e). 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\De stDirectory). 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.

Nov 16 '05 #2
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
misunderstandin g, 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.Unauthor izedAccessExcep tion 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."

Nov 16 '05 #3

"NewBie" <Ne****@discuss ions.microsoft. com> wrote in message
news:85******** *************** ***********@mic rosoft.com...
Hi Ram,

1) Does the account under which teh application is runnng have access to the share \\Computer\shar e? 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\d estdir).
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.
~

"Ram Baruch" wrote:
Hi,
I'm trying to use the File.Copy() function. It works well when the
desenation file is local (Like: C:\dest\dest.ex e). 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\De stDirectory). 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.

Nov 16 '05 #4
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.

"Kevin Yu [MSFT]" <v-****@online.mic rosoft.com> wrote in message
news:%2******** ********@cpmsft ngxa10.phx.gbl. ..
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
misunderstandin g, 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.Unauthor izedAccessExcep tion 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."

Nov 16 '05 #5
Hi,
The exception IS UnauthorizedAcc essException 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.

"Kevin Yu [MSFT]" <v-****@online.mic rosoft.com> wrote in message
news:%2******** ********@cpmsft ngxa10.phx.gbl. ..
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
misunderstandin g, 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.Unauthor izedAccessExcep tion 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."

Nov 16 '05 #6
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.

"Ram Baruch" <ra*********@ne wsgroups.nospam > wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi,
The exception IS UnauthorizedAcc essException 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.

"Kevin Yu [MSFT]" <v-****@online.mic rosoft.com> wrote in message
news:%2******** ********@cpmsft ngxa10.phx.gbl. ..
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
misunderstandin g, 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.Unauthor izedAccessExcep tion 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."


Nov 16 '05 #7
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."

Nov 16 '05 #8
Ok, thanks!
Ram.

"Kevin Yu [MSFT]" <v-****@online.mic rosoft.com> wrote in message
news:O7******** *****@cpmsftngx a10.phx.gbl...
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."

Nov 16 '05 #9

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

Similar topics

3
3661
by: Robert Tarantino | last post by:
Hello, I am trying to find a way to create a scheduled task or service that will copy my local profile folders under "Documents and settings" to a network drive. This would allow me to restore my settings if my profile became tampered with or corrupt. Is there any sample code available out there? -Robert
2
1491
by: Richard Jonas | last post by:
I've written a Windows Application in C#.net that runs in the background and silently archives files to a network drive (using the System.IO.File.Copy function). Sometimes, users may run this application when connected to our network via a dial-up connection. This means that files take a long time to copy. If users try and shut down their computer whilst a file is copying, an error message is shown and the only way to shut down the...
1
6678
by: Bhavya Shah | last post by:
Hello All, I am facing a serious problem while copying a file to a remote computer programmatically. What I want to do: I want to connect to a remote computer and copy a file to the remote computer programmatically. I have the administrator username and password of the remote computer. Can anyone tell me how this can be done? I have tried using ManagementScope but it does not work.
5
2357
by: TB | last post by:
Hi All: This news group is proving to be great help on my path towards mastering ASP.NET thanks to all of you helpful souls out there. I am looking forward to the day when I can contribute with a few ounces of hard-won knowledge as well. Meanwhile I have this (hopefully small) problem.
20
37922
by: TC | last post by:
I need an automated procedure to copy data from an Access table to a SQL Server table. Speed is important. What is the recommended technique? I can export the data from Access, copy it via FTP, then import it into SQL Server. I've tried that, and the speed is acceptable. It is an ugly solution, however, and I expect to find a better one -- preferably a solution better integrated with the Access RDBMS. I've tried using an ODBC...
2
1792
by: jatphat | last post by:
Somebody help me. How do i copy my Access database from one location on my hard disk to another . i tried file.copy(source, distination ) but the file would not move. i always get this error message "Another process is using the destinationFileName" . thanks
2
8138
by: Edhy Rijo [Progytech] | last post by:
Hi All, I am learning VB.NET and building small application that will do the following: 1.. Copy all files from a DVD to a specific folder in the hard drive and overwrite all files always. The problem I am facing is that the copy statement I am using is that when overwriting the files it will prompt for each file, so I can not find an option to tell it to overwrite all. If strCopyToFolder.EndsWith("\") = False Then strCopyToFolder +=...
9
3939
by: pooba53 | last post by:
My VB .NET application (created in VS 2003) resides in c:\Program Files \Test\ and there's a data.mdb (Access) file within this directory. I have a feature in my program that allows the user to import a backup copy of this Access db if they need to. I'm using the FileCopy method to simply copy over the data.mdb file within the directory above. However, I get a "System.UnauthorizedAccessException: Access to the path: c:\Program...
13
10777
by: writeson | last post by:
Hi all, I'm writing some code that monitors a directory for the appearance of files from a workflow. When those files appear I write a command file to a device that tells the device how to process the file. The appearance of the command file triggers the device to grab the original file. My problem is I don't want to write the command file to the device until the original file from the workflow has been copied completely. Since these...
0
9734
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10995
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10718
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10347
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9493
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7061
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5729
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5915
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.