How to open word file with images and bullets in a rich text box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mayankshri
    New Member
    • Feb 2012
    • 2

    How to open word file with images and bullets in a rich text box

    hi, I am open a word file from open dialog box in rich text box.
    i am using this code it open a word file but shows only text .i want to open file with text,images and bullets.
    Code:
    Microsoft.Office.Interop.Word.ApplicationClass wordObject = new Microsoft.Office.Interop.Word.ApplicationClass();
                    object File = txtfilepath.Text; //this is the path
                    object nullobject = System.Reflection.Missing.Value;
                    Microsoft.Office.Interop.Word.Application wordobject = new Microsoft.Office.Interop.Word.Application();
                    wordobject.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
                    Microsoft.Office.Interop.Word._Document docs = wordObject.Documents.Open(ref File, ref nullobject, ref nullobject, ref nullobject,
                    ref nullobject, ref nullobject, ref nullobject, ref nullobject,
                    ref nullobject, ref nullobject, ref nullobject, ref nullobject,
                    ref nullobject, ref nullobject, ref nullobject, ref nullobject);
                    docs.ActiveWindow.Selection.WholeStory();
                    docs.ActiveWindow.Selection.Copy();
                    IDataObject data = Clipboard.GetDataObject();
                    rtbgermanfile.Text = data.GetData(DataFormats.Text).ToString();
                    string name = rtbgermanfile.Text.Trim();
                    name = String.Join(Environment.NewLine, name.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries));
                    string newtext = name.Replace("\n\n", "\n");
                    string newtext2 = newtext.Replace("\n\n", "\n");
                    rtbgermanfile.Text = newtext2.ToString();
                    txtwriteingerman.Text = rtbgermanfile.Lines[0];
                    docs.Close(ref nullobject, ref nullobject, ref nullobject);
                    wordobject.Quit(ref nullobject, ref nullobject, ref nullobject);
                    //wordobject.Quit(SaveChanges:false, OriginalFormat: false, RouteDocument: false);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(wordobject);
                    txtwriteinenglish.Focus();
    Thanks in Advance.
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    Well since you cannot show an image in a RichTextBox you're going to have to create your own custom user control that inherits from the RichTextBox in order for this to work

    Comment

    Working...