1

Here is my scenario,

I have an Outlook add-in which, I am writing some information into a common file through this Add-In. When I created a installable, I kept common file under "All Users"(Common Application Data Folder) folder. When I install this add-in on XP it is working perfectly fine and no issue of permission.

Now, when i move this application to Windows 7, I am getting some file access permission exception. With reference to some blogs, I have added application specific folder under "All Users." After this also I am unable to write into this file.

Is there anything else that I need to do, by which I will able to write into this file.

I have read some blogs about UAC, however, I didn't get clear picture of its use for Add-in.

2 Answers 2

1

By default, standard users don't have write access to the common app data folder. If you wish to allow your users to write there you should create a sub-folder and apply an appropriate ACL. Do this as part of your installation because that's when you have sufficient rights to create the ACL.

Another option is to store these settings on a per-user basis and thereby avoid the issues with security.

8
  • Thank you for your response. I have already created application specific sub folder under "Common Application Data Folder", however I am not aware with ACL with installation. Is there any specific reference, by which I can come over this situation? Dec 5, 2011 at 6:10
  • Your setup tool will be able to apply security settings, i.e. ACLs. Dec 5, 2011 at 6:14
  • I have checked, however, I am unable to get those. I am using VSTO 2010. I will appreciate your detail description if any. Dec 5, 2011 at 6:30
  • what tool do you use to create your install program? Dec 5, 2011 at 6:36
  • I am using visual studio's setup project template? Dec 5, 2011 at 6:38
0

To add specific permissions to files, I use a helper extension function I created for this: (You need the right privs to do this on a file)

public static void AddAccessEveryone(this FileInfo file, FileSystemRights rights, AccessControlType accessType)
{
    FileSecurity access = file.GetAccessControl();
    SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
    access.AddAccessRule(new FileSystemAccessRule(everyone, rights, accessType));
    file.SetAccessControl(access);
}

You call it like this:

file.AddAccessEveryone(FileSystemRights.Read | FileSystemRights.Write, AccessControlType.Allow);

You have to add the reference System.ServiceModel to your project. You must also call it after the file has been created, it doesn't do any good to call it before then.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.