• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 607
  • Last Modified:

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.
0
darbid73
Asked:
darbid73
  • 6
  • 4
2 Solutions
 
CodeCruiserCommented:
Two possibilities, keep a list of file extensions that you can deal with or try to read the file as text and if not successful then raise an error. What sort of program is it?
0
 
darbid73Author Commented:
I will be writing it in VB.net for Windows 7 boxes.

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.
0
 
CodeCruiserCommented:
By program type, I meant functionality wise.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
darbid73Author Commented:
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.
0
 
CodeCruiserCommented:
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.
0
 
darbid73Author Commented:
I am unable to test right now but looking at the msdn reference stuff there is no specific exception for that.

This thread here looks like an answer. what do you think.
0
 
CodeCruiserCommented:
Give the stackoverflow thread a try.
0
 
darbid73Author Commented:
by the way thanks CodeCruiser for picking up yet another one of my questions.
0
 
darbid73Author Commented:
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.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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