473,847 Members | 2,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File.Copy

Hi I would like to use File.Copy with UNC paths. I have seen this problem
reported by others as well. Can i use File.Copy with UNC paths. ie., i would
like to copy a file from one of the folder to a shared folder. eg.,

File.Copy(srcPa th, "\\machinename\ \folder)

This is giving an error "Could not find part of the path
\\machinename\\ folder"

Is this feature supported? if yes please can anyone let me knwo how to
achieve it.

Thanks
Jul 9 '08 #1
3 5153


"Ganesha" <Ga*****@discus sions.microsoft .comwrote in message
news:83******** *************** ***********@mic rosoft.com...
Hi I would like to use File.Copy with UNC paths. I have seen this problem
reported by others as well. Can i use File.Copy with UNC paths. ie., i
would
like to copy a file from one of the folder to a shared folder. eg.,

File.Copy(srcPa th, "\\machinename\ \folder)

This is giving an error "Could not find part of the path
\\machinename\\ folder"

Is this feature supported? if yes please can anyone let me knwo how to
achieve it.

Thanks
Try escaping a double-backslash before machinename:

File.Copy(srcPa th, "\\\\machinenam e\\folder");

- OR -

File.Copy(srcPa th, @"\\machinename \folder");

I haven't tested to ensure that File.Copy can copy to a network folder via a
UNC path, so this may not be your solution, but as it stands by looking,
that could be the problem.

HTH,
Mythran
Jul 9 '08 #2
Hi Ganesha.
The problem is probably that you need to provide credentials to the current
thread before you can access the share.
if you run the program as a user who has access to the server share it
should work

in fact, if the current user has logged on with remote credentials
succesfully this session it should also work.

but if that's not an option you may need to drop into p/invoke to get
windows to manage the logon context for you.. and that's something I'd have
to look up myself.

Leon

"Mythran" <My*****@commun ity.nospamwrote in message
news:33******** *************** ***********@mic rosoft.com...
>

"Ganesha" <Ga*****@discus sions.microsoft .comwrote in message
news:83******** *************** ***********@mic rosoft.com...
>Hi I would like to use File.Copy with UNC paths. I have seen this problem
reported by others as well. Can i use File.Copy with UNC paths. ie., i
would
like to copy a file from one of the folder to a shared folder. eg.,

File.Copy(srcP ath, "\\machinename\ \folder)

This is giving an error "Could not find part of the path
\\machinename\ \folder"

Is this feature supported? if yes please can anyone let me knwo how to
achieve it.

Thanks

Try escaping a double-backslash before machinename:

File.Copy(srcPa th, "\\\\machinenam e\\folder");

- OR -

File.Copy(srcPa th, @"\\machinename \folder");

I haven't tested to ensure that File.Copy can copy to a network folder via
a UNC path, so this may not be your solution, but as it stands by looking,
that could be the problem.

HTH,
Mythran

Jul 9 '08 #3
I have an impersonation class on my blog which you call a function passing
the impersonation info (doman, username, password) and it raises an event in
which you can do the work while impersonated. When the event handler
completes, it undoes the impersonation. Its a handy tool to stop you having
to look that stuff up and do the Dll imports every time.
Let me know what you think.

--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Leon Jollans" wrote:
Hi Ganesha.
The problem is probably that you need to provide credentials to the current
thread before you can access the share.
if you run the program as a user who has access to the server share it
should work

in fact, if the current user has logged on with remote credentials
succesfully this session it should also work.

but if that's not an option you may need to drop into p/invoke to get
windows to manage the logon context for you.. and that's something I'd have
to look up myself.

Leon

"Mythran" <My*****@commun ity.nospamwrote in message
news:33******** *************** ***********@mic rosoft.com...


"Ganesha" <Ga*****@discus sions.microsoft .comwrote in message
news:83******** *************** ***********@mic rosoft.com...
Hi I would like to use File.Copy with UNC paths. I have seen this problem
reported by others as well. Can i use File.Copy with UNC paths. ie., i
would
like to copy a file from one of the folder to a shared folder. eg.,

File.Copy(srcPa th, "\\machinename\ \folder)

This is giving an error "Could not find part of the path
\\machinename\\ folder"

Is this feature supported? if yes please can anyone let me knwo how to
achieve it.

Thanks
Try escaping a double-backslash before machinename:

File.Copy(srcPa th, "\\\\machinenam e\\folder");

- OR -

File.Copy(srcPa th, @"\\machinename \folder");

I haven't tested to ensure that File.Copy can copy to a network folder via
a UNC path, so this may not be your solution, but as it stands by looking,
that could be the problem.

HTH,
Mythran
Jul 10 '08 #4

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

Similar topics

11
3665
by: BoonHead, The Lost Philosopher | last post by:
I think the .NET framework is great! It's nice, clean and logical; in contradiction to the old Microsoft. It only saddens me that the new Microsoft still doesn't under stand there own rules when it comes to file paths. A lot of Microsoft installers for example, and also installers of other companies, do not work because they handle paths in the following manner:
0
2111
by: SeanR | last post by:
I have a function to copare two files. It will first copy the original file form a different server to a local temp path and then compare that version to a version that has been restored form tape. Once the compare is complete the file that was copied to a temp location needs to be deleted. I am using the method file.copy(sourcePath, tempPath, true) to copy the file and then file.delete(tempPath) to delete the file. On some of the files...
2
621
by: RitaG | last post by:
Hi. In a VB.Net program I use File.Copy to copy some zipped (and text) files from one server to another. I'm required by management to do a file compare after the copy has completed. Is the File.Copy sufficient and it will error out if there's a problem or do I need to do a file compare to make sure nothing went wrong in the copy? If I do need to do a file comapre I was thinking about shelling out and running a bat file to use the Dos...
5
1911
by: DraguVaso | last post by:
Hi, I need a SECURE way to copy parts of a file. I'm having files which contains a whole bunch of records. In one 'fysical' file I'm having one or more logical files. What I need to do is to copy a logical file (a part of the fysical file) into a new file. But the 'big' problem is: these records contains bankstatements, so I can't take the risk that there would be a record missing, or even one little charachter. The copy I make has to...
8
2942
by: luis molina Micasoft | last post by:
it seems that when i do file.copy the svchost.exe is hanged, i mean if i make 40 threads of file.copy , 40 copys of files at same time the system is going down and stop responding, this is when i'm working with cifs (shares). there is another solution to copy files than file.copy in .net?
8
9773
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network drive resource (S:\Path\FileName). Here is my problem: my vb.net program has problems with UNC. If the UNC server is restarted or goes off-line, my VB.net program crashes. The code for UNC access to the file is included below and is put in the tick event of a form timer control running every...
1
3547
by: Rachel McConnell | last post by:
Hi, I am trying to import data using COPY, from a file containing thirty or so COPY commands each with 0 or more rows of data. Reason, I have a small data set I want to include into a database with an identical schema, with existing data. I figured a good way to do this would be to use pg_dump on the small dataset, trim out the table definitions and constraints, and run the resulting file. (I also reordered the COPY statements to...
3
12867
by: maheshkadam | last post by:
Hi friends I am new to perl so please guide me. I have one application which created backup log file every day.But it appends that file so you can see logs for different day in one file only. My requirement is to copy backup log for the specific day (yesterday) and write in other file. That file will be mailed to admin for ready reference. So here is some text from that log file
1
4341
by: =?Utf-8?B?UmFkZW5rb19aZWM=?= | last post by:
I am using standard File.Copy(source,dest,true) method in C# and I have problem with copying large number of files. Here is my code: foreach (FileInfo file in files) { File.Copy(file.FullName,destPath+ "\\" + file.Name, true); } This code copies only 5 or 10 files but in "files" collection there is 60 files.
0
9727
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
10981
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...
0
10643
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10706
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
10330
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
7050
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
5716
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
5907
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3158
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.