Sign in to follow this  
chrisliando

[.net] How to validate file path and check file type?

Recommended Posts

I use Visual C++ and I want to load a text file to a textBox. How I can check if the file is true text? Not a binary? I have used the openFileDialog filter and it is working without problem. But I also must handle the user input filename via the textBox. 1. I must validate the user file name input. I think, users are get usual with mistakes. So let say, they input wrong path like this: C::\\\...... It is truly not valid file path.. Does the File class has a method to validate the user input? If not, how can I validate it? 2. I must ensure that user input file is a text file, not binary or other type..How to know if it is a text file / non-text file? Thank you very much.

Share this post


Link to post
Share on other sites
System.IO.File.Exists(path) will work for the first one. You can also use methods in System.IO.Path like System.IO.Path.GetDirectory(). You can also get the extension that way.

To find out if the file is a plain text file, you would probably have to look at the header or something. Look more into the System.IO.File type, it may have what you need.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this