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. Visual Basic
  4. Copy Content from Word Docuemnt to RichBox

Copy Content from Word Docuemnt to RichBox

Scheduled Pinned Locked Moved Visual Basic
2 Posts 2 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.
  • P Offline
    P Offline
    Peace4all
    wrote on last edited by
    #1

    Hi guys I want to copy Content from Word Document (2007 or 2010) . and I am Using File Stream to do this action. here is the Code ===================================================== Dim strPath As String = "C:\Users\Toshiba\Desktop\Test.docx" Dim fStream As New FileStream(strPath.ToString, FileMode.Open, FileAccess.Read) Dim sReader = New StreamReader(fStream) sReader.BaseStream.Seek(0, SeekOrigin.Begin) While sReader.Peek() > 0 RichTextBox1.Text += sReader.ReadLine() End While sReader.Close() ==================================================== I don't no when I copy the Content to RichBox it copy garbage data .. But when i copy from txt file it works fine with out any mistake . But i need to copy from word document (2007 or 2010) because my User request is this . so can any modified my code to copy from word without garbage data .. i try to modify by set this ---------------------------------------- Dim sReader = New StreamReader(fStream, System.Text.Encoding.Unicode) ---------------------------------------- but no change on the result.. so am waiting your replays either by edit the above code or give my easiest way to do this action .. thanks in advance

    W 1 Reply Last reply
    0
    • P Peace4all

      Hi guys I want to copy Content from Word Document (2007 or 2010) . and I am Using File Stream to do this action. here is the Code ===================================================== Dim strPath As String = "C:\Users\Toshiba\Desktop\Test.docx" Dim fStream As New FileStream(strPath.ToString, FileMode.Open, FileAccess.Read) Dim sReader = New StreamReader(fStream) sReader.BaseStream.Seek(0, SeekOrigin.Begin) While sReader.Peek() > 0 RichTextBox1.Text += sReader.ReadLine() End While sReader.Close() ==================================================== I don't no when I copy the Content to RichBox it copy garbage data .. But when i copy from txt file it works fine with out any mistake . But i need to copy from word document (2007 or 2010) because my User request is this . so can any modified my code to copy from word without garbage data .. i try to modify by set this ---------------------------------------- Dim sReader = New StreamReader(fStream, System.Text.Encoding.Unicode) ---------------------------------------- but no change on the result.. so am waiting your replays either by edit the above code or give my easiest way to do this action .. thanks in advance

      W Offline
      W Offline
      Wayne Gaylard
      wrote on last edited by
      #2

      You cannot use a FileStream to read a Word document, as these files are not just text files but compressed xml files. To interact with Word documents, you need to use the Office Interop assemblies. Here[^] is a good place to start {MSDN).

      When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman

      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