SPUser Group Management



SPUser Group Management


How to Create\Update\Retrieve\Delete a Personal UserGroup for a User in SharePoint by using APIs



Personal User Groups can be Created, Updated, Retrieved and Deleted by using SharePoint APIs as given below...


//Create Group
SPUser spUser = mySite.Owner;
SPMember spMemebr = mySite.RootWeb.Users["My User Name"];
spUser.Groups.Add("GroupName", spMemebr, spUser, "This is Group Description");
spUser.Update();


//Update Group
SPUser spUser = mySite.Owner;
SPGroup spGroup = spUser.Groups["GroupName"];
spGroup.Name = "newGroupName";
spGroup.Update();


//Retrieve Group
SPUser spUser = mySite.Owner;
SPGroupCollection spGroupCollection = spUser.Groups;


foreach (SPGroup spGroup in groupCollection)
{
//Store all groups in internal collection
}

//Delete Group
SPUser spUser = mySite.Owner;
spUser.Groups.Remove("newGroupName");
spUser.Update();



Save Site As Template

Save Site As Template


How to Save Site As Template (stp file)

Go to "/_layouts/savetmpl.aspx" in your current site, Now you will see the option to save your current site as template. (screenshot given below)
Enter the stp file name and check the checkbox "Include Content" if you want to include the all content (lists, libraries,etc) from the site current site.



Note: If your Publishing Feature is not turned on you will see the "save site as template" option under SiteSettings -> LookAndFeel section, the above scenario will apply only when the Publishing Feature is turned off.