private static bool IsLocalPath(string p)
{
return new Uri(p).IsFile;
}
...or, if you want to include support for certain invalid URIs...
private static bool IsLocalPath(string p)
{
if (p.StartsWith("http:"))
{
return false;
}
return new Uri(p).IsFile;
}
Example Usage
static void Main(string[] args)
{
CheckIfIsLocalPath("C:\foo.txt");
CheckIfIsLocalPath("C:");
CheckIfIsLocalPath("http://www.txt.com");
}
private static void CheckIfIsLocalPath(string p)
{
var result = IsLocalPath(p); ;
Console.WriteLine("{0} {1} {2}", result, p, new Uri(p).AbsolutePath);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…