iam new to sharepoint 2010 developer and iam creating a site definition but i could not change the default welcome page using the onet.xml file ,i tried all possible ways but i failed please any one can help?开发者_运维技巧
If any one could, I want a site definition with customized welcome page called Home as example.
Create a web scoped feature with following receiver
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
try
{
var currentWeb = (SPWeb) properties.Feature.Parent;
var pubWeb = PublishingWeb.GetPublishingWeb(currentWeb);
SPFile homePageFile = currentWeb.GetFile("Pages/custompage.aspx");
pubWeb.DefaultPage = homePageFile;
pubWeb.Update();
}
catch (Exception e)
{
//log etc..
}
}
Don't forget to refrence Microsoft.SharePoint.Publishing dll.
Use feature stapling. Feature stapling refrence http://msdn.microsoft.com/en-us/library/ff382738(v=office.12).aspx.
Add following code to your ONET.xml Don't foreget to activate Publishing Feature.
<Configurations>
<Configuration ID="0" ...>
<WebFeatures>
<!-- Publishing Feature ID -->
<Feature ID="GUID" />
<!-- Your Feature ID -->
<Feature ID="GUID" />
</WebFeatures>
</Configuration>
精彩评论