Copy Content from Word Docuemnt to RichBox
-
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
-
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
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