如何获取SearchBoxEx实例来修改其属性?

时间:2011-12-09 15:32:06

标签: c# sharepoint sharepoint-2010

我需要在现有企业搜索中心的Search Box Web部件中修改SearchResultPageURL属性。显然,搜索框是在SearchBoxEx类中建模的。到目前为止,我无法弄清楚如何获取SearchBoxEx实例,我发现很难找到有关此主题的任何信息。

如何在C#中获取SearchBoxEx实例?

1 个答案:

答案 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;