Friday, May 13, 2011

Publishing Pages : check-in file programmatically

One of the common scenarios when working with content migration is to handle the files checked out by other users. Following code is written to check-in all files check out by any users.

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please enter site url");

using (SPSite site = new SPSite(Console.ReadLine()))
{
using (SPWeb web = site.OpenWeb())
{
PublishingPageCollection publishingPages = PublishingWeb.GetPublishingWeb(web).GetPublishingPages();

foreach (PublishingPage page in publishingPages)
{
SPFile file = page.ListItem.File;
if (file.CheckedOutByUser != null)
{
Console.WriteLine("The page {0} is check out by user {1}. Check-in in to take control.", file.Title, file.CheckedOutByUser);

file.CheckIn("checked in by script", SPCheckinType.MajorCheckIn);
SPModerationInformation moderationInformation = page.ListItem.ModerationInformation;
if (moderationInformation.Status == SPModerationStatusType.Pending)
{
file.Approve("Approved by script");
}
if (moderationInformation.Status == SPModerationStatusType.Draft)
{
file.Publish("Published using script");
file.Approve("Approved by script");
}
}
}
}
}
}
}

1 comment:

  1. While all of the free online slots sites in our list accept cryptocurrencies, BitStarz is a multi-award winning crypto casino that stands head and shoulders above the rest. With its current choice of slots standing at around 190 in whole, Red Dog Casino doesn’t have the largest choice of free online slots on the town. But all of its video games are taken from RealTime Gaming, which suggests you’re entry to|gaining access to|having access to} the software program provider’s bespoke assortment. Of course, you can also also|you can even} play a tremendous 300+ online slots at this main online 온라인카지노 casino entirely at no cost. And because of|as a end result of} Slots.LV is consistently updating its library with new titles, there’s no end to the fun. Ignition has a closely curated choice of over a hundred and fifty slot games.

    ReplyDelete