C#访问网络共享文件夹的方法

2020-01-05 09:31:33于丽

测试方法:


public void TestNetWorkConnection() 
  { 
   string localpath = "X:"; 
   //int status = NetworkConnection.Connect(@"//192.168.0.2/test", localpath, @"test", "test"); 
   int status = NetworkConnection.Connect("////192.168.0.2//test", localpath, @"test", "test"); 
   if (status == (int)ERROR_ID.ERROR_SUCCESS) 
   { 
    FileStream fs = new FileStream(localpath + @"//123.txt", FileMode.OpenOrCreate); 
    using (StreamWriter stream = new StreamWriter(fs)) 
    { 
     stream.WriteLine("你好呀,成功了"); 
     stream.Flush(); 
     stream.Close(); 
    } 
    fs.Close(); 
   } 
   else 
   { 
    Console.WriteLine(status); 
   } 
   NetworkConnection.Disconnect(localpath); 
  } 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持ASPKU。


注:相关教程知识阅读请移步到c#教程频道。