HI Support,
I would like to know drag and drop to gridivew from attached file of forward outlook email. Now I got error. Can't read file stream. I can read file stream normal attached file (pdf or excel).
Thanks,
Moe
2 Answers, 1 is accepted
Hello, Moe,
If I understand your requirement correctly, you need to drag a file from Outlook and drop it onto RadGridView. Please correct me if I am wrong. This seems to be more like a general programming question and it can be handled by the OLE drag and drop functionality:
However, please have in mind that the email attachment isn't a real file on your hard disk. It contains information about the file name and its contents. It is possible to read this information to save it as a file.
After some research in the appropriate forums I have found the following article which seems to be quite useful on this topic:
https://www.codeproject.com/Articles/28209/Outlook-Drag-and-Drop-in-C
Please give the demonstrated approach a try and see how it works for your custom scenario.
Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
HI Dess,
In attached file is simple of drag and drop from email. Yes, I want to drag outlook email of attached file of email drop into gridview or form . But
I didn't get file stream in yellow highlight part. If outlook email of attached of excel file or pdf file , I can get that file stream. I would like to how to solve and do have in telerik like that method?
I can't attached file. So I will show in below my demo coding.
Private Sub Form1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.Copy
ElseIf e.Data.GetDataPresent("FileGroupDescriptor") Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub Form1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragDrop
Dim fileNames As String() = Nothing
Try
If e.Data.GetDataPresent(DataFormats.FileDrop, False) = True Then
fileNames = CType(e.Data.GetData(DataFormats.FileDrop), String())
For Each fileName As String In fileNames
Next
ElseIf e.Data.GetDataPresent("FileGroupDescriptor") Then
Dim theStream As Stream = CType(e.Data.GetData("FileGroupDescriptor"), Stream)
Dim fileGroupDescriptor As Byte() = New Byte(511) {}
theStream.Read(fileGroupDescriptor, 0, 512)
Dim fileName As StringBuilder = New StringBuilder("")
Dim i As Integer = 76
While fileGroupDescriptor(i) <> 0
fileName.Append(Convert.ToChar(fileGroupDescriptor(i)))
i += 1
End While
theStream.Close()
Dim path1 As String = Path.GetTempPath()
Dim theFile As String = path1 & fileName.ToString()
Dim ms As MemoryStream = CType(e.Data.GetData("FileContents", True), MemoryStream)
Dim fileBytes As Byte() = New Byte(ms.Length - 1) {}
ms.Position = 0
ms.Read(fileBytes, 0, CInt(ms.Length))
Dim fs As FileStream = New FileStream(theFile, FileMode.Create)
fs.Write(fileBytes, 0, CInt(fileBytes.Length))
fs.Close()
Dim tempFile As FileInfo = New FileInfo(theFile)
If tempFile.Exists = True Then
' tempFile.Delete()
Else
Trace.WriteLine("File was not created!")
End If
End If
Catch ex As Exception
Trace.WriteLine("Error in DragDrop function: " & ex.Message)
End Try
End Sub
Hello, Moe,
To be honest, this question is not directly related to RadGridView from the Telerik UI for WinForms suite. It is more like a question regarding the Ole drag and drop and how the attachment is stored in the system.
Following the provided code snippet I have prepared a sample project and tested dragging a pdf/gif/image file from the Outlook mail to the form. It is successfully parsed to a stream. Please refer to the attached gif file. Am I missing something? What is the observed behavior on your end?
Hi Dess,
Like that attachment file is okay. In outlook email attached file of outlook email similar like in my attached photo. I try some of many ways but I still can't fix. Do you have any idea to solve ?
Thanks,
Moe
According to the attached screenshot, it seems that this email contains another email as an attachment (Outlook item). Actually, this is not related to RadGridView or the Telerik UI for WinForms suite. It is a general programming question and that is why I researched in MSDN and StackOverflow how to get the content of this mail. The following thread is quite useful on this topic:
https://social.msdn.microsoft.com/Forums/windows/en-US/98be4a63-455a-4914-bb9e-96b983b2f696/c-drag-drop-get-data-from-outlook-email?forum=winforms
One of the replies refer to the following Code Project: https://www.codeproject.com/Articles/32899/Reading-an-Outlook-MSG-File-in-C
It contains a sample project that allows dragging an Outlook item to the standard MS TreeView and inspecting the message content.
I believe that it would be helpful for your specific scenario.