Sharepoint Search Delegate Controls
I have been followinf this http://msdn.microsoft.com/en-us/library/ms470880.aspx to create a delegate control to overide the default search used in Sharepoint. I am trying to make the search use a custom search scope called people. I don't seem able to do this. Could anyone please give me some tips?
Feature 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 Enter text here Go!
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" %开发者_Python百科> <%@ 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>
To change the default search scope you don't need to create a delegate control. This can be done by selecting Site Actions > Site Settings > Site Collection Administration | Search scopes, and clicking on the "Display Group: Search Dropdown" link (note this can take a few minutes to take effect).
If you want to override other properties on the default control you can use a delegate control similar to the one below in your feature:
<?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>
See SearchBoxEx Members on MSDN for more information on the properties available.
If that doesn't do what you need then you can place a custom control in the %Program Files%\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\CONTROLTEMPLATES directory and load it using a feature similar to the one below:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Control Id="SmallSearchInputBox"
Sequence="25"
ControlSrc="~/_ControlTemplates/MySearchControl.ascx"/>
</Elements>
Note you must also ensure that your masterpage has the appropriate delegate control tag:
<SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox"/>
精彩评论