File.Copy

G

Ganesha

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
 
M

Mythran

Ganesha said:
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
 
L

Leon Jollans

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
 
C

Ciaran O''Donnell

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.
 

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

Top