Hi, I am building a project in UiPath. I am trying to access a file using this method:

Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)+“\Downloads” + “\KNMI_”+DateTime.Now.AddDays(-1).ToString(“yyyyMMdd”)+“.txt”

This will get the download folder, the file contains the weather from yesterday hence the -1 days.

This function will give me C:\Users\name\Downloads\KNMI_20200516.txt

This is also the same location where the file is stored, still using the Read Text File it gives me the System.AggregateException. Any ideas why?

Thanks in advance!

Welcome to the forum.

Give a try on another Path, not residing within the special folder c:\Users…
If this is working, then focus on an analysis if the Access Rights for working with the Download folders are causing the exception

Also have a look on the Path combine method. This lest easy construct a Path:


EDIT: misread ppr post, this will still serve as example

To use special folders with Path.Combine

timestamp = DateTime.Now.AddDays(-1).ToString(“yyyyMMdd”)
filename = String.Format("KNMI_{0}.txt", timestamp)
filepathRaw = Path.Combine("%USERPROFILE%", "Downloads", filename)
filepath = Environment.ExpandEnvironmentVariables(filepathRaw)

1 Like

Maybe I was not clear enough in my statement. My message was

  • test access rights confusion by using another filepath, not residing in special folders
  • encourage to use Path.Combine (sure should work for every folder)

@marijn00 the statement from MSAN is really beautiful and allows a clear inspection on the different stages. I would use it directly

I just realize it and edited my message :wink:

@msan @ppr thank you for your input. I changed to code to what you said. Regarding the testing, earlier in the project I do the same thing using an Excel Application Scope and it does work there, but using the read file it doesn’t work. Any idea how this is caused?