I'm creating a local file transfer app. I would like the user to drag-drop an item into the file transfer application to initiate the file transfer just like skype or other messengers.
While dropping an item. The drop event was triggered. But, I don't know where to get the details of the item such as Location, Size etc., eg., If I drop an Image. I want to read the details mentioned above.
Note:I have enabled the AllowDrop
& Subsribed to Drop
event.[If that helps]
Do you mean Size of file or Size of image in pixel? Anyway, use this code:
private void Window_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, true))
{
string[] droppedFilePaths = e.Data.GetData(DataFormats.FileDrop, true) as string[];
foreach (var path in droppedFilePaths)
{
string location = null;
int pxWidth = 0, pxHeight = 0;
FileInfo fi = new FileInfo(path);
//fi.Length //File size
//fi.DirectoryName //Directory
using (var fs = fi.OpenRead())
{
try
{
var bmpFrame = BitmapFrame.Create(fs);
var m = bmpFrame.Metadata as BitmapMetadata;
if (m != null)
location = m.Location;
pxWidth = bmpFrame.PixelWidth;
pxHeight = bmpFrame.PixelHeight;
}
catch
{
//File isn't image
}
}
this.fileList.Items.Add(string.Format("({0}x{1}), location: {2}", pxWidth, pxHeight, location));
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With