如何访问同一局域网内的其他电脑文件

 如何访问同一局域网内的其他电脑文件
此处为作者写的一个类:
using System.Collections.Specialized;
/// <summary>
/// get hbldocument folder, intranet
/// </summary>
/// 2006-11-08 Jason
/// <param name="remoteHost"> computer ip or name </param>
/// <param name="userName"> user name </param>
/// <param name="passWord"> password </param>
/// <returns> true:success; </returns>
public bool ConnectNet(string remoteHost, string userName, string passWord)
         {
                   bool Flag = true;
                   Process myproc = new Process();
                   try
                   {
                            myproc.StartInfo.FileName = "cmd.exe";
                            myproc.StartInfo.UseShellExecute = false;
                            myproc.StartInfo.RedirectStandardInput = true;
                            myproc.StartInfo.RedirectStandardOutput = true;
                            myproc.StartInfo.RedirectStandardError = true;
                            myproc.StartInfo.CreateNoWindow = false;
                            myproc.Start();
                            string dosLine = @"net use " + remoteHost + " " + passWord + " " + " /user:" + userName + ">NUL";
                                     myproc.StandardInput.WriteLine(dosLine);
                                     myproc.StandardInput.WriteLine("exit");
                                     while (myproc.HasExited == false)
                                     {
                                               myproc.WaitForExit(1000);
                                     }
                                     string errormsg = myproc.StandardError.ReadToEnd();
                                     if (errormsg != "")
                                     {
                                               Flag = false;
                                     }
                                     myproc.StandardError.Close();
                            }
                            catch (Exception ex)
                            {
                                     Flag = false;
                                     string errmsg = ex.Message;
                            }
                            finally
                            {
                                     try
                                     {
                                               myproc.Close();
                                              myproc.Dispose();
                                     }
                                     catch(Exception ex)
                                     {
                                               Flag = false;
                                               string errmsg = ex.Message;
                                     }
                            }
                            return Flag;
                   }
在页面中引用如下:
using System.IO;
using System.Collections.Specialized;
if (!this.ConnectNet(folder_path,ls_usrid,ls_pswd))
{
DirectoryInfo di = new DirectoryInfo(folder_path);
FileInfo[] fi = di.GetFiles();
NameValueCollection files = new NameValueCollection();
for (int i = 0; i < fi.Length; i++)
{
          File.Copy(folder_path + "//" + fi[i].Name, Server.MapPath("..") + "//" + fi[i].Name, true);
}
}

 Trakback:http://blog.csdn.net/FollowIT/archive/2006/11/09/1375494.aspx

参考:

http://blog.csdn.net/knight94/archive/2006/03/21/631309.aspx

http://blog.csdn.net/knight94/archive/2006/03/31/645367.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值