How to load MS Word Document files into a Richtextbox.

1. Start by saving the MS Word document as a richtext file.
2. Add the code below to a button.
 3. Add a richtextbox to your project.
You are good to go.

 Private Sub btnBrowseRTF_Click(sender As Object, e As EventArgs) Handles btnBrowseRTF.Click

Dim saveDirectory As String = Application.StartupPath & "\ProcessedRTFS" Using openFileDialog1 As OpenFileDialog = New OpenFileDialog()
 openFileDialog1.Filter = "Richtext Files (*.rtf ) |*.rtf|All Files(*.*) |*.*"
      If openFileDialog1.ShowDialog() = DialogResult.OK Then
          If Not Directory.Exists(saveDirectory) Then
 Directory.CreateDirectory(saveDirectory)

End If

 Dim fileName As String = Path.GetFileName(openFileDialog1.FileName)
 Dim fileSavePath As String = Path.Combine(saveDirectory, fileName) File.Copy(openFileDialog1.FileName, fileSavePath, True)
 'txtImgName.Text = fileName
 txtPathRTF.Text = fileSavePath
 End If
 End Using

 RichTextBox1.LoadFile(txtPathRTF.Text, RichTextBoxStreamType.RichText)

 End Sub

Comments

Popular posts from this blog

CREATING CRYSTAL REPORTS VB.NET 2012 STEP BY STEP - PART 2

How to paste image into picturebox from clipboard with VB.Net

KENYA'S NEW CURRENCY