如何提供凭据以便我可以连接到 .NET 中的网络驱动器?
我正在尝试从网络驱动器检索文件,需要提供用户凭据才能访问该驱动器。
最佳答案
非常优雅的解决方案,灵感来自 this one .这个仅使用 .Net 库,不需要使用任何命令行或 Win32 API。
现成引用代码:
NetworkCredential theNetworkCredential = new NetworkCredential(@"domain\username", "password");
CredentialCache theNetCache = new CredentialCache();
theNetCache.Add(new Uri(@"\\computer"), "Basic", theNetworkCredential);
string[] theFolders = Directory.GetDirectories(@"\\computer\share");
关于c# - 使用用户名和密码连接到网络驱动器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3700871/