2010-01-15 80 views
1

我一直followinf此http://msdn.microsoft.com/en-us/library/ms470880.aspx創建委託控件來覆蓋Sharepoint中使用的默認搜索。我正在嘗試使用名爲people的自定義搜索範圍進行搜索。我似乎無法做到這一點。任何人都可以請給我一些提示?Sharepoint搜索委託控件

功能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> 

回答

1

要改變你不需要創建一個委託控件的默認搜索範圍。這可以通過選擇網站操作>網站設置>網站收集管理|搜索範圍,然後點擊「顯示組:搜索下拉框」鏈接(注意這可能需要幾分鐘才能生效)。

如果你想你可以使用類似的功能,下面的一個代表控件的默認控制覆蓋其他屬性:

<?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"/>