Re: Validating file names

From: Jay B. Harlow [MVP - Outlook] (Jay_Harlow_MVP_at_msn.com)
Date: 02/29/04


Date: Sun, 29 Feb 2004 10:49:14 -0600

Lance,
Short of actually trying to create or open the file, I do not know of any
function to validate a file name.

A quick search of MSDN did not offer any real help either.

Part of the problem you are going to have with said function: is that your
A: running FAT16 may (will) have different rules, then your C: running
FAT32, from your D: running CDFS, from your E: running NTFS, from your F:
running Novel, from your G: running Linux file system, from your H: running
IFS, from your.... (I'm sure there are more types of file systems
supported!)

Also remember a number of functions accept a UNC path, a URI path, or even a
URL path to "open" the file.

NOTE: I am not saying one does not exist! I am saying that I do not know of
one. I am also saying if you create one, remember that different files
systems (readily available as network drives) have different rules for file
names.

I would consider using a System.Test.RegularExpressions.RegEx to create a
pattern that would match most "commonly used" file names and limit names to
that subset. However more then likely I would simply attempt to create/open
file file and handle any exceptions that were thrown.

Hope this helps
Jay

"Lance" <zippy@hotmail.com> wrote in message
news:A8EB7DC5-6EB6-4EDF-B115-AF2A336131AB@microsoft.com...
> Are there any methods that indicate whether a string can be used as a full
path for a file? For example, what I'm looking for is a method that would
test for things like correct file name format, invalid characters, total
number of characters (to make sure the path is not too long), existing local
drive letters, etc. Note that the file does not have to exist. Even a
method that only tests some of these items would be useful. The best
solution that I can come up with is to attempt to create a FileInfo in a
Try-Catch-End Try statement. If an exception is thrown then the specified
path is invalid. Of course this isn't very good because it requires an
exception to be thrown (nor does it test everything that I would like to
test).
>
> Thanks for any help.
> Lance



Relevant Pages

  • Re: Installing and running on another machine
    ... > when it starts saying that it has thrown an exception. ... > DLL that I wrote with it and the DLL registers properly and has the ... Post the complete exception text. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Using an ActiveX ocx control on a Webform
    ... > download the ActiveX I can Automate the ActiveX object through the ... > Exception of type InvalidActiveXStateException was thrown. ... > tried using the item in the design mode of a regular .NET Windows ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Spidering home page - and nothing else
    ... Note that I am not saying to host your site on your computer ... a file system, and not a webserver. ... Then you either use a webserver, or have to use weird paths and refer to ... http://example.com/index.html the browser will fetch (again AFAIK, ...
    (alt.internet.search-engines)
  • Re: Exception-Objekt freigeben
    ... When an exception is thrown, the exception object that is thrown is destroyed ... we have added the AcquireExceptionObject and ReleaseExceptionObject functions. ... then the thrown object is not destroyed by the RTL, but assumed to be in control ...
    (de.comp.lang.delphi.misc)
  • Re: how to change method return type from void to boolean
    ... Will the method return in case of exception thrown ... final OperationListener operationListener) { ... However my problem is that I need to determine what was wrong and show it to the user (in gui layer). ...
    (comp.lang.java.programmer)