To check if a folderpath contains Invalid characters you can use the following snippet.

Sample C#

public static bool IsValidPathName(string pathName)
{
     return Path.GetInvalidPathChars().All(invalidChar => pathName.Contains(invalidChar) != true);
}

Sample VB.NET

Public Shared Function IsValidPathName(pathName As String) As Boolean
     Return Path.GetInvalidPathChars().All(Function(invalidChar) pathName.Contains(invalidChar) <> True)
End Function

for more informations see the MSDN Path.GetInvalidPathChars Method

One thought on “How to check if a folderpath contains Invalid characters”

Leave a Reply