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");
}
}
}
}
}
}
}

2 comments:

  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
  2. Novamaker, mannequin processing, printer administration and monitoring, all in one. We Heated Weighted Blankets are large fans of the Creality Ender three, which we profile next. But we've to exchange the Ender three's Top Pick slot from our last update with the Elegoo Neptune 2, which is everything the Ender three is, but less expensive and with generally smoother prints. To be trustworthy, we see Elegoo and Anycubic working neck-and-neck phrases of|in relation to} quality printers. When you click through from our website to a retailer and purchase a services or products, we could earn affiliate commissions. This helps support our work, but does not affect on} what we cowl or how, and it does not affect on} the value you pay.

    ReplyDelete