sharepointsharepoint-2007spsitedataquery

How to programmatically get pages which is pending for approval?


I having a Site with multiple SubSite inherited,

each of the SubSite got a default Sharepoint approval workflow attached on Pages Library,

therefore, whenever the pages is submit for approval,

there will be a task created in Workflow Tasks List on each of the SubSite.

By using SPSiteDataQuery manage to query data from all the subsite in Workflow Tasks List, as per 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 the page is pending for approval, the workflow status is Not Started and it is Completed when it is approved.

So if I query based on all workflow status equal Not Started, then it will return all results which is pending for approval? and how can I get the pages Title and FileRefUrl?

thank you in advance for any advises.


Solution

  • Personally, I would do this:

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