在 C# 中访问 Windows 中受密码保护的网络驱动器?
因此,在 C# 中,我尝试访问网络上的文件,例如“//applications/myapp/test.txt”,如下所示:
const string fileLocation = @"//applications/myapp/test.txt";
using (StreamReader fin = new StreamReader(FileLocation))
{
while(!fin.EndOfStream()){
//Do some cool stuff with file
}
}
但是我收到以下错误:
System.IO.IOException : Logon failure: unknown user name or bad password.
我认为这是因为我需要提供一些网络凭据但我不确定如何让它们在这种情况下工作。
有谁知道访问受密码保护的位置上的这些文件的最佳方法(或任何方法)?
提前致谢!!
So in C# I am trying to access a file on a network, for example at "//applications/myapp/test.txt", as follows:
const string fileLocation = @"//applications/myapp/test.txt";
using (StreamReader fin = new StreamReader(FileLocation))
{
while(!fin.EndOfStream()){
//Do some cool stuff with file
}
}
However I get the following error:
System.IO.IOException : Logon failure: unknown user name or bad password.
I figure its because I need to supply some network credentials but I'm not sure how to get those to work in this situation.
Does anyone know the best way (or any way) to gain access to these files that are on a a password protected location?
Thanks in advance!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题让我在同样的情况下很快就找到了答案。
是我调整代码的方式:
以下
This question got me to where I needed to be pretty quickly in the same case.
Here's how I adapted the code:
followed by