Answered Changes to CoreResultsWebPart fetched properties not saving

  • Monday, June 04, 2012 2:08 PM
     
      Has Code

    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

All Replies

  • Monday, June 04, 2012 10:07 PM
     
     Answered Has Code

    You can try this before setting SelectColumns and saving:

    ((SearchResultsBaseWebPart)coreResults).PropertiesToRetrieve = string.Empty;


    Blog | SharePoint Field Notes Dev Tool | ClassMaster

    • Marked As Answer by Dylan Cristy Tuesday, June 05, 2012 12:52 PM
    •  
  • Tuesday, June 05, 2012 12:54 PM
     
     
    Thanks Steve, that worked.  I also found a link to another post of yours with a little more explanation on the same topic.