Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I need a content query web part that returns me the last 10 modified or added documents into any document library on that specific website.

How can I add the rowlimit by code?

ContentByQueryWebPart cqwp = new ContentByQueryWebPart();
                                cqwp.ContentTypeBeginsWithId = "0x0101008E49C3D400044AB3A2F1DD14073E74F6001D06D12572244BE3A11AAEE3ED60F576";
                                cqwp.WebUrl = SPContext.Current.Web.ServerRelativeUrl;
                                cqwp.Title = "Last Updated Documents";                                
                                string query = @"<Where> "+
                                                    ""+
                                                "</Where>"+
                                                "<OrderBy> "+
                                                    "<FieldRef Name='Modified'  Ascending='FALSE'/> "+
                                                "</OrderBy>";
                                cqwp.QueryOverride = query;
                                cqwp.ListsOverride =  "<Lists ServerTemplate='101'></Lists>";
                                cqwp.WebsOverride = "<Webs Recursive='False' />";
                                cqwp.ViewFieldsOverride = @"<ViewFields> " +
                                                                "<FieldRef Name='Type' Nullable='True' Type='Text'/> " +
                                                                "<FieldRef Name='Name' Nullable='True' Type='Text'/> " +
                                                                "<FieldRef Name='ContentType' Nullable='True' Type='Text'/> " +
                                                                "<FieldRef Name='Modified' Nullable='True' Type='DateTime'/> " +
                                                                "<FieldRef Name='Modified By' Nullable='True' Type='Text'/> " + 
                                                            "</ViewFields>";                               

                                mgrPageManager.AddWebPart(cqwp, "Footer", 0);
                                mgrPageManager.SaveChanges(cqwp);
share|improve this question

1 Answer 1

up vote 1 down vote accepted

You can set the RowLimit property of your SPQuery object because the is in the schema definition of a view not on the <Query>.

share|improve this answer
    
there is no such SPQuery object on a content query webpart, there is only queryoverrides which is a string –  Esteban V Jun 10 '13 at 10:08
1  
what about msdn.microsoft.com/en-us/library/… –  Salvatore Di Fazio Jun 10 '13 at 10:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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