Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

I need to upload a .doc file text data to a rich text box . IS it possible ??

I have a code which work fine for .txt files...


VB
If (OpenFileDialog1.ShowDialog = DialogResult.OK) Then

            If System.IO.File.Exists(OpenFileDialog1.FileName) = True Then

                Dim objReader As New System.IO.StreamReader(OpenFileDialog1.FileName.ToString.Trim)

                RichTextBox1.Text = objReader.ReadToEnd

                objReader.Close()

            Else

                MsgBox("File Does Not Exist")

            End If
        End If
Posted
Updated 1-Jul-14 21:01pm
v2

1 solution

 
Share this answer
 
Comments
Sidharth R 2-Jul-14 5:14am    
Thank you...!
i got the answer..

Dim filePath As String = Nothing
Dim file As New OpenFileDialog()
file.Title = "Word File"
file.InitialDirectory = "c:\"
file.RestoreDirectory = True

If file.ShowDialog() = DialogResult.OK Then
filePath = file.FileName.ToString()
End If
Try
' create word application
Dim word As Microsoft.Office.Interop.Word.Application = New Microsoft.Office.Interop.Word.Application()
' create object of missing value
Dim miss As Object = System.Reflection.Missing.Value
' create object of selected file path
Dim path As Object = filePath
' set file path mode
Dim [readOnly] As Object = False
' open document
Dim docs As Microsoft.Office.Interop.Word.Document = word.Documents.Open(path)
docs.ActiveWindow.Selection.WholeStory()
' handover the data to cllipboard
docs.ActiveWindow.Selection.Copy()
' clipboard create reference of idataobject interface which transfer the data
Dim data As IDataObject = Clipboard.GetDataObject()
'set data into richtextbox control in text format
txtdata.Text = data.GetData(DataFormats.Text).ToString()
' read bitmap image from clipboard with help of iddataobject interface
Dim img As Image = DirectCast(data.GetData(DataFormats.Bitmap), Image)
' close the document
docs.Close(miss, miss, miss)

Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900