Creating XML file with write access given to all the windows account users

后端 未结 3 486
有刺的猬
有刺的猬 2021-01-24 01:19

I am creating an XML file in the common application folder using C#:

%ALLUSERSPROFILE%\\Application Data\\

File will be created when applicatio

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-24 01:45

    I don't think you can pass a parameter to XDocument.Save to control the permissions but you should be able to set them after the save. Something like the following should do:

    System.Security.AccessControl.FileSecurity fsec = System.IO.File.GetAccessControl(fileName);
    fsec.AddAccessRule( new System.Security.AccessControl.FileSystemAccessRule("Everyone", System.Security.AccessControl.FileSystemRights.Modify, System.Security.AccessControl.AccessControlType.Allow));
    System.IO.File.SetAccessControl(fileName, fsec);
    

提交回复
热议问题