i have used this code but when i deploy nothing changes :

public override void FeatureActivated(SPFeatureReceiverProperties properties)
            SPSite site = properties.Feature.Parent as SPSite;

            if (site != null)
                SPWeb topLevelSite = site.RootWeb;
                string webAppRelativePath = topLevelSite.ServerRelativeUrl;
                if (!webAppRelativePath.EndsWith("/"))
                    webAppRelativePath += "/";
                foreach (SPWeb web in site.AllWebs)
                    // Activate the publishing feature for all webs.
                    web.MasterUrl = webAppRelativePath + "_catalogs/masterpage/-collabspace.master";
                    web.CustomMasterUrl = webAppRelativePath + "_catalogs/masterpage-collabspace.master";
                    web.SiteLogoUrl = "/Style%20Library/labspace/images/-logo.jpg";

                    string groupName = "Ma-SolCollab";
                    string groupDescription = "Group for CollabSol";

                        CreateSubSiteGroup(SPContext.Current.Web, groupName, "Full Control", groupDescription);

                    catch (Exception ex)
                        string message = ex.Message;

 private static void CreateSubSiteGroup(SPWeb web, string groupName, string PermissionLevel, string groupDescription)
            SPUserCollection users = web.AllUsers;
            SPUser owner = web.SiteAdministrators[0];
            SPMember member = web.SiteAdministrators[0];
            SPGroupCollection groups = web.SiteGroups;
            groups.Add(groupName, member, owner, groupDescription);
            SPGroup newSPGroup = groups[groupName];
            SPRoleDefinition role = web.RoleDefinitions[PermissionLevel];
            SPRoleAssignment roleAssignment = new SPRoleAssignment(newSPGroup);
            web.AllowUnsafeUpdates = true;
            web.AllowUnsafeUpdates = false;

You cannot use SPContext.Current inside FeatureActivated function cmd.exe process does not understand or know how to get your current context! If you are running via browser, you have the w3wp.exe process from which you can get the context!

Since you have your web defined in foreach (SPWeb web in site.AllWebs)

pass the same in CreateSubSiteGroup(web, groupName, "Full Control", groupDescription);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.