如何訪問同一區域網路內的其他電腦檔案

來源:互聯網
上載者:User
 如何訪問同一區域網路內的其他電腦檔案

此處為作者寫的一個類: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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.