c# - 使用桌面应用程序 C# 读取远程文件
问题描述
我正在尝试用 c# 开发一个桌面应用程序,我们可以从中访问和修改远程服务器中的文件。
作为第一阶段,我尝试WNetAddConnection2
连接到远程服务器,但它似乎不起作用显示:
未找到网络路径。
也可以使用从客户端计算机的远程访问来更新文件内容。这是我尝试过的
private void ConnectToShare(string remoteFilePath, string username, string password)
{
NETRESOURCE nr = new NETRESOURCE
{
dwType = RESOURCETYPE_DISK,
lpRemoteName = remoteFilePath
};
int result = WNetUseConnection(IntPtr.Zero, nr, password, username, 0, null, null, null);
if (result != NO_ERROR)
{
throw new Win32Exception(result);
}
}
解决方案
推荐阅读
- sql - Postgres 触发器和函数自动完成表
- python - 如何将用户输入与外部文本文件匹配
- arrays - 使用范围或数组进行的简单操作的不同结果
- antlr4 - 无法在非组合语法中为字符串文字创建隐式标记:
- python - uWSGI ImportError:无法导入名称 Flask
- java - 如何从多个线程更新缓存
- scala - Spark过滤器+地图与flatMap
- jenkins - 从阶段级别更新 Jenkins 管道中的环境全局变量 - 有可能吗?
- javascript - 如何将值打包为带符号的 32 int
- android - 当 onDestroy 在 android 中运行时 MainActivity 泄漏了 ServiceConnection。如何防止这个错误?