How would I create a web part or view that displays all 'Pending' documents within a SPSite. Ideally it would also allow users with the correct permissions to also approve them from here too but to keep things simple I could settle for just a list. Thanks

  • Do you want to get all the documents in multiple libraries of a site or from just one particular library? – Unnie Jun 12 '14 at 8:10

Since you need to get data from multiple libraries you can use SPSiteDataQuery to fetch all the documents with Pending status. You can refer below code to start with:

using (SPSite site = new SPSite(SPContext.Current.Web.Url))
                using (SPWeb web = site.OpenWeb())
                    SPSiteDataQuery query = new SPSiteDataQuery();

                    //Ask for all document libraries
                    query.Lists = "<Lists ServerTemplate=\"101\" />";
                    // check for moderation status =2 ie Pending.
                    query.ViewFields = "";//set the fields which you want to fetch
                    query.Query = @"<Query>
                                            <Eq><FieldRef Name='_ModerationStatus' /><Value Type='ModStat'>2</Value></Eq>

                    // Query all Web sites in this site collection.
                    query.Webs = "<Webs Scope=\"SiteCollection\" />";

                    DataTable dt = web.GetSiteData(query);
  • Thanks for this. I'm new to the SP object model, now you have defined this its much easier to understand. Just need to define my DT – JazzyN Jun 16 '14 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.