Gets an array containing the characters that are not allowed in path names.
Namespace:
System.IO
Assembly:
mscorlib (in mscorlib.dll)
'Usage
Dim returnValue As Char()
returnValue = Path.GetInvalidPathChars()
'Declaration
Public Shared Function GetInvalidPathChars As Char()
Return Value
Type:
array<System..::.Char>[]()[]An array containing the characters that are not allowed in path names.
The array returned from this method is not guaranteed to contain the complete set of characters that are invalid in file and directory names. The full set of invalid characters can vary by file system. For example, on Windows-based desktop platforms, invalid path characters might include ASCII/Unicode characters 1 through 31, as well as quote ("), less than (<), greater than (>), pipe (|), backspace (\b), null (\0) and tab (\t).
The following code example demonstrates the GetInvalidFileNameChars method and the GetInvalidPathChars method to validate a path.
Imports System
Imports System.IO
Module PathExample
Sub Main()
' Get a list of invalid path characters.
Dim invalidPathChars As Char() = Path.GetInvalidPathChars()
Console.WriteLine("The following characters are invalid ina path:")
' Display each invalid character to the console.
Dim invalidPChar As Char
For Each invalidPChar In invalidPathChars
Console.WriteLine(invalidPChar)
Next invalidPChar
' Get a list of invalid file characters.
Dim invalidFileChars As Char() = Path.GetInvalidFileNameChars()
Console.WriteLine("The following characters are invalid ina path:")
' Display each invalid character to the console.
Dim invalidFChar As Char
For Each invalidFChar In invalidFileChars
Console.WriteLine(invalidFChar)
Next invalidFChar
Console.ReadLine()
End Sub
End Module
' Note that while this code attempts to display a list of all invalid
' characters in paths and filenames, not all of the characters are
' within the displayable set of characters. Because the list of invalid
' characters can vary, based on the system, output for this code can vary.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0
.NET Compact Framework
Supported in: 3.5, 2.0
XNA Framework
Supported in: 3.0, 2.0, 1.0
Reference