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;


list.Update();

To Enable anonymous on the site (web) level -


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

web.Update();

To Enable anonymous on the list\library level

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

list.Update();

0 comments:

Post a Comment

Disclaimer

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 sharepointprogrammingblogger@gmail.com .

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

@ Learning SharePoint.com