How to get pages pending approval programmatically?

I have a site with several sub-sites inherited,

each SubSite received a standard Sharepoint approval protocol attached to the page library,

therefore, whenever pages are submitted for approval,

a task will be created created in the list of workflow tasks on each of the sub-sites.

Using SPSiteDataQuery, you can query data from the entire child node in the workflow task list, as shown in the following example:

DataTable dt = null;
using (SPSite site = new SPSite("Site Url"))
{
    using (SPWeb web = site.OpenWeb())
    {
        SPSiteDataQuery q = new SPSiteDataQuery();
        q.Lists = "<Lists ServerTemplate='107' />";
        q.Query = @"<OrderBy><FieldRef Name='Modified' Ascending='False' /></OrderBy>";
        q.ViewFields = "<FieldRef Name=\"Title\" />"\;
        q.Webs = "<Webs Scope='Recursive'/>";
        q.RowLimit = 20;

        dt = web.GetSiteData(q);
    }
}
return dt;

whenever a page is awaiting approval, the status of the workflow is not running, and it is completed when it is approved.

, Not Started, , ? Title FileRefUrl?

.

+3
1

:

        using (SPSite site = new SPSite(SharepointServerURL))
        {
            using (SPWeb web = site.OpenWeb())
            {                    
                SPFolder sitePages = web.Folders["/SitePages"];
                SPListItemCollection pages = sitePages.DocumentLibrary.Items;                    

                foreach (SPListItem page in pages)
                {
                    if (page.ModerationInformation.Status == SPModerationStatusType.Pending)
                    {
                        Console.WriteLine(page.Title + page.Url);                            
                    }
                }
            }                
        }
+4

All Articles