Get a list of invalid file characters in CSharp

Description

The following code shows how to get a list of invalid file characters.

Example


  /*ww w.jav a 2  s .c  o  m*/
  
  
     

using System;
using System.IO;

class GetCharExample
{
    public static void Main()
    {

        char[] invalidFileChars = Path.GetInvalidFileNameChars();

        Console.WriteLine("The following characters are invalid in a filename:");
        ShowChars(invalidFileChars);
    }

    public static void ShowChars(char[] charArray)
    {
        foreach (char someChar in charArray)
        {
            Console.WriteLine("{0:c},\t{1:X4}", someChar, (int)someChar);
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    IO »




File Attribute
File Security
Directory Attribute
Directory Recursive
Binary File
Text Field
Buffered IO
Create Copy Delete Move
CSV
Drive
File System Watcher
Isolated Storage
MemoryStream
Serialize
Zip