C# Path GetInvalidFileNameChars

Description

Path GetInvalidFileNameChars Gets an array containing the characters that are not allowed in file names.

Syntax

Path.GetInvalidFileNameChars has the following syntax.


public static char[] GetInvalidFileNameChars()

Returns

Path.GetInvalidFileNameChars method returns

Example

The following code example demonstrates the GetInvalidFileNameChars method and the GetInvalidPathChars method to retrieve invalid characters.


/*from w  w w  .j av a 2  s. co  m*/
using System;
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