开发者

WPF List files from a folder

开发者 https://www.devze.com 2023-03-25 03:31 出处:网络
I want to get a number of songs from a folder and list their names in a WPF Listview. I also want each item in the list view to be a draggable file and can be copied from the list to the desktop. I\'

I want to get a number of songs from a folder and list their names in a WPF Listview. I also want each item in the list view to be a draggable file and can be copied from the list to the desktop. I've achieved this on one button, using the code:

Point mpos = e.GetPosition(null);
Vector diff = this.start - mpos;
string[] files = new String[1];
files[0] = @"C:\Song1.mp3";
DragDrop.DoDragDrop(this, new DataObject(DataFormats.FileDrop, files),
   DragDropEffects.Copy);

For that each item in the list needs to have a filepath string associated with it.

How do I:

1. Get the files from a folder and list them.

2. Associate with each one a filepath string for the dragging.

T开发者_开发问答hanks!


You can use Directory.GetFiles() to get all the file paths in a folder and then use Path.GetFileName() (or Path.GetFileNameWithoutExtension()) on each path returned to get just the file names.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号