To import .Doc file into rich text box in c#
-
hello everybody i m a BS student i have a problem while importing MS Word file(.doc)into a rich text box in C# i have use this caod richTextBox1.Text = File.ReadAllText(fileName,System.Text.ASCIIEncoding.ASCII); can anybody please help me
-
You can't display doc file into rich text box.It supports only rtf files or text files.
Life is a stage and we are all actors!
-
dear sir Hristo Bojilov but how i can open a .doc file in a Windows Form in C# there may be some way ????????
Of course ,you could open any file and read it's data but you still can't display doc into RichTextBox.Ask google and you will find this question many times and it's answer is the same -you can't. [EDIT] doc file is not simple text file and you couldn't view it's contents with Notepad. It's based on binary format specification and RichTextBox doesn't recognize it. You could view or edit doc file with Word or with some third party libraries or with creating your own parser and viewer.
Life is a stage and we are all actors!
modified on Tuesday, September 1, 2009 6:54 AM
-
Of course ,you could open any file and read it's data but you still can't display doc into RichTextBox.Ask google and you will find this question many times and it's answer is the same -you can't. [EDIT] doc file is not simple text file and you couldn't view it's contents with Notepad. It's based on binary format specification and RichTextBox doesn't recognize it. You could view or edit doc file with Word or with some third party libraries or with creating your own parser and viewer.
Life is a stage and we are all actors!
modified on Tuesday, September 1, 2009 6:54 AM
You can import word doc into richtextbox with following: private void PreviewRecord(object sender, EventArgs e) { string str; OpenFileDialog openfiledg = new OpenFileDialog(); openfiledg.Filter = "Word Document (*.doc)|*.doc|All Files (*.*)|*.*"; openfiledg.FilterIndex = 2; openfiledg.RestoreDirectory = true; if ((openfiledg.ShowDialog() == DialogResult.OK && openfiledg.FileName.Length > 0)) { IDataObject Data1; object nullobj, file; Microsoft.Office.Interop.Word.Document wordDoc; Microsoft.Office.Interop.Word.ApplicationClass WordApp = new Microsoft.Office.Interop.Word.ApplicationClass(); nullobj = System.Reflection.Missing.Value; file = openfiledg.FileName; wordDoc = WordApp.Documents.Open(ref file, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj); wordDoc.ActiveWindow.Selection.WholeStory(); wordDoc.ActiveWindow.Selection.Copy(); Data1 = Clipboard.GetDataObject(); str = Data1.GetData(DataFormats.Rtf).ToString(); richTextBox1.Rtf = str; wordDoc.Close(ref nullobj, ref nullobj, ref nullobj); } }