Articles in this section
Category / Section

How to open and read Word document in C#?

4 mins read

Syncfusion® Essential® DocIO is a .NET Core Word library used to create, read, and edit Word documents programmatically without Microsoft Word or Interop dependencies. Using this library, you can open and read Word document in C#.

Steps to open and read Word document using C#

  1. Create a new C# .NET Core console application project. Create .NET Core console application in Visual Studio in ASP.NET Core Word
  2. Install the Syncfusion.DocIO.Net.Core NuGet package as a reference to your .NET Core applications from NuGet.org. Add DocIO.Net.Core NuGet packages of ASP.NET Core Word
  3. Include the following namespace in the Program.cs file:

C#

using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
  1. Use the following code example to open and read Word document in C#.

C#

//Open the file as a stream.
using (FileStream inputFileStream = new FileStream(Path.GetFullPath(@"../../../Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
    //Load the file stream into a Word document.
    using (WordDocument document = new WordDocument(inputFileStream, FormatType.Automatic))
    {
        //Get the Word document text.
        string text = document.GetText();
        //Display Word document's text content.
        Console.WriteLine(text);
        Console.ReadLine();
    }
}

A complete working sample to open and read Word document in C# can be downloaded from GitHub.

Input Word document as follows.

Reads the template Word document in C# using DocIO

By executing the program, you will get the output document as follows.

Displays the Word document's text content in C# using DocIO

Take a moment to peruse the documentation where you can find basic Word document processing options along with the features like mail mergemerge and split documents, find and replace text in the Word document, protect the Word documents, and most importantly, the PDF and Image conversions with code examples.

Explore more about the rich set of Syncfusion® Word Framework features.

See Also:

Create Word document in Windows Forms

Create Word document in WPF

Create Word document in ASP.NET Core

Create Word document in ASP.NET MVC

Create Word document in Xamarin

Create Word document in Xamarin.Android


Conclusion

I hope you enjoyed learning about how to open and read Word document in C#.

You can refer to our ASP.NET Core DoclO feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our  ASP.NET Core DoclO example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied