How to know selected file in C#

孤街浪徒 提交于 2019-12-13 18:07:47

问题


I want to build a software.
This software will just get the path of currently selected file.
Suppose I click a file on my desktop.
Now I want to get the path of this file.
So whenever a new selection is made just get the path of newly selected file.
Any ideas?


回答1:


The windows Desktop window is a ListView Control like in the end (at least it was in Windows XP...) so if you need to know selected item of a ListView you basically need to get the handle of the desktop and check what has been selected.

Not sure about windows Vista and 7 bit I guess it's not too different, as David has commented, if you want this for every single explorer window could be more difficult but should still be possible, have a look here for a start:

How do I get the window handle of the desktop?




回答2:


Maybe you should look at the OpenFileDialog class




回答3:


I think you can use what Shaun had said about looking at OpenFileDialog.

You can also refer to this link below:

How to use OpenFileDialog

That link also teaches you how to change the title, filtering files of type and 1 or 2 others regarding OpenFileDialog.

Hope this helps.



来源:https://stackoverflow.com/questions/7220606/how-to-know-selected-file-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!