abhi
abhi

Reputation: 23

Reading a Non txt file in C#

I am trying to read the contents of a *.jsp file and need to retrieve a specific string.

I tried many file handling methods in C# but it seems all work only with txt files. Is it possible to use the same methods for a file with a different extension?

Upvotes: 0

Views: 1827

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500615

The normal IO classes in .NET don't depend on the file extension. You should be able to use:

string jsp = File.ReadAllText("page.jsp");

... assuming the JSP is encoded in UTF-8. You should find out the encoding of the file and load it using that encoding. I wouldn't be surprised if that turned out to be the problem you were having, although you haven't specified anything.

Upvotes: 3

Related Questions