Access shared network folder using credentials

Rajesh Ambakkat 216 Reputation points
2021-11-03T12:19:42.94+00:00

I am trying to access a network drive from code using credentials. I tried to use the following code, it seems to be not working

        NetworkCredential theNetworkCredential = new NetworkCredential(equipment.User, equipment.Password);
        CredentialCache theNetCache = new CredentialCache();
        theNetCache.Add(new Uri(equipment.SourceFolder), "Basic", theNetworkCredential);

        string[] theFiles = Directory.GetFiles(equipment.SourceFolder);

Is there any way we can access it with other machines account (folder is shared from this machine).

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,078 questions
{count} votes