Check if anonymous access is enabled for a sharepoint list programmatically

Another short but useful code snippets to check whether the anonymous access is enabled on a Sharepoint list\library and the base permissions to the anonymous users is ViewListItem. Also some other useful code snippets listed below

To check anonymous is enabled -

if ((list.AnonymousPermMask64 & SPBasePermissions.ViewListItems) == SPBasePermissions.ViewListItems)

// Anonymous Enabled


To disable anonymous on the list do the following -

list.AnonymousPermMask64 = SPBasePermissions.EmptyMask;

To Set more permissions for Anonymous users programmatically on a list

list.AnonymousPermMask64 = SPBasePermissions.AddListItems | BasePermissions.EditListItems | SPBasePermissions.DeleteListItems;


To Enable anonymous on the site (web) level -

web.AnonymousState = SPWeb.WebAnonymousState.On;
web.AnonymousPermMask64 = SPBasePermissions.ViewListItems | SPBasePermissions.ViewVersions | SPBasePermissions.Open | SPBasePermissions.ViewPages;


To Enable anonymous on the list\library level

list.AnonymousState = SPWeb.WebAnonymousState.On;
list.AnonymousPermMask64 = SPBasePermissions.ViewListItems | SPBasePermissions.EditListItems | SPBasePermissions.AddListItems;



Post a Comment


This is a personal weblog. The opinions expressed here represent my own and not those of my employer or anyone else. Should you have any questions or concerns please e-mail me at .

Copyright (c) 2010 @ All rights are reserved.Do Not Copy.

@ Learning