C# .NET - get the Owner of the file created through C#

Asked By santoshk kumar on 30-Jun-08 10:09 AM

i want  to get all the properties of the file  (ex:a txtfile or word file or excel file any file)

properties like (time created,size of the file,etccccccccc)

how to get the owner of the file i.e who  created the file (not the current login user )

many users will be their for a system

if a file is created by user A

and now B is login  now i want to chek who created the file from this (B) account

please asssisit me

file info - Partha Mandayam replied to santoshk kumar on 30-Jun-08 10:12 AM

You can find all file info using WMI.


hi - alice johnson replied to santoshk kumar on 30-Jun-08 01:14 PM

You can make use of the file watcher system to acheive this task.

FileSystemWatcher fsw = new FileSystemWatcher();
fsw.Path = textBox1.Text;
fsw.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite |
                   NotifyFilters.DirectoryName | NotifyFilters.FileName;
fsw.Changed += new FileSystemEventHandler(OnChanged);
fsw.Created += new FileSystemEventHandler(OnCreated);
fsw.Deleted += new FileSystemEventHandler(OnChanged);
fsw.Renamed += new RenamedEventHandler(OnRenamed);
fsw.EnableRaisingEvents = true;

See these links... they will help u understand better:



See this code; - Sagar P replied to santoshk kumar on 30-Jun-08 11:43 PM

private string GetFileOwner(string path)


ManagementObject mgmt = new ManagementObject("Win32_LogicalFileSecuritySetting.path='" + path + "'");

ManagementBaseObject secDesc = mgmt.InvokeMethod("GetSecurityDescriptor",null,null);

ManagementBaseObject descriptor = secDesc.Properties["Descriptor"].Value as ManagementBaseObject;

ManagementBaseObject owner = descriptor.Properties["Owner"].Value as ManagementBaseObject;

return owner.Properties["Domain"].Value.ToString() + "\\" + owner.Properties["Name"].Value.ToString();


Best Luck!!!!!!!!!!!!!!!!!!!

Use this code snipet - Nadaraja Yogendran replied to santoshk kumar on 02-Jul-08 12:14 AM
using System.IO;
using System.Security.AccessControl;
using System.Security.Principal;

namespace ConsoleApplication1

 class GetFileProperty

  static void Main(string[] args)

            FileInfo fileInfo = new FileInfo (@"C:\Contacts.txt");
            FileSecurity fileSecurity = fileInfo.GetAccessControl();
            IdentityReference identityReference = fileSecurity.GetOwner(typeof(NTAccount));