2010-01-15 6 views
1

J'ai suivi cette http://msdn.microsoft.com/en-us/library/ms470880.aspx pour créer un contrôle de délégué pour dépasser la recherche par défaut utilisée dans Sharepoint. J'essaie de faire la recherche utiliser une portée de recherche personnalisée appelée personnes. Je ne semble pas capable de faire ça. Quelqu'un pourrait-il me donner quelques conseils?Commandes de délégué de recherche de point de partage

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 Entrez le texte ici 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" %> <%@ 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> 

Répondre

1

Pour modifier le champ de recherche par défaut, vous n'avez pas besoin de créer un contrôle de délégué. Cela peut être fait en sélectionnant Actions du site> Paramètres du site> Administration de la collection de sites | Recherchez les étendues et cliquez sur le lien "Afficher le groupe: Recherche Dropdown" (notez que cela peut prendre quelques minutes pour prendre effet).

Si vous souhaitez remplacer d'autres propriétés sur le contrôle par défaut, vous pouvez utiliser un contrôle délégué similaire à celui ci-dessous dans votre fonction:

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

Voir SearchBoxEx Members on MSDN pour plus d'informations sur les propriétés disponibles. Si cela ne correspond pas à vos besoins, vous pouvez placer un contrôle personnalisé dans le répertoire% Program Files% \ Common Files \ Microsoft Shared \ Extensions serveur Web \ 12 \ TEMPLATE \ CONTROLTEMPLATES et le charger à l'aide d'une fonctionnalité similaire. à celui-ci:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">   
<Control Id="SmallSearchInputBox" 
    Sequence="25" 
    ControlSrc="~/_ControlTemplates/MySearchControl.ascx"/>  
</Elements> 

Remarque vous devez également vous assurer que votre masterpage a la balise de contrôle de délégué approprié:

<SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox"/> 
Questions connexes