drag and drop files in richtextbox control with their actual file names

Hi

Can anyone suggest a code to drag and drop any file to richtextbox

Right now if i drop any file like .doc file in richtextbox it shows file like 'work document'
it doesnt say it actual file name and when i am dragging a file and i debug in dragenter event of richtextbox ..it doesnt give me file's name.

so can anybody suggest how to drop a file in richtext box and find file's actual name
and when i click save button i need the files content so that i can save whole richtextbox content with files and texts in it.

Thanks

jyotikasorathiaAsked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
(Interesting...I didn't realize that the VB.Net 2003 RTB doesn't have the DragXXX events)

To get the files name:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        RichTextBox1.AllowDrop = True
    End Sub

    Private Sub RichTextBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragEnter
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            e.Effect = DragDropEffects.All
        End If
    End Sub

    Private Sub RichTextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragDrop
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            Dim files() As String = e.Data.GetData(DataFormats.FileDrop)
            MsgBox(files(0))
        End If
    End Sub
0
 
Bob LearnedCommented:
I am in the process of reinstalling .NET 2003, so I don't have the ability to create code right now.

What format are you using to extract data from the drag/drop object?

Bob
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
0
 
Bob LearnedCommented:
I was wondering if you were using the DataFormats.FileDrop format to get the file name?

Bob
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.