I have added the CQWP successfully to the web part page programmatically. Now I want to query data for that web part i.e. I want to display the title of the file from the document library.
My code is:
SPSite site = new SPSite("http://........");
SPWeb web = site.RootWeb;
web.AllowUnsafeUpdates = true;
SPLimitedWebPartManager webParts = web.GetLimitedWebPartManager("SiteAssets/webparts.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
ContentByQueryWebPart wp = new ContentByQueryWebPart();
wp.Title = "My web part using OM";
wp.ListUrl = web.Url + "/Sample Docs";
wp.ListName = "Sample Docs";
wp.ItemXslLink = web.Url + "/Style Library/ItemStyle.xsl";
wp.CommonViewFields = "Title,Text";
webParts.AddWebPart(wp, "Right", 0);
webParts.SaveChanges(wp);
web.Update();
Console.WriteLine("Web part added successfully");
Console.ReadKey();
Document Library is in the root site with name Sample Docs.
I am getting the output like:
How to query data? Please help.