C# 打開網絡文件(UNC)

比如一個   UNC 路徑爲   

  string path = @"\\WUMI_LIU_PC1\Users\1.pdf";

 string[] readText = File.ReadAllLines(path, Encoding.UTF8);  //這樣就可以讀取到  path 路徑下的文件了。

這是在C# 中的使用。

按照這個思路, 在 htm 中 也這麼使用這個路徑。

發現 打不開這個路徑的文件。

 

後來通過調試,發現在C# 中, string path = @"\\WUMI_LIU_PC1\Users\1.pdf";

 其實是 \\\\WUMI_LIU_PC1\\Users\\1.pdf  前面使用四個斜槓的。

 msdn中這麼描述的:

In members that accept a path, the path can refer to a file or just a directory. The specified path can also refer to a relative path or a Universal Naming Convention (UNC) path for a server and share name. For example, all the following are acceptable paths:

  • "c:\\MyDir\\MyFile.txt" in C#, or "c:\MyDir\MyFile.txt" in Visual Basic.

  • "c:\\MyDir" in C#, or "c:\MyDir" in Visual Basic.

  • "MyDir\\MySubdir" in C#, or "MyDir\MySubDir" in Visual Basic.

  • "\\\\MyServer\\MyShare" in C#, or "\\MyServer\MyShare" in Visual Basic.

地址:http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(SYSTEM.IO.FILE);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22);k(DevLang-CSHARP)&rd=true

 

 

 

 

發佈了41 篇原創文章 · 獲贊 20 · 訪問量 16萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章