2
namespace CSWP
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite oSie = new SPSite("http://sp14:14583/sites/School"))
            {
                using (SPWeb oWeb = oSie.OpenWeb())
                {

                PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(oWeb);
                SPFile file = oWeb.GetFile(oWeb.Url + "Pages/Chapter-1.aspx");
                using (SPLimitedWebPartManager wpm = file.GetLimitedWebPartManager(PersonalizationScope.Shared))
                {
                    ContentBySearchWebPart csw = new ContentBySearchWebPart();
                    var QuerStrv = new DataProviderScriptWebPart
                    {
                        PropertiesJson = csw.DataProviderJSON
                    };
                    csw.ItemTemplateId = "~sitecollection/_catalogs/masterpage/Display Templates/Content Web Parts/Item_ContentSearch.js";
                    QuerStrv.Properties["QueryTemplate"] = "path:http://sp14:14583/sites/CustomSite ContentTypeId:0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39* (IsDocument:True OR contentclass:STS_ListItem) Title:Chapter-1";

                    csw.DataProviderJSON = QuerStrv.PropertiesJson;
                    wpm.AddWebPart(csw, csw.ZoneID, 0);
                    wpm.SaveChanges(csw);             
                    oWeb.Update();                       
                }
            }
        }
    }
}
}

I am trying to modify the DataProviderJSON. My requirement is to get the "Page content" of particular Page in Content search webpart. I am trying to get the page content of Chapter - 1 here.

What am I missing, is there anything wrong with my syntax on passing the DataProviderJsonValue?

Your Answer

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

Browse other questions tagged or ask your own question.