Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1978
  • Last Modified:

Illegal characters in path error

Greetings Experts,
I keep getting the "Illegal characters in path" error, and it seems to come from the System.IO.FileInfo constructor, from System.Security.Permissions.FileIOPermission.HasIllegalCharacters(String[] str).

The characters which trigger this error are special french characters like é, è, à, etc... So my question is:
Is there a way to either allow these characters, or remove them from the filename with some kind of parsing method.

I tried making this method:

        Public Shared Function HasIllegalCharacters(ByVal path As String) As Boolean
            Return (path.IndexOfAny(System.IO.Path.InvalidPathChars) >= 0)
        End Function

But the System.IO.Path.InvalidPathChars doesn't contain these special characters. What should I try next?
0
ID3TECH
Asked:
ID3TECH
1 Solution
 
Jens FiedererCommented:
VS2005 considers InvalidPathChars obsolete and prefers the new GetInvalidPathChars method...but there is no guarantee that this is exhaustive ("not guaranteed to contain the complete set of characters that are invalid").

Have you considered doing the opposite?  Just using a set of known LEGAL characters and failing if one of the characters is not in THAT?
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now