首页 > 解决方案 > 使用桌面应用程序 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);
          }
    }

标签: c#windowsnetwork-programmingdesktop-applicationremote-server

解决方案


推荐阅读