如何訪問同一區域網路內的其他電腦檔案
此處為作者寫的一個類: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; }在頁面中引用如下:usingSystem.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