Lorenzo
Lorenzo

Reputation: 19

How to go to a folder without specify the path

I am creating a button that will open one directory in your computer (for example: C:\Users\NameOfUser\Downloads) when you click it. But if I do this on another computer or from another user account with a different name the button doesn’t work. I just used Process.Start() for the button.

Is there a different way to do this that will work from any user account?

Upvotes: 0

Views: 133

Answers (1)

Joel Coehoorn
Joel Coehoorn

Reputation: 416159

You can get most folder paths like this just by calling Environment.GetFolderPath() with the right Environment.SpecialFolder enum value. Unfortunately, the Downloads special folder in .Net isn't quite "special" enough and (imo) is unreasonably complicated to get. If you actually need to know the path, the correct way is to follow the accepted answer here:

Getting Downloads Folder in C#?

Even worse, it's written for C# and uses code that's not very easy to translate.

The good news is there's also a NuGet package I'd expect you can use from VB. The even better news is you don't really care about the exact path in this case. You just want to open an Explorer window via Process.Start(). That means you can use this shortcut (also available via the other question):

Process.Start("shell:Downloads")

Upvotes: 1

Related Questions