比如一個 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.