How to know selected file in C# - c#

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?

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?

Maybe you should look at the OpenFileDialog class

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.

Related

Windows 10 File Browser popup menu showing New items

Using:
Visual Studio 2017
Windows Form
C#
I know how to create a Popup menu displaying items that I have added with code to a native WinForm ContextMenuStrip control.
For example:
My coded Popup menu
What I am looking for and trying to achieve and I have not found so far is how to populate a ContextMenuStrip or any alternative control with the Items that show up when you right click on a blank space on File Explorer and select New and displays a list of the Items you can create base on what you have installed on your computer.
For example:
File Explorer Popup Menu > New
I have looked at many suggestion on different sites but they all show what I already know in how to add items manually and none explain how to add the Items that show up in the File Explorer New sub menu.
Could anyone tell me if this is even possible and/or point me to the right place.
Regards,
You're describing the problem as if it were some programming task, so most probably, it's not the thing you expect to see. Adding items to that menu is more of a problem of configuration of the almighty 'explorer.exe'..
Please see here and read where to place item templates and how to register "file classes" for them in the registry.
I don't like answers like this that just drop a link to other resource, but it's not reasonable to copy&paste&redact it all not knowing if it's what you really want..
Also, note that if you see your desktop, then 'explorer.exe' is already running, and editing its configuration in the registry probably won't take any effect until this process is restarted. Typically you get advices like in that article above:
To have this change take effect, you need to restart your PC, not just sign out and back in.
But that's not true. Just kill explorer.exe via task manager, and then start it back again. No need to reboot.

Get the field on which the explorer window is sorted

I would like to know if there is a way to know how the files in a Windows Explorer window are sorted. Kind of having the "ORDER BY" clause of the window.
Example : "Name ascending" or "Date Modified Descending".
This question is NOT about windows' name-sorting algorithm, but about user-defined sort criteria of a specific open Windows Explorer window.
The goal is, when I double-click on an image in Windows Explorer, to start my program (no problem there), and to find which were the previous and next images (for my program's previous and next buttons), as it was in the explorer window.
Do you know if it's possible, and if so, how ?
That would be perfect if it were in C#, but even C++ would be great.
I guess you could use the shell extension to persist the current sort order of all windows explorer sessions to disk when they changed, with timestamps. Then you read that data into your app when needed to decide how the UI is rendered.

Open PathListBoxScrollBehavior WPF

I'm using blend 4 and vs 2010 to develop a port of an app from iPad to Windows Desktop.
I have a pathlistbox with PathListBoxScrollBehavior attached like in the carousel tutorial showed by Microsoft in the presentation of PathListBoxUtils.
My path is a open path (a line) and I don't want a infinite carousel but a path list box that go through the items but stops when comes in the last or first item. Am I being clear?
Something similar to what exist is on ios (similar to the cover flow effect too)
http://www.youtube.com/watch?v=YIWDlnvHRLw&feature=related
I know there are ways to do that but I can't find it.
There are a check box called WrapItems. When unchecked your Path List Box won't spin infinitely.
There are some bugs to solve yet but are specific to my project.
Hope this solution helps you too.

.lnk shortcuts in Windows Form

I'm trying to create a windows form app that will be able to handle icons from desktop, like keeping them and changing their properties etc...Can you please give me some advice how to create this pseudo-desktop? I haven't found anything that allows me to place .lnk shortcuts on Form.
Thanks
For that, you do not need real LNK files (For creating them you need to use p/invoke).
Just make a ListView with Icon-View. If the User doubleclicke on a item you can handle the click and launch whatever you want to associate with this action.

Adding a context menu item to windows explorer

I've been searching for days about this, but haven't found anything.
I am trying to find out how I can add a context menu item to the windows explorer. I do not want it for specific filetypes, BUT I want it to appear on everything inside a specific path.
For example, I want right-click menus of anything inside "C:\folder" to contain this item, but it shouldn't appear outside this folder...
Is that possible?
Any help will be really appreciated!
Thanks in advance,
John.
The normal way this is achieved is to add it to the Registry under:
HKEY_LOCAL_MACHINE/Software/Classes/Folder/Shell
However in your specific case you want to do some preprocessing before it is displayed (eg is it in the specified directory) which wouldn't work with a simple registry alteration.
I think there is a way to force you way into any operation and add a hook to it. I'm talking about old school knowledge now though and I cannot think what the technology would be called. I think its how you would have, for example, forced your way into the rendering engine to put custom skins on normal explorer windows or inject an extra button into the title bar of apps like you used to see back in the day.
It just occurred to me that adding a button to the windows title bar might have given a search starting point, I found this article which refers to subclassing windows components and injecting your own behaviour. I think that is what I'm talking about above:
http://www.codeproject.com/KB/wtl/titlebar.aspx
Hope this gives you a new direction to search in.

Categories

Resources