Illegal characters in path error

Posted on 2006-05-09
Last Modified: 2008-01-09
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?
Question by:ID3TECH
    1 Comment
    LVL 23

    Accepted Solution

    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?

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now