Find owner/creator of a file

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

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

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.

Hi Siene,

Can you please change as below and try :

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

1 Like

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 …

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: How can I find out who created a file in Windows using .NET? - Stack Overflow

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

6 Likes

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

1 Like