CSharpTest.Net
MakeValidFileName(String) Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Utils Namespace > FileUtils Class > MakeValidFileName Method : MakeValidFileName(String) Method

filename

Glossary Item Box

Creates a valid filename by removing all invalid characters.

Syntax

Visual Basic (Declaration) 
Public Overloads Shared Function MakeValidFileName( _
   ByVal filename As String _
) As String
C# 
public static string MakeValidFileName( 
   string filename
)

Parameters

filename

Example

Library/Library.Test/TestFileUtils.cs

C#Copy Code
Assert.AreEqual("a...", FileUtils.MakeValidFileName("a..."));
Assert.AreEqual("a. . .", FileUtils.MakeValidFileName("a. . . "));
Assert.AreEqual("leading whitespace is bad", FileUtils.MakeValidFileName(" leading whitespace is bad"));
Assert.AreEqual("trailing whitespace is bad", FileUtils.MakeValidFileName("trailing whitespace is bad\t"));
Assert.AreEqual("a_a.txt", FileUtils.MakeValidFileName("a/a.txt", "_"));
Assert.AreEqual("a_a.txt", FileUtils.MakeValidFileName("a|a.txt", "_"));
Assert.AreEqual("a_a._txt", FileUtils.MakeValidFileName("a<|/\\*?>a.*txt", "_"));

Assert.AreEqual(".a", FileUtils.MakeValidFileName(".a"));
Assert.AreEqual(". -", FileUtils.MakeValidFileName(". -"));
Assert.AreEqual("..a", FileUtils.MakeValidFileName("..a"));
Assert.AreEqual("a..", FileUtils.MakeValidFileName("a.."));
Assert.AreEqual("No extension is fine", FileUtils.MakeValidFileName("No extension is fine"));
Assert.AreEqual(". a leading dot is ok", FileUtils.MakeValidFileName(". a leading dot is ok"));
Assert.AreEqual("really really long file extension is actually ok.", FileUtils.MakeValidFileName("really really long file extension is actually ok."));
VB.NETCopy Code
Assert.AreEqual("a...", FileUtils.MakeValidFileName("a..."))
Assert.AreEqual("a. . .", FileUtils.MakeValidFileName("a. . . "))
Assert.AreEqual("leading whitespace is bad", FileUtils.MakeValidFileName(" leading whitespace is bad"))
Assert.AreEqual("trailing whitespace is bad", FileUtils.MakeValidFileName("trailing whitespace is bad" & vbTab))
Assert.AreEqual("a_a.txt", FileUtils.MakeValidFileName("a/a.txt", "_"))
Assert.AreEqual("a_a.txt", FileUtils.MakeValidFileName("a|a.txt", "_"))
Assert.AreEqual("a_a._txt", FileUtils.MakeValidFileName("a<|/\*?>a.*txt", "_"))

Assert.AreEqual(".a", FileUtils.MakeValidFileName(".a"))
Assert.AreEqual(". -", FileUtils.MakeValidFileName(". -"))
Assert.AreEqual("..a", FileUtils.MakeValidFileName("..a"))
Assert.AreEqual("a..", FileUtils.MakeValidFileName("a.."))
Assert.AreEqual("No extension is fine", FileUtils.MakeValidFileName("No extension is fine"))
Assert.AreEqual(". a leading dot is ok", FileUtils.MakeValidFileName(". a leading dot is ok"))
Assert.AreEqual("really really long file extension is actually ok.", FileUtils.MakeValidFileName("really really long file extension is actually ok."))

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys