开发者

How can i change the site definition default welcome page

开发者 https://www.devze.com 2023-03-15 03:42 出处:网络
iam new to sharepoint 2010 developer and iam creating a site definition but i could not change the default welcome pageusing the onet.xml file ,i tried all possible ways but i failed please any one ca

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消