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.
wp.Title = "My web part using OM"; wp.ListUrl = web.Url + "/Sample Docs"; wp.ListName = "Sample Docs"; wp.XslLink = web.Url + "/Style Library/XSL Style Sheets/ItemStyle.xsl"; wp.QueryOverride = "<where> <Eq> <FileLeafRef Name='Title' /> <Value Type='Text'/></Eq></Where>"; webParts.AddWebPart(wp, "Right", 0); webParts.SaveChanges(wp); web.Update();Though I am getting the error that there is a problem with query.
– users1100 Sep 12 '13 at 09:07<where> <Eq> <FieldRef Name='FileLeafRef'/><Value Type='File'>example1</Value></Eq></Where>still I am getting error. – users1100 Sep 12 '13 at 09:28