Follow the below given steps to achieve the goal.
- First of all make sure that the site we have to apply the page layout is a "Publishing Site."
- Create a Visual Studio Empty Project.
- Add a Feature Receiver
- Add new reference of "Microsoft.SharePoint.Publishing".
- Apply this on the top of the class.
using Microsoft.SharePoint.Publishing; using System.Linq;
- On feature activation use the below given code.
private void SetDefaultPageLayout(SPWeb _web) { PublishingWeb _pubWeb = PublishingWeb.GetPublishingWeb(_web); if (_pubWeb != null) { PageLayout _pageLayout = (from _pl in _pubWeb.GetAvailablePageLayouts() where _pl.Name == "CustomDefaultPageLayout.aspx" select _pl).FirstOrDefault(); _pubWeb.SetDefaultPageLayout(_pageLayout, true); _pubWeb.Update(); } }
- Call the function "SetDefaultPageLayout" from the Feature Activation event.
Thanks for the transferring knowledge , but how can I apply custom page layout to default page of sharepoint publishing site ?
ReplyDelete@Dipti - The above given example finds out the CustomDefaultPageLayout.aspx from the list of page layouts. If it exists we are setting the CustomDefaultPageLayout.aspx as a Default page layout, so when the user tries to create a new page he/she can see our CustomDefaultPageLayout.aspx settings.
ReplyDeleteHi..
ReplyDeleteThanks for the post could u explain step by step..
Thanks
@Anonymous, I think the post itself is step by step.
Delete