Changes to CoreResultsWebPart fetched properties not saving
-
4 iunie 2012 14:08
Hi,
I am trying to configure several aspects of the default search webparts in an enterprise search center through a feature receiver. I'm starting with the fetched properties of the search results. I found this other post about how to access the fetched properties of the core results webpart through code, so I'm trying to use that property (SelectedColumns) to make the changes I want. However, my changes don't stick. I'm also setting UseLocationVisualization to false, and after activating the feature if I go in and edit the webpart, I can see that it has been unchecked, so I know I'm hitting the right webpart, but the fetched properties stay as the default list of columns. Here's my code:
SPFile resultsPage = (SPFile)web.GetFileOrFolderObject(web.Url + "/Pages/results.aspx"); resultsPage.CheckOut(); resultsPage.Update(); wpManager = web.GetLimitedWebPartManager(resultsPage.Url, PersonalizationScope.Shared); CoreResultsWebPart coreResults = null; foreach (System.Web.UI.WebControls.WebParts.WebPart webPart in wpManager.WebParts) { if (webPart.GetType().Equals(typeof(CoreResultsWebPart))) { coreResults = (CoreResultsWebPart)wpManager.WebParts[wpManager.WebParts.IndexOf(webPart)]; coreResults.UseLocationVisualization = false; coreResults.SelectColumns = @"<Columns><Column Name=""WorkId""/> <Column Name=""BlahBlahBlah""/></Columns>"; wpManager.SaveChanges(coreResults); } } resultsPage.CheckIn(string.Empty); resultsPage.Publish(string.Empty); resultsPage.Update();
Does anyone know what I might be missing in order to get my SelectColumns value to stick?
Thanks,
Dylan
Toate mesajele
-
4 iunie 2012 22:07
You can try this before setting SelectColumns and saving:
((SearchResultsBaseWebPart)coreResults).PropertiesToRetrieve = string.Empty;
Blog | SharePoint Field Notes Dev Tool | ClassMaster
- Marcat ca răspuns de Dylan Cristy 5 iunie 2012 12:52
-
5 iunie 2012 12:54Thanks Steve, that worked. I also found a link to another post of yours with a little more explanation on the same topic.