How to get default Downloads folder path

I am creating an Automation project for multiple users, where i have to get files from DOWNLOADS folder.

The challenge is that Downlods folder path is different for each user’s machine e.g “C:\Users\USER_NAME\Downloads”, USER_NAME is different for each user.

how to get Downlods folder path, so that it can be used as dynamic location for each user.

Hi @Bilal_Anwar ,

Could you try using the below Expression :

"C:\Users\USER_NAME\Downloads".Replace("USER_NAME",Environment.UserName)

It should be able to replace the USER_NAME placeholder with the username that is used where the automation is running.

1 Like

Hi @Bilal_Anwar

You can try the following code in the assign activity:

Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\Downloads\"

It get’s the path to UserProfile and then adds Downloads to the path.

3 Likes

This worked for me as well.

The best way to obtain that folder is through the Win32 API call SHGetKnownFolderPath(). Of course things are rarely that simple in this environment. The main problem is that Microsoft never exposed this API through .NET which leaves every method of accessing it a bit of a hack. A .NET programmer would typically drop down to do a P/Invoke to use it but that can be messy under UiPath. GT_Ropa has a good answer. A slightly cleaner version of that is

Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),“Downloads”)

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.