.NET Word Examples
- Create Word Document
- Perform Mail Merge
- Manage Bookmarks
- Find and Replace Text
- Format Tables
- Split Word Documents
- Merge Multiple Word Documents
- Fill and Manage Form Fields
- Generate and Update Table of Contents
- Compare Word Documents
- Encrypt and Decrypt Documents with Password
- Convert Word Documents to PDF
- Convert Word Documents to Images
- Word-HTML Conversions
- Word-Markdown Conversions
- Word-Text Conversions
Convert Word to Text Using the Syncfusion .NET Word Library
The Syncfusion® .NET Word Library offers convert Word documents to text files and vice versa with a few lines of C# code. Neither Microsoft Word nor interop dependencies are required when using the powerful Syncfusion .NET Word Library.
Watch this video to learn how to convert a Word document to a text file and text to Word document using the Syncfusion .NET Word Library.
Convert Word document to text using C#
Learn how to convert Word documents to text files and text files to Word documents programmatically using C# with the Syncfusion .NET Word Library. This guide demonstrates bidirectional conversion between Word and text formats.
Step 1: Create a new project
Start by creating a new C# Console Application project.
Step 2: Install the NuGet package
Add the Syncfusion.DocIO.Net.Core package to your project from NuGet.org.
Step 3: Add required namespaces to convert Word to text
Add the following namespaces to your Program.cs file.
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using System.IO;Step 4: Open a Word document
Open an existing Word document from a file stream.
FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx);Step 5: Save as text file
Convert and save the Word document as a text file.
//Create file stream
FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.txt"), FileMode.Create, FileAccess.ReadWrite);
//Save the Word document to file stream
document.Save(outputFileStream, FormatType.Txt);
document.Close();
fileStreamPath.Close();
outputFileStream.Close();Step 6: Open the text file
Open an existing text file and load it as a Word document.
//Loads an existing Word document into DocIO instance
FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.txt"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
// Load the document into DocIO
WordDocument document = new WordDocument(fileStreamPath, FormatType.Txt);Step 7: Save the Word document
Convert and save the text content as a Word document.
//Create file stream
FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite);
// Save the new document to the output stream
document.Save(outputFileStream, FormatType.Docx);
//Close the document
document.Close();
fileStreamPath.Close();
outputFileStream.Close();GitHub project
NuGet installation
Get started quickly by downloading the installer and checking license information on the Downloads page.
Table of contents
Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.
Learning
Technical Support
