Code below gets you the list object
string srListURL = <list url>
SPSite mySite = new SPSite(strListURL);
SPWeb myWeb = mySite.OpenWeb();
try
{
SPList myList = myWeb.GetList(strListURL);
}
catch(Exception)
{
//error handling here
}
Showing posts with label Customization. Show all posts
Showing posts with label Customization. Show all posts
Wednesday, September 7, 2011
Friday, August 12, 2011
Listing a site's owners or users with full control
Code below will list down a site's owners or users with full control
//first try the code below, should work most of the time
//unless users/admins mess up with the default groups
try
{
SPGroup myOwnerGroup = myWeb.AssociatedOwnerGroup;
foreach (SPUser myOwner in myOwnerGroup.Users)
{
//do what needs to be done here
}
}
catch (Exception ex)
{
//just ignore & proceed with the fall back mechanism to get the owners
}
//if the code above didn't return any values then the code below is the fall back mechanism
SPSite mySite = new SPSite(<website url>);
SPWeb myWeb = mySite.OpenWeb();
try
{
foreach (SPUser myWebUser in myWeb.AllUsers)
{
if (myWeb.DoesUserHavePermissions(myWebUser.LoginName, SPBasePermissions.ManagePermissions))
{
//do what needs to be done here
}
}
}
catch (Exception ex)
{
//error processing here
}
//first try the code below, should work most of the time
//unless users/admins mess up with the default groups
try
{
SPGroup myOwnerGroup = myWeb.AssociatedOwnerGroup;
foreach (SPUser myOwner in myOwnerGroup.Users)
{
//do what needs to be done here
}
}
catch (Exception ex)
{
//just ignore & proceed with the fall back mechanism to get the owners
}
//if the code above didn't return any values then the code below is the fall back mechanism
SPSite mySite = new SPSite(<website url>);
SPWeb myWeb = mySite.OpenWeb();
try
{
foreach (SPUser myWebUser in myWeb.AllUsers)
{
if (myWeb.DoesUserHavePermissions(myWebUser.LoginName, SPBasePermissions.ManagePermissions))
{
//do what needs to be done here
}
}
}
catch (Exception ex)
{
//error processing here
}
Subscribe to:
Posts (Atom)