Copy files over a network share

  • Thread starter Thread starter John Varouxis
  • Start date Start date
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
 
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
 
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.
 
Back
Top