在WPF中拖放文件传输.如何在窗口中获取已删除内容的文件名

Pri*_*aka 4 c# wpf file-upload

我正在创建一个本地文件传输应用程序.我希望用户将项目拖放到文件传输应用程序中以启动文件传输,就像skype或其他信使一样.

丢弃一个项目.丢弃事件已触发.但是,我不知道从哪里获取项目的详细信息,例如位置,大小等,例如,如果我放下图像.我想阅读上面提到的细节.

注意:我已启用AllowDrop&Subsribed to Drop事件.[如果有帮助]

vor*_*olf 5

你的意思是文件大小或像素大小?无论如何,使用此代码:

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));
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)