none
DataProviderJSON not set properly when creating ContentSearchWebpart in programmatically in sharepoint 2013 RRS feed

  • Question

  • Hi All,

    Am creating ContentSearchWebpart programmatically in Feature activation, I have tried to include querytemplate in programmatically using the below code but the query template value not appear on change query box when editing the content search webpart, it shows default value {IsDocument=true or contentclass:"STS_ListItem"}. 

    I have tried to include ItemTemplateId in programmatically, ItemTemplateId working fine.

    Please help to solve the issue. How can I include QueryTemplate in programmatically?

    Code:

    SPLimitedWebPartManager manager = publishPage.ListItem.File.GetLimitedWebPartManager(PersonalizationScope.Shared);
    ContentBySearchWebPart cswp = new ContentBySearchWebPart();
    DataProviderScriptWebPart querySettings = new DataProviderScriptWebPart
    {
    	PropertiesJson =
        cswp.DataProviderJSON
    };
    querySettings.Properties["QueryTemplate"] = " contentclass:STS_ListItem_Posts";
    cswp.DataProviderJSON = querySettings.PropertiesJson;

    Thanks in Advance.

    Pariventhan



    Pariventhan.S

    Monday, November 17, 2014 5:37 PM

Answers