C# Path GetInvalidPathChars

Description

Path GetInvalidPathChars Gets an array containing the characters that are not allowed in path names.

Syntax

Path.GetInvalidPathChars has the following syntax.


public static char[] GetInvalidPathChars()

Returns

Path.GetInvalidPathChars method returns

Example


using System;/*from   ww  w .  j a va 2  s  .co  m*/
using System.IO;

class GetCharExample
{
    public static void Main()
    {
        char[] invalidPathChars = Path.GetInvalidPathChars();

        foreach (char someChar in invalidPathChars)
        {
            if (Char.IsWhiteSpace(someChar))
            {
                Console.WriteLine(",\t{0:X4}", (int)someChar);
            }
            else
            {
                Console.WriteLine("{0:c},\t{1:X4}", someChar, (int)someChar);
            }
        }

        char[] invalidFileChars = Path.GetInvalidFileNameChars();

        foreach (char someChar in invalidFileChars)
        {
            if (Char.IsWhiteSpace(someChar))
            {
                Console.WriteLine(",\t{0:X4}", (int)someChar);
            }
            else
            {
                Console.WriteLine("{0:c},\t{1:X4}", someChar, (int)someChar);
            }
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter