Gets whether the specified path is a valid absolute file path. - CSharp System.IO

CSharp examples for System.IO:File Path

Description

Gets whether the specified path is a valid absolute file path.

Demo Code


using System.Threading;
using System.Text.RegularExpressions;
using System.Text;
using System.Security.Cryptography;
using System.Net;
using System.Linq;
using System.Globalization;
using System.Collections.Generic;
using System;//from   ww w  .j a  v  a2 s . c  om

public class Main{
        /// <summary>
        /// Gets whether the specified path is a valid absolute file path.
        /// </summary>
        /// <param name="path">Any path. OK if null or empty.</param>
        static public bool IsValidPath(string path)
        {
            Regex r = new Regex(@"^(([a-zA-Z]\:)|(\\))(\\{1}|((\\{1})[^\\]([^/:*?<>""|]*))+)$");
            return r.IsMatch(path);
        }
}

Related Tutorials