gpt4 book ai didi

c# - 使用用户名和密码连接到网络驱动器

转载 作者:IT王子 更新时间:2023-10-29 04:38:25 24 4
gpt4 key购买 nike

如何提供凭据以便我可以连接到 .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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com