How to open and read Word document in C#?
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#
- Create a new C# .NET Core console application project.
- Install the Syncfusion.DocIO.Net.Core NuGet package as a reference to your .NET Core applications from NuGet.org.
- Include the following namespace in the Program.cs file:
C#
using Syncfusion.DocIO; using Syncfusion.DocIO.DLS;
- 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.
By executing the program, you will get the output document as follows.
Take a moment to peruse the documentation where you can find basic Word document processing options along with the features like mail merge, merge 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 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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!