UNC directory format detection C # code

Source: Internet
Author: User
Tags naming convention

 <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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.