开发者

WPF List files from a folder

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜