Click here to Skip to main content
11,412,400 members (65,715 online)
Click here to Skip to main content

How to convert DOC into other formats using C#

, 22 Oct 2003
Rate this:
Please Sign up or sign in to vote.
This article explains how to convert DOC into other formats using C#.


This article will only show you how to use the COM object library in C#, so you can easily convert a DOC file into different formats that are supported by Microsoft Word. This could be accomplished by using the Microsoft Word 10.0 Object library. You can add this library by using the menu bar of .NET IDE, that is ProjectAdd Reference…- COM, here you can add the reference to the Microsoft Word 10.0 Object library for your code & it is necessary for the conversion. By adding this library as a reference in your project, you can now use the Word namespace which will allow you to do all the stuff. So it is necessary to add this reference into your project.

Conversion code

The following code shows how to convert DOC to RTF. You can convert to any format which is supported by MS Word by only changing the type of Target file.

using System; 

namespace DocConvert 

      class DoctoRtf 
            static void Main() 

                //Creating the instance of Word Application
                Word.Application newApp = new Word.Application(); 

                // specifying the Source & Target file names
                object Source="c:\\abc\\Source.doc";
                object Target="c:\\abc\\Target.rtf";

                // Use for the parameter whose type are not known or  
                // say Missing
                object Unknown =Type.Missing;

                // Source document open here
                // Additional Parameters are not known so that are  
                // set as a missing type
                newApp.Documents.Open(ref Source,ref Unknown, 
                     ref Unknown,ref Unknown,ref Unknown, 
                     ref Unknown,ref Unknown,ref Unknown, 
                     ref Unknown,ref Unknown,ref Unknown, 
                     ref Unknown,ref Unknown,ref Unknown,ref Unknown);

        // Specifying the format in which you want the output file 
                object format = Word.WdSaveFormat.wdFormatRTF;

        //Changing the format of the document
                newApp.ActiveDocument.SaveAs(ref Target,ref format, 
                        ref Unknown,ref Unknown,ref Unknown, 
                        ref Unknown,ref Unknown,ref Unknown, 
                        ref Unknown,ref Unknown,ref Unknown, 
                        ref Unknown,ref Unknown,ref Unknown, 
                        ref Unknown,ref Unknown);                    

                // for closing the application
                newApp.Quit(ref Unknown,ref Unknown,ref Unknown);


What the code does

If you want to convert the particular file, then you have to first open that file. You can do this by using the Documents class in the Word namespace & then call the Open method which has a number of parameters, out of which source filename is important. Others you can say as missing. Then use the ActiveDocument’s SaveAs to save the file in a target format and lastly close all the documents by using Quit.


Make sure that you include the reference to Microsoft Word 10.0 object library in your code; otherwise the compiler will flag error for the Word namespace.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Prashant Agrawal
India India
No Biography provided

Comments and Discussions

QuestionConvert Word Doc to PDF using Microsoft.Interop takes long time to conver large size files(ex 30MB) Pinmemberbhushanjat24-Apr-15 4:27 
Questioncant save as PDF format Pinmemberhugojim30-Apr-13 14:42 
QuestionRegarding the conversion of .docx to HTML PinmemberLucky Ahuja30-Oct-12 21:10 
Questionhow to convert c++ file into c# Pinmember123435jitu16-Jun-12 7:07 
Questioncode in c# to convert word into .pdf format By Gurpreet Singh [modified] PinmemberGurpreet_Singh_003627-Sep-11 0:36 
GeneralVery helpfull PinmemberLokanta_brahmachari1-Mar-11 6:00 
GeneralMy vote of 1 Pinmemberwaqassarwar4210-Nov-10 20:01 
GeneralMy vote of 1 Pinmemberrajesh11423-Nov-10 5:37 
GeneralFileInfo class object PinmemberDevaang1111-Aug-09 19:40 
GeneralRe: FileInfo class object PinmemberMichael Heydeck6-Jan-10 5:39 
GeneralThanks Pinmember786hhhhhh20-Oct-08 21:01 
Generala reference to Microsoft Word 10.0 reference library could not be added. Converting the type library to .net assembly failed Pinmemberpw_asksam13-Sep-08 16:31 
Generalcant save as PDF format PinmemberMember 386191529-Aug-08 1:08 
Questionhow to delete "\r" ??` Pinmemberlaukaqc5-Jun-08 18:14 
i import a word file and then make it a csv file.

However, there are many "\r", "\r\r" something like that within the word file so when i convert the file to csv, there are many new lines.

Can you guys suggest me how to delete the "\r" by writing a function?
AnswerRe: how to delete "\r" ??` PinmemberCainKellye12-Jan-09 7:51 
GeneralConvert Word To PDF Pinmemberryanjoseph19-May-08 16:03 
GeneralRe: Convert Word To PDF Pinmembereg_Anubhava5-Oct-09 20:25 
Generalask !! HELP PinsussTukangNanya10-Dec-07 0:30 
GeneralNot able to convert into PDF PinmemberUjjwalk25-Nov-07 2:50 
Generalconvert a particular page of doc file into PDF PinmemberAbhinav Shrimali31-Oct-07 4:41 
Questionis it possible to use MS word 9.0 object library? PinmemberRenukapadhamanaban11-Oct-07 17:10 
GeneralCan't we converted the file without actually opening word. PinmemberZeeshan Reyaz4-Jun-07 4:24 
GeneralRe: Can't we converted the file without actually opening word. PinmemberMember 408137523-Mar-08 4:19 
Questionhow to convert a doc file into bmp file?????????? Pinmemberjaneeta28-Mar-07 22:44 
Questionhow to convert a doc file into bmp file?????????? Pinmemberjaneeta28-Mar-07 22:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150414.5 | Last Updated 23 Oct 2003
Article Copyright 2003 by Prashant Agrawal
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid