| Author: Madhavan 21 Jul 2008 | Member Level: Gold | Rating: Points: 6 |
hi Spoorthi,
try this...(Windows Application) 1. Open a new windows app. 2. Go to Project->Add Reference->Select COM tab->Select Microsoft Word 9.0 Object library and click Ok. 3. Use the following code. // This is for Rtf to Txt convertion 4. after the convertion u can read the contents from the txt using filestream.
private Word.ApplicationClass MSdoc; object Unknown = Type.Missing; private void RTF2TXT(object Source, object Target) { //Creating the instance of Word Application if (MSdoc == null) MSdoc = new Word.ApplicationClass();
try { MSdoc.Visible = false; MSdoc.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); MSdoc.Application.Visible = false; MSdoc.WindowState = Word.WdWindowState.wdWindowStateMinimize;
object format = Word.WdSaveFormat.wdFormatText;
MSdoc.ActiveDocument.SaveAs(ref Target, ref format, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown); } catch (Exception e) { MessageBox.Show(e.Message); } finally { if (MSdoc != null) { MSdoc.Documents.Close(ref Unknown, ref Unknown, ref Unknown); //WordDoc.Application.Quit(ref Unknown, ref Unknown, ref Unknown); //MSdoc.Application.Quit(ref Unknown, ref Unknown, ref Unknown); } // for closing the application
} MessageBox.Show("File Converted", "RTF2TXT Convertion");
} private void button1_Click(object sender, EventArgs e) { if (textBox1.Text != "" && textBox2.Text != "") RTF2TXT(textBox1.Text, textBox2.Text); else MessageBox.Show("Enter the File name", "RTF2TXT Convertion"); }
Regards, Madhavan
|