Getting file names
Getting file names is very simple. Just call:
dragEventArgs.Data.GetData("FileGroupDescriptorW")
this will return MemoryStreamwhich contains the structure FILEGROUPDESCRIPTORA. This can be analyzed to get file names. Here and here are links to CodeProject projects that show you two different ways to parse FILEGROUPDESCRIPTORAin C #, so I wonβt go into details here. I would probably use the technique described in the first draft.
Obtaining Actual Data
, FileContents. , , COM-. , System.Runtime.InteropServices.ComTypes.IDataObject FORMATETC, lindex . , System.Windows.DataObject lindex = -1.
, , WPF DataObject. , NET Framework. , - RegisterDragDrop ole32.dll, IOleDropTarget, COM IDataObject, . , , , .NET Framework, .
, FileContent :
- , , GetData,
- ,
System.Windows.IDataObject, 1 ( ). MethodInfo.Invoke "GetData", : "FileContents", false, ComTypes.DVASPECT, lindexMemoryStream
:
public MemoryStream GetFileContents(IDataObject dataObject, int index)
{
MethodInfo getData = (
from method in dataObject.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)
where method.Name=="GetData" && method.GetParameters().Length==4
select method
).FirstOrDefault();
if(getData==null)
{
FieldInfo innerField = (
from field in dataObject.GetType().GetFields()
where field.FieldType == typeof(IDataObject)
select field
).FirstOrDefault();
if(innerField==null) throw new Exception("Cannot get FileContents from DataObject of type" + dataObject.GetType());
return GetFileContents((IDataObject)innerField.GetValue(dataObject), index);
}
return (MemoryStream)getData.Invoke(dataObject, new object[]
{
"FileContents", false,
System.Runtime.InteropServices.ComTypes.DVASPECT.DVASPECT_CONTENT,
index
});
}