I was able to implement the drag and drop from Windows Explorer using the RadDragAndDropManager with native mode, which works well.
However, is it possible to drag and drop an attachment from Outlook to RadGridView? How?
Thanks,
Chris
13 Answers, 1 is accepted
Unfortunately this is a limitation of the RadDragAndDropManager.
You can use the DragDropManager. To achieve the desired behavior you can get the Data in the Drop event, and extract the necessary information from the DataObject.
Let me know if you need any further help with this.
Nik
the Telerik team
Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.
Thanks for the reply.
Do you have a sample code or project on how to do it?
Thanks,
Chris
You can use the DragDroppayloadManager class to see what are the available formats in the CurrentPayload, and extract them later on. Here is a simple example.
private
void
OnDrop(
object
sender, Telerik.Windows.DragDrop.DragEventArgs e)
{
if
(DragDropPayloadManager.GetFormats(e.Data).Contains(
"FileContents"
))
{
try
{
var stream = DragDropPayloadManager.GetDataFromObject(e.Data,
"FileContents"
);
}
catch
{
}
}
}
Hope this helps! All the best,
Nik
the Telerik team
Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.
I am using the DragDropManager and when I add the code below to my project, the line
var stream = DragDropPayloadManager.GetDataFromObject(e.Data,
"FileContents"
);
in the OnDrop callback throws an exception every time. Here is what I get. Do you know what could be causing this?
Thanks, Valerie
System.Runtime.InteropServices.COMException was caught
Message=Invalid lindex (Exception from HRESULT: 0x80040068 (DV_E_LINDEX))
Source=System
ErrorCode=-2147221400
StackTrace:
at System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC& format, STGMEDIUM& medium)
at System.Windows.DataObject.OleConverter.GetDataInner(FORMATETC& formatetc, STGMEDIUM& medium)
at System.Windows.DataObject.OleConverter.GetDataFromOleIStream(String format, DVASPECT aspect, Int32 index)
at System.Windows.DataObject.OleConverter.GetDataFromBoundOleDataObject(String format, DVASPECT aspect, Int32 index)
at System.Windows.DataObject.OleConverter.GetData(String format, Boolean autoConvert, DVASPECT aspect, Int32 index)
at System.Windows.DataObject.OleConverter.GetData(String format, Boolean autoConvert)
at System.Windows.DataObject.GetData(String format, Boolean autoConvert)
at System.Windows.DataObject.GetData(String format)
at Telerik.Windows.DragDrop.DragDropPayloadManager.GetDataFromObject(Object draggedObject, String format) in c:\TB\221\WPF_Scrum\Release_WPF\Sources\Development\Core\Controls\DragDropManager\DragDropPayloadManager.cs:line 52
at Desktop.Infrastructure.RadTreeViewDragDropBehavior.OnDrop(Object sender, DragEventArgs e) in C:\WCLX\Code Review Workspace\Desktop\Desktop\Infrastructure\RadTreeViewDragDropBehavior.cs:line 264
InnerException:
Unfortunately I cannot say anything with certainty about this. What is your scenario? Is your application running in elevated trust? Do you modify the DataObject in any way prior to extracting the data from it?
Nik
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
Thanks, Valerie
I have already answered to your support ticket. In order to make our communication consistent, it would be better to follow a single thread on the topic.
Yoan
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
Thanks,
-Sashi
Basically the only thing special about the case is that you have to look for specific data format in the comming DataObject(args.Data). Everything else behaves in the same way as a default DragDrop scenario, the only thing special is to extract the data form the DataObject, which can be done by using the DragDropPayloadManager class with the GetDataFromObject method.
Let me know if I can help you further with this.
Regards,
Nik
Telerik
var data = e.Data as DataObject;
if (data != null && data.ContainsFileDropList())
{
var files = data.GetFileDropList();
foreach (var file in files)
{
Do FileInfo, get information about the file and Get the bytes...
}
}
along the same lines...If I was to drag and drop an outlook message which has a bunch of attachments..how would my loop look like..i see keys like "FileContents" , "FileGroupDesc..W" etc...wondering how to put a loop together similar to the windows explorer scenario..
Thanks,
-Sashi.
if (e.Data.GetFormats().Contains("FileGroupDescriptorW"))
{
using (Stream o2 = (Stream)e.Data.GetData("FileGroupDescriptorW"))
{
string SchemaPR_ATTACH_CONTENT_ID = @"http://schemas.microsoft.com/mapi/proptag/0x3712001E";
string SchemaPR_ATTACH_CONTENT_LOCATION = @"http://schemas.microsoft.com/mapi/proptag/0x3713001E";
string SchemaPR_ATTACH_METHOD = @"http://schemas.microsoft.com/mapi/proptag/0x37050003";
string SchemaPR_ATTACH_FLAGS = @"http://schemas.microsoft.com/mapi/proptag/0x37140003";
Microsoft.Office.Interop.Outlook.Application outlook = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.Selection sel = outlook.ActiveExplorer().Selection;
foreach (object item in sel)
{
if (item is Microsoft.Office.Interop.Outlook.MailItem)
{
Microsoft.Office.Interop.Outlook.MailItem mail = item as Microsoft.Office.Interop.Outlook.MailItem;
foreach (Microsoft.Office.Interop.Outlook.Attachment attachment in mail.Attachments)
{
dynamic AttachCID = attachment.PropertyAccessor.GetProperty(SchemaPR_ATTACH_CONTENT_ID);
dynamic AttachContentLocation = attachment.PropertyAccessor.GetProperty(SchemaPR_ATTACH_CONTENT_LOCATION);
dynamic AttachFlags = attachment.PropertyAccessor.GetProperty(SchemaPR_ATTACH_FLAGS);
dynamic AttachMethod = attachment.PropertyAccessor.GetProperty(SchemaPR_ATTACH_METHOD);
/*
* If ATTACH_CONTENT_ID or ATTACH_CONTENT_LOCATION are present and are not null
* string the attachment is embedded. Those are string (PT_STRING8) properties.
* If ATTACH_METHOD, a long (PT_LONG) property is there and has a value of 6
* it's embedded. If ATTACH_FLAGS, a long (PT_LONG) is there and has a value
* of 4 it's embedded.
*/
bool IsEmbededAttachment = !String.IsNullOrEmpty(AttachCID) || !String.IsNullOrEmpty(AttachContentLocation)
|| AttachFlags == 4 || AttachMethod == 6;
if (IsEmbededAttachment) continue;
string abosolutePath = System.IO.Path.Combine(SomeDir, attachment.FileName);
attachment.SaveAsFile(abosolutePath);
}
}
}
}
}