Validate File Name (Not File Characters)

S

sheeeng

O

Oliver Sturm

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
 
M

Morten Wennevik [C# MVP]

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(".")
 
S

sheeeng

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

myterious folder 4

Top