How to Convert Word to TXT with C#/VB.NET

TXT Introduction

TXT is one windows attached text format, which is the most frequently used file format. It is used to the save text information and can be opened with several tools easily, for example, notepad, browser and so on.

Actually, there are a few formats for TXT file, for example, font style, size and color. Therefore, TXT file is suitable for saving plain text. Although TXT file doesn’t have many formats, it is still popular for easily to open and read.

Convert Word to TXT

Sometimes, because users need to have a plain text file for submitting to website, they may convert Word document to TXT.

In this post, I will introduce a method about how to convert Word to TXT by using C#/VB.NET.

Note: Spire.Doc is used in this example. If you want to use the following code, please download and install this component firstly. Then, add its dll file as reference in project.

Detailed Steps Shown as Following:           

I. Load file which I want to convert to TXT by using document.LoadFromFile() method. 

C#

            Document document = new Document();

            document.LoadFromFile(@”E:\work\Documents\Blues Introduction.docx”);

VB.NET

            Dim document As New Document()

            document.LoadFromFile(“E:\work\Documents\Blues Introduction.docx”)

II. Convert Word to TXT by using document.SaveToFile() method. There are two parameters passed to this method, file name format and file format. Extension of file name should be .txt and file format should be .Txt as well.

C#

            document.SaveToFile(“ToText.txt”, FileFormat.Txt);

VB.NET

            document.SaveToFile(“ToText.txt”, FileFormat.Txt)

III. Launch the saved txt file.

C#

            System.Diagnostics.Process.Start(“ToText.txt”);

VB.NET

            System.Diagnostics.Process.Start(“ToText.txt”)

Result Shown as Following:

_____________________________________________________________________________________________

Click Here to LEARN MORE about Spire.Doc

Click Here to DOWNLOAD Spire.Doc

Spire.Office also can be used to realize this function.

Related Posts:

Convert Word to EPub

Convert Word to HTML

Convert Word to XML

Convert Word to Image

Convert Word to PDF

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s