我一直关注此http://msdn.microsoft.com/en-us/library/ms470880.aspx来创建一个委托控件来覆盖Sharepoint中使用的默认搜索。我试图让搜索使用一个名为people的自定义搜索范围。我似乎无法做到这一点。有人可以给我一些提示吗?
功能xml
<?xml version="1.0" encoding="utf-8"?>
<Feature
Id="9E16894A-998F-4928-97B3-FCB35EAD1C49"
Title="Standard User Interface Items"
Description="Provides several standard user interface components and links"
Version="12.0.0.0"
Hidden="TRUE"
DefaultResourceFile="core"
Scope="Web"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="controls\SearchArea.xml" />
</ElementManifests>
</Feature>
SearchArea.xml 在此输入文字 走!
mySearchArea.ascx
<%@ Control Language="C#" Inherits="Microsoft.SharePoint.WebControls.SearchArea,Microsoft.SharePoint,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" compilationMode="Always" %>
<%@ Register Tagprefix="wssawc" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %>
<%
string strScopeWeb = null;
string strScopeList = null;
string strWebSelected = null;
SPWeb web = SPControl.GetContextWeb(Context);
string strEncodedUrl
= SPHttpUtility.EcmaScriptStringLiteralEncode(
SPHttpUtility.UrlPathEncode(web.Url + "/_layouts/searchresults.aspx", false, false)
);
strEncodedUrl = "'" + strEncodedUrl + "'";
strScopeWeb = "'" + SPHttpUtility.HtmlEncode( web.Url ) + "'";
SPList list = SPContext.Current.List;
if ( list != null &&
((list.BaseTemplate != SPListTemplateType.DocumentLibrary && list.BaseTemplate != SPListTemplateType.WebPageLibrary) ||
(SPContext.Current.ListItem == null) ||
(SPContext.Current.ListItem.ParentList == null) ||
(SPContext.Current.ListItem.ParentList != list))
)
{
strScopeList = list.ID.ToString();
}
else
{
strWebSelected = "SELECTED";
}
%>
<table border=0 cellpadding="0" cellspacing="0" class='ms-searchform'><tr>
<td>
<SELECT id='idSearchScope' name='SearchScope' class='ms-searchbox' title=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SearchScopeToolTip),Response.Output);%>>
<OPTION value=<%=strScopeWeb%> <%=strWebSelected%>> <SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,search_Scope_Site%>" EncodeMethod='HtmlEncode' Id='idSearchScopeSite'/> </OPTION>
<%
if (strScopeList != null)
{
%>
<OPTION value=<%=strScopeList%> SELECTED> <SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,search_Scope_List%>" EncodeMethod='HtmlEncode' Id='idSearchScopeList'/> </OPTION>
<%
}
%>
</SELECT>
</td>
<td>
<INPUT Type=TEXT id='idSearchString' size=25 name='SearchString' display='inline' maxlength=255 ACCESSKEY=S class='ms-searchbox' onKeyDown="return SearchKeyDown(event, <%=strEncodedUrl%>);" title=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SearchTextToolTip),Response.Output);%>>
</td>
<td>
<div class="ms-searchimage"><a target='_self' href='javascript:' onClick="javascript:SubmitSearchRedirect(<%=strEncodedUrl%>);javascript:return false;" title=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SearchImageToolTip),Response.Output);%> ID=onetIDGoSearch><img border='0' src="/_layouts/images/gosearch.gif" alt=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SearchImageToolTip),Response.Output);%>></a></div>
</td>
</tr></table>
答案 0 :(得分:1)
要更改默认搜索范围,您无需创建委托控件。这可以通过选择网站操作&gt;来完成。网站设置&gt;网站集管理|搜索范围,然后点击“显示组:搜索下拉列表”链接(请注意,此操作可能需要几分钟才能生效)。
如果要覆盖默认控件上的其他属性,可以使用与功能中类似的委托控件:
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Control
Id="SmallSearchInputBox"
Sequence="25"
ControlClass="Microsoft.SharePoint.Portal.WebControls.SearchBoxEx"
ControlAssembly="Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">
<Property Name="GoImageUrl">/_layouts/1033/images/myapp/go-btn.gif</Property>
<Property Name="GoImageUrlRTL">/_layouts/1033/images/myapp/go-btn.gif</Property>
<Property Name="GoImageActiveUrl">/_layouts/1033/images/myapp/go-btn-hover.gif</Property>
<Property Name="GoImageActiveUrlRTL">/_layouts/1033/images/myapp/go-btn-hover.gif</Property>
<Property Name="QueryPromptString">Enter search query here</Property>
<Property Name="UseSiteDefaults">true</Property>
<Property Name="FrameType">None</Property>
<Property Name="ShowAdvancedSearch">false</Property>
<Property Name="DropDownMode">HideScopeDD</Property>
<Property Name="TextBoxWidth">200</Property>
<Property Name="CssClass">headersearch</Property>
</Control>
</Elements>
有关可用属性的更多信息,请参阅SearchBoxEx Members on MSDN。
如果这不能满足您的需求,那么您可以在%Program Files%\ Common Files \ Microsoft Shared \ Web Server Extensions \ 12 \ TEMPLATE \ CONTROLTEMPLATES目录中放置一个自定义控件,并使用类似于下面的那个:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Control Id="SmallSearchInputBox"
Sequence="25"
ControlSrc="~/_ControlTemplates/MySearchControl.ascx"/>
</Elements>
请注意,您还必须确保您的母版页具有适当的代理控制标记:
<SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox"/>