locked
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

Answers

  • 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"];
     web.AssociatedGroups.Add(g);
     web.Update();

    More information is here:

    http://blogs.technet.com/b/spsforum/archive/2011/12/09/quick-solution-6-group-cannot-be-found.aspx

    Best Regards,

    Dennis


    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