Quantcast
Channel: Point Out Hidden Sharepoint Features
Viewing all articles
Browse latest Browse all 18

Set the audience of a publishing page programmatically

$
0
0
Most of the time we want to add publishing pages to pages document library on feature activation for that we normally use module tag to specify file. In file tag we can specify all details, but Target audiance value we can't specify as value is not static like Title and all other properties.
whenever we add custom pages inside pages library from UI, we set properties. to do same things using feature, on feature activation add following code.
In this code block i made every page to be accessable to owner group of site only.
//curWeb is SPWeb object
PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(curWeb);

PublishingPageCollection Pages = pubWeb.GetPublishingPages();

foreach (PublishingPage Page in Pages)

{

Page.CheckOut();

Page.Audience = ";;;;"+ curWeb.AssociatedOwnerGroup.Name;

Page.Update();

Page.CheckIn("Target audiance updated");
}

Viewing all articles
Browse latest Browse all 18

Latest Images

Trending Articles





Latest Images