ARTICLE

Programmatically Edit SharePoint Security Group Quick Launch

Posted by Ravish Sindhwani Articles | SharePoint 2010 July 05, 2012
In this article you will see how to programmatically edit the SharePoint Security Group Quick Launch.
Reader Level:

We often have a requirement such as to create a SharePoint Group and at the same time we need to add the name of this newly created security group in the Security Group quick launch.

This can be done using the SharePoint User Interface like this:

SecShr1.jpg

SecShr2.jpg

Likewise we can edit the SharePoint quick launch and add or remove the Security Groups from it.

What if we have a requirement to edit it programmatically?

Suppose we have a requirement to create a SharePoint Group programmatically and at the same time this newly created SharePoint Group needs to be added to the Security Group Quick Launch and removed from some other groups.

The following is the code snippet which can be used to edit the Security Group Quick Launch.

objSPweb.AssociatedGroups.Add() and objSPweb.AssociatedGroups.Remove() are the two methods which are used to edit the Security Group Quick launch.

/***************************************************************/
        ///Edit Group Quick Launch
        ///
        using (SPSite objSPSite = new SPSite(SPContext.Current.Web.Url))
        {
            using (SPWeb objSPweb = objSPSite.OpenWeb())
            {
                objSPweb.AllowUnsafeUpdates = true;
                objSPweb.AssociatedGroups.Add(SPContext.Current.Web.Groups["Test Members"]);
                objSPweb.Update();
            }
        }
/***************************************************************/


In this way we can achieve this requirement.

Hope it will be a help to you!
 

Login to add your contents and source code to this article
post comment
     

Hello Ravish, Good one. But in this no need to add "RunWithElevatedPrivileges" ?

Posted by Mihir Jul 18, 2012
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts