var resultWebPart =
webPartManager.WebParts.Cast<WebPart>()
.FirstOrDefault(
wp => wp is ResultScriptWebPart) as ResultScriptWebPart;
var querySettings = new DataProviderScriptWebPart
{
PropertiesJson =
resultWebPart.DataProviderJSON
};
querySettings.Properties["QueryTemplate"] =
"{searchboxquery} (contentclass:STS_ListItem OR IsDocument:True)";
resultWebPart.DataProviderJSON = querySettings.PropertiesJson;
webPartManager.SaveChanges(resultWebPart);
But beware: Altough there is a Property DataProviderScriptWebPart.QueryTemplate which you can set, it is not included if you request the DataProviderScriptWebPart.PropertiesJson. You have to set the property using the Properties-Collection of the object.
(of course you could also simple edit the Json-String itself, but I prefer this way).
Keine Kommentare:
Kommentar veröffentlichen