D
dgk
I can't find anything in the framework that will tell me whether a
filename is valid. I suppose that I can just try to open it and trap
an error but that seems wasteful. I dug around and found this code:
Public Function IsValidName(ByVal name As String) As Boolean
Dim i As Integer
For i = 0 To name.Length - 1
Dim ch As Char = name.Chars(i)
Dim uc As Globalization.UnicodeCategory =
[Char].GetUnicodeCategory(ch)
Select Case uc
Case Globalization.UnicodeCategory.UppercaseLetter,
Globalization.UnicodeCategory.LowercaseLetter,
Globalization.UnicodeCategory.TitlecaseLetter,
Globalization.UnicodeCategory.DecimalDigitNumber
Case Else
Return False
End Select
Next i
Return True
End Function
but this one failed on a name with a space in it, and that is valid.
Any suggestions?
filename is valid. I suppose that I can just try to open it and trap
an error but that seems wasteful. I dug around and found this code:
Public Function IsValidName(ByVal name As String) As Boolean
Dim i As Integer
For i = 0 To name.Length - 1
Dim ch As Char = name.Chars(i)
Dim uc As Globalization.UnicodeCategory =
[Char].GetUnicodeCategory(ch)
Select Case uc
Case Globalization.UnicodeCategory.UppercaseLetter,
Globalization.UnicodeCategory.LowercaseLetter,
Globalization.UnicodeCategory.TitlecaseLetter,
Globalization.UnicodeCategory.DecimalDigitNumber
Case Else
Return False
End Select
Next i
Return True
End Function
but this one failed on a name with a space in it, and that is valid.
Any suggestions?