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
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
Post a Comment