Group cannot be found after site is created and adding user to groups | Sharepoint 2013 migrated application RRS feed

  • Question

  • This is MOSS2007 application migrated to SP2013. New site collection get created and later groups are created on newly created site. Once in a while adding groups fails. below is lines of code: Fails in siteGroups.Add(), 'GRP NAME1' is getting created but when browsing it gives 'grp cannt be found' , further code is not executing. 

    Exception details:

    Thursday, July 9, 2015 7:42 PM


  • Hi,

    The following code snippet for your reference:

     SPSite site = new SPSite("site’s URL");
     SPWeb web = site.OpenWeb();
     SPUser user = web.CurrentUser;
     web.SiteGroups.Add("group name", user, user, "description");
     SPGroup g = web.SiteGroups["group name"];

    More information is here:


    Best Regards,


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    • Proposed as answer by Patrick_Liang Thursday, July 16, 2015 1:21 PM
    • Marked as answer by Patrick_Liang Sunday, July 19, 2015 4:59 AM
    Monday, July 13, 2015 2:29 AM