I have developed an application in c# using visual studio 2015, that copies some files from one directory (source) to another (destination) in general. My problem is that the source path is another computer in a domain. I wish to be able to access the directory and get my files, user the domain, username and password the source computer. I have seen some solution, but I can't get how they access the other computer. I used to get my files by using the Directory. GetDirectories (path), and I'm far too deep using it now and can't change it to smooth as. thanks for helping me with my problem I'm truly blocked for days now.
string[] folder1;
string[] folder2;
folder1 = Directory.GetDirectories(path);
foreach (string fld1 in folder1)
{
folder2 = Directory.GetDirectories(fld);
foreach(string fld2 in folder2)
{
for(int i = 0; i < MyList.Count(); i++)
{
if(fld2.Contains("nok") || fld2.Contains("Nok"))
LNok = Directory.GetFiles(fld2, picList[i]);
else
Lok = Directory.GetFiles(fld2, picList[i]);
}
}
}
Since
System.IO.FileandSystem.IO.Directorymethods don’t support passing credentials, the preferred solution is to impersonate an authorized user account. This requires to import two methods from the advapi32.dll and kernel32.dll using pInvoke:The following code makes use of those methods to create a
WindowsImpersonationContextHere you may find the MSDN documentation of the LogonUser function