Is there a way to convert a Microsoft text document into a notes file .txt file?

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 optional word formate

I want the plain text format of my Word document to text documnt.

+5
source share
1 answer

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

So, you have RTF that needs to be converted to plain text. Here is an example

The easiest approach is to simply add a link 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);
+2
source

All Articles