Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading file contents using C#

Tags:

c#

file

I want to read the contents of following file types using C#:

  1. RTF
  2. PDF
  3. HTML
  4. MS Word

Is there any common API in .Net for reading all file type contents?

like image 550
Steve Chapman Avatar asked Apr 22 '26 16:04

Steve Chapman


2 Answers

There is no built in support for reading most of those file types. HTML is plain text so you can use the System.IO/StreamReader to read it, but you must parse it yourself.

There are third party components which will read these file types, but I am not sure if there is one all encompassing component.

For PDFs, I believe iTextSharp allows you to read.

For RTF/Word, You can use the Primary Interop Assemblies

like image 163
Bob Avatar answered Apr 25 '26 05:04

Bob


I've used Aspose before it's a very powerful product it's reasonably pricey so would only recommend it if your application also needs to create new word/pdf/rtf documents.

I agree with the other comments about just using System.IO for reading HTML files.

like image 30
Nick Josevski Avatar answered Apr 25 '26 06:04

Nick Josevski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!