I’m trying to get UiPath to auto-download a data from website and after which it will go to my ‘downloads’ folder and open up the latest file.
I then want it to read range from that excel file and write on a separate excel file I have.
However when writing range, I get an error of ‘Object reference not set to an instance of an object’. Below is my workflow. Appreciate if I can get help to resolve the error. Thanks!
What’s with the String.Join? You don’t need that, you aren’t returning an array, you’re returning an individual string element from the array by using the index. You only need the Directory.GetFiles expression.
Also, 1 is the wrong index. It’s a 0 based array so use (0) to get the first file. That’s why you’re getting the error, you’re specifying an array element that doesn’t exist.
Have added delay but still getting the below error →
RemoteException wrapping System.NullReferenceException: Object reference not set to an instance of an object.
at UiPath.Core.Activities.ScopeActivity.OnFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
at System.Activities.Runtime.FaultCallbackWrapper.Invoke(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
at System.Activities.Runtime.FaultCallbackWrapper.FaultWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
Oh, the result of the expression is an array with only one element.
Try this.
Directory.GetFiles(FolderPath,“*”).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1)(0)
Also, you don’t need to assign this to a variable. You can just put it directly into the property of the Excel Application Scope. It’s good to avoid unnecessarily creating variables. Only if you need the filepath/name later should you assign it to a variable. If you’re only using it for the Excel Application Scope, just put the expression into its property and get rid of the FileName variable.