darbid73
asked on
How to check if can / read as many text type files as possible.
Users can point any type of file at my code and I need to know if I can read the text from it.
I can deal with Office files and PDF by looking at the file extension.
But what about the rest.
What I am hoping is that I can somehow test it against streamreader or another .NET object and see if I can read the file or not.
I can deal with Office files and PDF by looking at the file extension.
But what about the rest.
What I am hoping is that I can somehow test it against streamreader or another .NET object and see if I can read the file or not.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
By program type, I meant functionality wise.
ASKER
The program is going to upload the file to a database. Before it is uploaded certain properties of the file need to be added. if I can read the text of the file I can fill out many of the properties for the user.
With streamreader, you would not be able to distinguish between file types. Try using the IO.File.ReadAllText and see if it raises an error for binary files.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Give the stackoverflow thread a try.
ASKER
by the way thanks CodeCruiser for picking up yet another one of my questions.
ASKER
When asking this question I did not realise how much of a question it is. The question is not easy to answer and you will find many discussions on this.
CodeCruisers answer whilst simplistic is essentially the answer. I have marked one of my comments as answer as well as you can see the thread from stackoverflow which basically has a discussion on this topic.
CodeCruisers answer whilst simplistic is essentially the answer. I have marked one of my comments as answer as well as you can see the thread from stackoverflow which basically has a discussion on this topic.
ASKER
Ok the list was what I was thinking, but how do I do that. I would need the program that generates that type of document.
One thing I am not sure about with the streamReader object is that if I point it at a Word doc I get something back, but of course it cannot be read. So how do I differentiate.