Add Publishing page to sharepoint site programmatically at Feature activation
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb web = properties.Feature.Parent as SPWeb;
web.AllowUnsafeUpdates = true;
SPWebApplication Webapp = web.Site.WebApplication;
SPList list = web.Lists["Pages"];
String url = list.RootFolder.ServerRelativeUrl.ToString();
PublishingSite pubSite = new PublishingSite(web.Site);
//store your Page Layout Name
string pageLayoutName = "ArticleLeft.aspx";
string layoutURL = web.Url + "/_catalogs/masterpage/" + pageLayoutName;
PageLayout layout = pubSite.PageLayouts[layoutURL];
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
PublishingPage newCampaignPage;
string campaignPage = "Campaigns.aspx"; //Page name which you want to create from the template
newCampaignPage = publishingWeb.GetPublishingPages().Add(campaignPage, layout);
newCampaignPage.Title = "Campaigns";
newCampaignPage.Update();
}
}
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb web = properties.Feature.Parent as SPWeb;
web.AllowUnsafeUpdates = true;
SPWebApplication Webapp = web.Site.WebApplication;
SPList list = web.Lists["Pages"];
String url = list.RootFolder.ServerRelativeUrl.ToString();
PublishingSite pubSite = new PublishingSite(web.Site);
//store your Page Layout Name
string pageLayoutName = "ArticleLeft.aspx";
string layoutURL = web.Url + "/_catalogs/masterpage/" + pageLayoutName;
PageLayout layout = pubSite.PageLayouts[layoutURL];
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
PublishingPage newCampaignPage;
string campaignPage = "Campaigns.aspx"; //Page name which you want to create from the template
newCampaignPage = publishingWeb.GetPublishingPages().Add(campaignPage, layout);
newCampaignPage.Title = "Campaigns";
newCampaignPage.Update();
}
}
I’m not that much of a internet reader to be honest but your blogs really nice, keep it up!
ReplyDeleteI'll go ahead and bookmark your website to come back later.
Cheers
Look into my web blog Testostorm Reviews