C# file copy to UNC path

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How does one copy a file to a UNC path and include authentication?

My current code is:

System.IO.File.Copy(@"c:\picture.jpg", @"\\server\share\picture.jpg");

Of course I just get a login failed for this, as I don't know how to
transmit authentication information with the request.

Anyone know how to do this?
 
The "right" way to do this is probably to grant the principle the proper
access rights, however if you've ruled that out and are willing to
accept the security implications involved, you could issue a "net use"
command via System.Diagnostics.Process.Start(...) prior to trying to
copy the file. You can find the syntax for it by typing:

net use /?

at the command line. I believe that once it has been issued the system
will cache the access rights (wrong term... right concept) and allow
access to the machine for subsequent calls. You'll have to try it out
to know for sure but I think this just might do it.

Anyone know of another way to do this that doesn't feel so "wrong?"

Have A Better One!

John M Deal, MCP
Necessity Software
 

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

Back
Top