Validate File Name (Not File Characters)

  • Thread starter Thread starter sheeeng
  • Start date Start date
S

sheeeng

Hello sheeeng,
There is a C++ implementation of it at
http://www.codeproject.com/file/isvalidfilename.asp. But anyone knows
how to implement it in C#?

Not sure I understand your question - translating the C++ code to C# seems
like a logical idea. Otherwise, the rules listed in the article don't look
very difficult to implement, so you might do better just reimplementing
the whole thing following those rules.


Oliver Sturm
 
I don't know how you may retrieve reserved device names, but assuming the
list in the article is complete, simply create a list of all the device
names (for instance a List<string>) and check the filename against this
list

[Pseudocode]
if( ReservedList.Contains( FirstSectionOfFilename( filepath ) ) )
{
// Notify user about invalid filename
}

FirstSectionOfFilename retrieves the first part of the filename ending at
the first dot, using SubString and IndexOf(".")
 
Thanks! I will try implement your Pseudocode now.
I don't know how you may retrieve reserved device names, but assuming the
list in the article is complete, simply create a list of all the device
names (for instance a List<string>) and check the filename against this
list

[Pseudocode]
if( ReservedList.Contains( FirstSectionOfFilename( filepath ) ) )
{
// Notify user about invalid filename
}

FirstSectionOfFilename retrieves the first part of the filename ending at
the first dot, using SubString and IndexOf(".")

Hello sheeeng,


Not sure I understand your question - translating the C++ code to C#
seems like a logical idea. Otherwise, the rules listed in the article
don't look very difficult to implement, so you might do better just
reimplementing the whole thing following those rules.


Oliver Sturm
 
Back
Top