Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. To import .Doc file into rich text box in c#

To import .Doc file into rich text box in c#

Scheduled Pinned Locked Moved C#
helpcsharp
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tanweer
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • T tanweer

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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!

      T 1 Reply Last reply
      0
      • L Lost User

        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!

        T Offline
        T Offline
        tanweer
        wrote on last edited by
        #3

        dear sir Hristo Bojilov but how i can open a .doc file in a Windows Form in C# there may be some way ????????

        L 1 Reply Last reply
        0
        • T tanweer

          dear sir Hristo Bojilov but how i can open a .doc file in a Windows Form in C# there may be some way ????????

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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

          S 1 Reply Last reply
          0
          • L Lost User

            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

            S Offline
            S Offline
            smshepard
            wrote on last edited by
            #5

            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); } }

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups