Reputation: 43
I am moving files from source folder to destination folder using File.Move, when files got moved to destination folder file owner name is getting changed to Administrator instead of original user I tried below code but unable to set file owner in destination folder. My application is a windows service
My Code:
Dim fOwner = File.GetAccessControl(srcFolder + "\" + srcFileName).GetOwner(GetType(System.Security.Principal.SecurityIdentifier))
After Moving file I am setting it to original owner
File.GetAccessControl(destFolder + "\" + destFileName).SetOwner(fOwner)
but it still shows owner as administrator. Tried lot of examples but no luck.
Upvotes: 1
Views: 247
Reputation: 547
I believe you need to also call SetAccessControl
to apply the owner change. Try something like this:
Dim fs as FileSecurity = File.GetAccessControl(Path.Combine(destFolder, destFileName))
fs.SetOwner(fOwner)
File.SetAccessControl(Path.Combine(destFolder, destFileName),fs)
Upvotes: 1