Programmatically Add Content By Query WebPart to Page

using (SPLimitedWebPartManager webPartManager = SPContext.Current.Web.GetLimitedWebPartManager("SitePages/CRISP/Home.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))
{
        ContentByQueryWebPart cqwp = new ContentByQueryWebPart();
        cqwp.ContentTypeBeginsWithId = "0x0101006F0A470EEB1140E7AA14F4CE8A50B54C0001CB1477F4DD432AA86DD56CC3887AF40902";
        cqwp.WebUrl = web.ServerRelativeUrl;
        cqwp.MainXslLink = "/Style Library/XSL Style Sheets/ContentQueryMain.xsl"; 
        cqwp.Title = "Recently Published";
        webPartManager.AddWebPart(cqwp, "Top", 1);
        webPartManager.Web.Dispose();
}

Comments

Popular posts from this blog

what is Event Cache table in sharepoint

CAML Query syntax and options in SharePoint

Change anchor link url in sharepoint calender