How to create a feature with feature stapplingin SharePoint?
1) Open a new sharepoint visual studio 2010 project
2) Make your feature as normal
3) Find the site definition id you want to staple your feature to
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\1033\XML\webtemp*.xml
4) Create a new module, call it "Stapling" or something
5) Insert this into the module file, replacing the site definition template name and feature guid:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<FeatureSiteTemplateAssociation Id="FEATUREGUID" TemplateName="YOURSITETEMPLATE#0" />
</Elements>
6) A new feature should have been created for "Stapling", but if it has not, create it and the Stapling module to it
7) Set the deployment scope to "Farm"
8) You should have 2 features in your project now
9) Package and deploy
--
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.SharePoint;
namespace AddUsers
{
class AddUserClass
{
static void Main(string[] args)
{
SPSite siteCollection = new SPSite(“Site URL”);
SPWeb site = siteCollection.OpenWeb();
SPGroup AddUserGroup = site.Groups["Group Name"];
AddUserGroup.AddUser(“domain/alias”, “email address”, “Name”, “Description”);
OR
SPRoleAssignment MyRoleAssign = new SPRoleAssignment(“domain/alias”, “email address”, “Name”, “Description”);
SPRoleDefinition MyRoleDef = newSubWeb.RoleDefinitions["Contribute"];
MyRoleAssign.RoleDefinitionBindings.Add(MyRoleDef);
site.RoleAssignments.Add(MyRoleAssign);
site.Dispose();
siteCollection.Dispose();
}
}
}
1) Open a new sharepoint visual studio 2010 project
2) Make your feature as normal
3) Find the site definition id you want to staple your feature to
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\1033\XML\webtemp*.xml
4) Create a new module, call it "Stapling" or something
5) Insert this into the module file, replacing the site definition template name and feature guid:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<FeatureSiteTemplateAssociation Id="FEATUREGUID" TemplateName="YOURSITETEMPLATE#0" />
</Elements>
6) A new feature should have been created for "Stapling", but if it has not, create it and the Stapling module to it
7) Set the deployment scope to "Farm"
8) You should have 2 features in your project now
9) Package and deploy
--
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.SharePoint;
namespace AddUsers
{
class AddUserClass
{
static void Main(string[] args)
{
SPSite siteCollection = new SPSite(“Site URL”);
SPWeb site = siteCollection.OpenWeb();
SPGroup AddUserGroup = site.Groups["Group Name"];
AddUserGroup.AddUser(“domain/alias”, “email address”, “Name”, “Description”);
OR
SPRoleAssignment MyRoleAssign = new SPRoleAssignment(“domain/alias”, “email address”, “Name”, “Description”);
SPRoleDefinition MyRoleDef = newSubWeb.RoleDefinitions["Contribute"];
MyRoleAssign.RoleDefinitionBindings.Add(MyRoleDef);
site.RoleAssignments.Add(MyRoleAssign);
site.Dispose();
siteCollection.Dispose();
}
}
}
No comments:
Post a Comment