views:

1865

answers:

2

Hello,

In an asp.net app, I have a task that ftps some xml files down to a local folder on my computer. I then want to read those files but when they're copied to my local folder, they don't have the Network Service user account set up. So, my question is how, in .Net C#, do you programmatically add the "Network Service" account with full control to my xml files.

+1  A: 

The following article (titled "Setting NTFS Permissions with C#") will help you out :)

Nippysaurus
+1  A: 

try this code if help

    public static bool CheckReadWriteAccces(string filePath, System.Security.AccessControl.FileSystemRights fileSystemRights)
    {
        FileInfo fileInfo = new FileInfo(filePath);

        string str = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToUpper();
        foreach (System.Security.AccessControl.FileSystemAccessRule rule in fileInfo.GetAccessControl().GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount)))
        {
            if (str == rule.IdentityReference.Value.ToUpper())
                return ((rule.AccessControlType == System.Security.AccessControl.AccessControlType.Allow) && (fileSystemRights == (rule.FileSystemRights & fileSystemRights)));
        }

        return false;
    }


    /// <summary>
    /// Make a file writteble
    /// </summary>
    /// <param name="path">File name to change</param>
    public static void MakeWritable(string path)
    {
        if (!File.Exists(path))
            return;
        File.SetAttributes(path, File.GetAttributes(path) & ~FileAttributes.ReadOnly);
    }
pho3nix