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

File.Copy

P: n/a
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(srcPath, "\\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
Share this Question
Share on Google+
3 Replies


P: n/a


"Ganesha" <Ga*****@discussions.microsoft.comwrote in message
news:83**********************************@microsof t.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(srcPath, "\\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(srcPath, "\\\\machinename\\folder");

- OR -

File.Copy(srcPath, @"\\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

P: n/a
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*****@community.nospamwrote in message
news:33**********************************@microsof t.com...
>

"Ganesha" <Ga*****@discussions.microsoft.comwrote in message
news:83**********************************@microsof t.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(srcPath, "\\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(srcPath, "\\\\machinename\\folder");

- OR -

File.Copy(srcPath, @"\\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

P: n/a
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*****@community.nospamwrote in message
news:33**********************************@microsof t.com...


"Ganesha" <Ga*****@discussions.microsoft.comwrote in message
news:83**********************************@microsof t.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(srcPath, "\\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(srcPath, "\\\\machinename\\folder");

- OR -

File.Copy(srcPath, @"\\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 discussion thread is closed

Replies have been disabled for this discussion.