我需要在现有企业搜索中心的Search Box Web部件中修改SearchResultPageURL属性。显然,搜索框是在SearchBoxEx类中建模的。到目前为止,我无法弄清楚如何获取SearchBoxEx实例,我发现很难找到有关此主题的任何信息。
如何在C#中获取SearchBoxEx实例?
答案 0 :(得分:0)
我自己想通了,搜索框webpart的简单演员就足够了,如下:
//get the web part:
SPLimitedWebPartManager webPartManager = file.GetLimitedWebPartManager(PersonalizationScope.Shared);
SPLimitedWebPartCollection webParts = webPartManager.WebParts;
var searchBoxWebPart = (from System.Web.UI.WebControls.WebParts.WebPart webPart in webParts
where (webPart.Title.Equals("Search Box"))
select webPart).First();
//cast:
SearchBoxEx searchBox = (SearchBoxEx)searchBoxWebPart;