search - Change XSLT of the SearchResultWebPart during the FeatureActivated -
i have piece of code changes xslt of searchresultwebpart @ sharepoint 2010 search center result page (spfileitem - spfile of search result page) :
splimitedwebpartmanager wpmanager = spfileitem.getlimitedwebpartmanager(personalizationscope.shared); foreach (webpart wpitem in wpmanager.webparts) { if (wpitem coreresultswebpart) { ((coreresultswebpart)wpitem).uselocationvisualization = false; ((coreresultswebpart)wpitem).xsl = somexsl; wpmanager.savechanges(wpitem); } spfileitem.update(); spfileitem.checkin(consts.checkincomment, spcheckintype.majorcheckin);
but, code doesn't work if called on feature activated (gives invalidoperationexception - incorrect object state). works in console application. after reflecting, found out there piece of code inside searchresultwebpart, checks if webpart wasn't initialized - throws mentioned above exception on setting xsl property. know how work problem out? me it'd quite convenient xsl change @ featureactivated...
i found solution problem, uses different way of setting xsl searchresultbasewebpart.
splimitedwebpartmanager wpmanager = spfileitem.getlimitedwebpartmanager(personalizationscope.shared); foreach (webpart wpitem in wpmanager.webparts) { if (wpitem coreresultswebpart) { ((coreresultswebpart)wpitem).uselocationvisualization = false; ((coreresultswebpart)wpitem).xsllink = spfileitem.web.url + @"/_layouts/xsl/myxsl.xsl"; wpmanager.savechanges(wpitem); } } spfileitem.update(); spfileitem.checkin(consts.checkincomment, spcheckintype.majorcheckin);
Comments
Post a Comment