Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to convert Microsoft word document to notepad file .txt formate?

I try this code

string[] ext = att.Name.Split('.');
string file = ext[0].ToString();
object Target = file + ".txt";
object nullobject = System.Reflection.Missing.Value;

Application.Documents.Open(ref FileName, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref value, ref value, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj);
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatUnicodeText;

Application.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);
Application.Visible = false;
Microsoft.Office.Interop.Word.Document oDoc1 = Application.ActiveDocument;
string strNewDocText1 = oDoc1.Content.Text;

But in strNewDocText1 get output including bullets and extra word formate

I want to simple plain-text format of my word document into text documnt.

like image 696
Krunal Mevada Avatar asked Nov 03 '22 21:11

Krunal Mevada


1 Answers

I believe you took this example from here: http://www.codeproject.com/Articles/5273/How-to-convert-DOC-into-other-formats-using-C

So basically you have a RTF, which must be convert to plain text. Here is an example

Simplest approach is just to add reference to System.Windows.Forms.dll.

System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox();

string richText = text// The rich text (with bullets and so on.)
rtBox.Rtf = richText ;
string plainText = rtBox.Text;

System.IO.File.WriteAllText(@"output.txt", plainText);
like image 188
Nas Avatar answered Nov 08 '22 12:11

Nas