Find owner/creator of a file


#1

Hi,
I’m searching for a way to find the owner of a file with UiPath studio, how do I do this?


#2

Hi @Siene,

Try below code to get the Owner of the file:
string user = System.IO.File.GetAccessControl(path).GetOwner(typeof(System.Security.Principal.NTAccount)).ToString();

Thanks
Girish


#3

I tried that code already before but I always get an error --> The workflow has validation errors. Review and resolve them first.

System.Activities.InvalidWorkflowException: The workflow has validation errors. Review and resolve them first. —> System.Activities.ValidationException: Compiler error(s) encountered processing expression “System.IO.File.GetAccessControl(file.FullName).GetOwner(typeof(System.Security.NTAccount)).ToString”
‘Is’ expected.


#4

Hi Siene,

Can you please change as below and try :

System.IO.File.GetAccessControl(path).GetOwner(GetType(System.Security.Principal.NTAccount)).ToString


#5

When I try this one I get compile error … it says ‘ls’ is expexted … I don’t know what this error means and how do a resolve it …


#6

Hi @Siene, modifying @Sasi.lalo 's one :

System.IO.File.GetAccessControl(path).GetOwner(GetType(System.Security.Principal.NTAccount)).Value

Notice that:

If a user is an administrator, then the files they created are considered to be owned by the whole administrators group, not the individual user.

Ref: https://stackoverflow.com/a/3370321/772402

So, if you created the file and you are an Administrator, it will always return BUILTIN\Administrators to you.


#7

Thank you, It was indeed the .Value and not .String! thank you!