Check if filename is valid (Win32)





-9
Date Submitted Mon. Aug. 28th, 2006 9:43 AM
Revision 1 of 1
Helper axsaxs
Tags CSharp | filename | valid
Comments 2 comments
A function to determine if the input filename is valid on Win32 platforms (that is, it does not include invalid characters, such as :\?...)


using System.Text;
using System.Text.RegularExpressions;

/// <summary>
/// Check if filename is valid on Win32 platforms (does not contain invalid characters)
/// </summary>
/// <param name="inputFileName">Name of the input file.</param>
/// <returns>
///     <c>true</c> if input filename is valid otherwise, <c>false</c>.
/// </returns>
public bool IsFilenameValid(string inputFileName)
{
    Match m = Regex.Match(inputFileName, @"[\\\/\:\*\?\" + Convert.ToChar(34) + @"\<\>\|]");
    return !(m.Success);
}

 

Alessio Saltarin

axsaxs.altervista.org

Comments

Comments use System.IO.Path
Mon. Aug. 28th, 2006 9:51 AM    Helper bobbyrward
  Comments Not InvalidPathChars
Sun. Feb. 18th, 2007 11:23 PM    Newbie dave_capper

Voting