[C# Helper]
Index Books FAQ Contact About Rod
[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[Beginning Software Engineering]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: List characters that are invalid in file and path names in C#

[List characters that are invalid in file and path names in C#]

This example uses the following code to display characters that are invalid in file and path names.

private void Form1_Load(object sender, EventArgs e) { string txt = ""; foreach (char ch in Path.GetInvalidFileNameChars()) { if (Char.IsWhiteSpace(ch) || Char.IsControl(ch)) txt += "<" + (int)ch + "> "; else txt += ch + " "; } txtInvalidFileNameChars.Text = txt; txt = ""; foreach (char ch in Path.GetInvalidPathChars()) { if (Char.IsWhiteSpace(ch) || Char.IsControl(ch)) txt += "<" + (int)ch + "> "; else txt += ch + " "; } txtInvalidPathChars.Text = txt; }

The code simply loops through the values returned by Path.GetInvalidFileNameChars and Path.GetInvalidPathChars. It displays the printable characters and shows the numeric values of the whitespace and control characters.

Download the example to experiment with it and to see additional details.

© 2009-2022 Rocky Mountain Computer Consulting, Inc. All rights reserved.