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.