How to get the project location in a UiPath Studio workflow
You can use UiPath.Constants.Project.Location
to retrieve the path to your project’s root.
This constant is available for use starting with Studio version 2022.10.3. If you are on an older version of Studio, you can use Environment.CurrentDirectory
– but note that this can lead to unexpected behaviors when used inside libraries.
Getting the path to a file inside the project folder
To get the path to a file all you have to do is combine the project path above with the path of the file relateive to the project root.
For example: assume we have a file located in <project_root>/TestData/test_file.txt
. To get the absolute path to this file we can write the following expression:
Path.Combine(UiPath.Constants.Project.Location, "TestData/test_file.txt")
Note: Use Path.Combine
instead of simple string concatenation as this will combine the paths properly no matter what operating system the automation runs on (macOS or Linux use a different character for the path separator). This method also handles missing or double path separators and does some additional validation on the strings to ensure it is a valid path.