Splits the string on path characters ('/' and '\\') and passes each to SafeFileName(), then reconstructs the string using '\\' and removing any empty segments. If provided null, this function returns null, provided an empty string or just a path seperator '/' it will return String.Empty
Syntax
Visual Basic (Declaration) | |
---|
Public Shared Function SafeFilePath( _
ByVal path As String _
) As String |
Parameters
- path
- The text to parse
Return Value
The text provided as a valid path
Example
Library/Library.Test/TestStringUtils.cs
C# | Copy Code |
---|
Assert.AreEqual(String.Empty, StringUtils.SafeFilePath("\\"));
Assert.AreEqual("----\\--------", StringUtils.SafeFilePath("\b\t\r\n/\\:*?\"'<>|"));
Assert.AreEqual("Greetings this\\is !@#)%~^@+)(",
StringUtils.SafeFilePath("Greetings this/is !@#)%~^@+)("));
Assert.AreEqual("ca761232\\ed42-11ce-bacd\\00aa0057b223",
StringUtils.SafeFilePath("/ca761232/ed42|11ce|bacd\\00aa0057b223\\")); |
VB.NET | Copy Code |
---|
Assert.AreEqual([String].Empty, StringUtils.SafeFilePath("\"))
Assert.AreEqual("----\--------", StringUtils.SafeFilePath(vbBack & vbTab & vbCr & vbLf & "/\:*?""'<>|"))
Assert.AreEqual("Greetings this\is !@#)%~^@+)(", StringUtils.SafeFilePath("Greetings this/is !@#)%~^@+)("))
Assert.AreEqual("ca761232\ed42-11ce-bacd\00aa0057b223", StringUtils.SafeFilePath("/ca761232/ed42|11ce|bacd\00aa0057b223\")) |
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
See Also