<summary>//If Path is UNC (Universal naming convention) path return or return FALSE. Formatter:\\servername\sharename//</summary>//<param name= "path" >path</param> <returns></returns> public static bool Isuncpath (string path) {if (!path. StartsWith (@ "\")) {return false; } var servernamerejectcharacters = @ "' [email protected]#$%^&* () =+_[]{}\|;:. ', <>/?"; var Servernamerejectcharactersarr = Servernamerejectcharacters.tolist (); Servernamerejectcharactersarr.add (' \ '); var foldernamerejectcharacters = @ "/:*? <>|"; var Foldernamerejectcharactersarr = Foldernamerejectcharacters.tolist (); Foldernamerejectcharactersarr.add (' \ '); if (path. Length < 5) {return false; } else { Third ' \ ' index in path var third = path. Remove (0, 2). IndexOf (' \ \ '); var serverName = path. Substring (2, third-1); for (int i = 0, i < servername.length; i++) {for (int j = 0; J < Servernamereject Charactersarr.count; J + +) {if (servername[i] = = Servernamerejectcharactersarr[j]) {return false; }}} var pathes = path. Remove (0, 2 + servername.length); if (pathes. Contains (@ "\")) {return false; } else {for (int i = 0; i < pathes. Length; i++) {for (int j = 0; J < Foldernamerejectcharactersarr.count; J + +) {if (pathes[i] = =Foldernamerejectcharactersarr[j]) {return false; }}}}} return true; }
UNC directory format detection C # code