Copy files over a network share

J

John Varouxis

Hi all,

I want to copy files residing in a network shared folder, but I have to pass
different user credentials than the executing user. How can I accomplish
this. The System.IO.File.Copy overloaded methods don't accept credentials in
any form.

Thanx in advance,
Yannis
 
G

Goran Sliskovic

John Varouxis said:
Hi all,

I want to copy files residing in a network shared folder, but I have to pass
different user credentials than the executing user. How can I accomplish
this. The System.IO.File.Copy overloaded methods don't accept credentials in
any form.

Thanx in advance,
Yannis

Hi,
I think you'll have to use native API to accomplish this. You have to call
LogonUser API and then impersonate. There is a sample in MSDN, check
WindowsIdentity.Impersonate Method in System.Security.Principal namespace.

I have once used WNetUseConnection API to map drive with different
credentials and then access it (as an alternative method).

Regards,
Goran
 
W

Willy Denoyette [MVP]

John Varouxis said:
Hi all,

I want to copy files residing in a network shared folder, but I have to
pass
different user credentials than the executing user. How can I accomplish
this. The System.IO.File.Copy overloaded methods don't accept credentials
in
any form.

Thanx in advance,
Yannis

The simplest is to establish a network session with the share (using net use
....) from your logon session, no special code needed. This works only if
your applications runs in the same logon session of course.

Willy.
 

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