关于访问共享文件

yy8866 2006-05-10 01:34:41
请问怎么用C#访问局域网中的一个共享文件夹啊?
此文件夹需要帐号密码,无法登录需要捕获异常。
...全文
199 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
copico 2006-05-11
  • 打赏
  • 举报
回复
先用用户名和密码建立共享连节通道
然后再向读本地文件一样打开共享夹,只是根目录是共享计算机。

WNetconnection
marvelstack 2006-05-11
  • 打赏
  • 举报
回复
下面是sdk中的例子。
先使用Wmi开通连接,再Copy文件
using System;
using System.Management;

// This example demonstrates how to connect to remote machine
// using supplied credentials.
class Sample_ConnectionOptions
{
public static int Main(string[] args) {
ConnectionOptions options = new ConnectionOptions();
options.Username = UserName; //could be in domain\user format
options.Password = SecurelyStoredPassword;
ManagementScope scope = new ManagementScope(
"\\\\servername\\root\\cimv2",
options);
try {
scope.Connect();
ManagementObject disk = new ManagementObject(
scope,
new ManagementPath("Win32_logicaldisk='c:'"),
null);
disk.Get();
}
catch (Exception e) {
Console.WriteLine("Failed to connect: " + e.Message);
}
return 0;
}
}
Knight94 2006-05-10
  • 打赏
  • 举报
回复
进行网络映射,参看
http://blog.csdn.net/knight94/archive/2006/03/21/631309.aspx
http://blog.csdn.net/knight94/archive/2006/03/31/645367.aspx

或者
用Process来发送“net use * \\dell1500-1\C$ password /user:cmic”
yy8866 2006-05-10
  • 打赏
  • 举报
回复
+++++++++++++++++++++++

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧