Hi,

how can i open and show a folder in windows using C#. like after complting some task i want the app to open the particular folder and present it to the user.

like we open any folder by double clicking on it. I want to do it the same thru code

thx

Dani AI

Generated

Short summary: you want Windows to show the folder you just processed (not a dialog inside your app). The usual, reliable approach is to launch the shell for that folder from your app — not to re-open a FolderBrowser/OpenFile dialog. laid out the workflow; was right to mention folder dialogs for selection, and 's attempt to call a non‑existent Process.Open should be replaced with the standard Process API.

A simple, cross‑version way (desktop app) is to start the folder path with the Process API. Check the folder exists first, and prefer an explicit ProcessStartInfo when you need shell semantics:

if (Directory.Exists(folderPath))
{
    System.Diagnostics.Process.Start(folderPath);
}

Or, to be explicit (and avoid ambiguity if a same‑named executable exists), append a trailing separator and use shell execute:

var psi = new ProcessStartInfo {
    FileName = folderPath + Path.DirectorySeparatorChar,
    UseShellExecute = true,
    Verb = "open"
};
System.Diagnostics.Process.Start(psi);

Process.Start is the documented way to start/open a folder. Also note the trailing‑slash trick is recommended to avoid accidental launching of a same‑named executable. (learn.microsoft.com)

If you want Explorer to open and select a specific file (so the user sees exactly which file was processed), you can call Explorer with the /select switch:

System.Diagnostics.Process.Start("explorer.exe", "/select,\"" + fullFilePath + "\"");

Be aware Explorer's /select can be flaky in some edge cases (newly created folders); for the most robust native behavior you can call the Shell API SHOpenFolderAndSelectItems via P/Invoke. (stackoverflow.com)

Note for modern .NET: shell behaviors require UseShellExecute=true (its default changed in .NET Core / .NET 5+). Also remember Process.Start runs on the machine the code runs on (so a server app won't pop Explorer on a remote user's desktop). Wrap calls in a try/catch for Win32Exception and validate the path first. (learn.microsoft.com)

Recommended Answers

All 6 Replies

You can use the OpenFileDialog or FolderBrowserDialog from the toolbox.

You can use the OpenFileDialog or FolderBrowserDialog from the toolbox.

i'm already using that in my program. But I couldn't figure out how I can open and show the folder to the user, not in my program and not for file selecting or browsing folders;

Ok in short this is what the program does

1. Ask the user to browse folder
2. Read all the files within the folder
3. check files for integrity
4. and then finishes

Now I want to do

5. Show the folder to the user in which the processing was done. i.e. open that folder in windows. thats it

I hope i'm clear now

thx

You make it perfectly clear!
OpenFileDialog has a property called InitialDirectory, feed it the folder the user was browsing, is this what you want?
Or do you want to take your app to the background, to manipulate XP? Vista? to open a FileDialog for the folder which your app was manipulating?

You make it perfectly clear!
OpenFileDialog has a property called InitialDirectory, feed it the folder the user was browsing, is this what you want?
Or do you want to take your app to the background, to manipulate XP? Vista? to open a FileDialog for the folder which your app was manipulating?

Yes, I want the later case

to take my app to the background, to manipulate XP? Vista? to open a FileDialog for the folder which your app was manipulating?

so the app can sshow the user which files in the folder were processed.

No, Danny they need to do that System.Diagnostics.Process.Open("DirectoryPath"); C# Sample

System.Diagnostics.Process.Open("C:\\Windows");

Thanks for pointing this out Ramy!
Did not know this.:-/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.