Allen的自由天空

有财富未必有人生,有人生未必有财富

导航

Create a new sharepoint search control

This example shows the basic process of creating and implementing an alternate control for the search box that is displayed on site pages. The alternate control specifies a different image file to use next to the box.

To change the search box icon

  1. Create a folder in Local_Drive:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/FEATURES called NewSearchBox by copying the default \TEMPLATE\FEATURES\ContentLightup folder

    <?xml version="1.0" encoding="utf-8" ?>
        <Feature Id="GUID"
        Title="New Search Image"
        Description="Points at which third parties light up in content pages"
        Version="12.0.0.0"
        Scope="WebApplication"
        xmlns="http://schemas.microsoft.com/sharepoint/">
        <ElementManifests>
        <ElementManifest Location="controls\searcharea.xml" />
        </ElementManifests>
        </Feature>
  2. In the NewSearchBox folder, modify the existing Feature.xml file, generating a new GUID by running guidgen.exe located in Local_Drive:\Program Files\Microsoft Visual Studio 8\Common7\Tools.

  3. In the Controls subfolder included in the first step, modify the searcharea.xml file so that it references an alternate .ascx file such as the following.

    <?xml version="1.0" encoding="utf-8" ?>
        <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
        <Control
        Id="SmallSearchInputBox"
        Sequence="100"
        ControlSrc="~/_controltemplates/mySearchArea.ascx">
        <Property Name="SearchTextToolTip">Search this site</Property>
        <Property Name="SearchImageToolTip">Go</Property>
        </Control>
        </Elements>
  4. In \TEMPLATE\CONTROLTEMPLATES, copy the SearchArea.ascx file , and then rename this copied file mySearchArea.ascx.

  5. On the <img> tag located near the end of your copied .ascx file, modify the value of the src attribute to point to an alternate image file. For testing purposes, you can use one of the default image files installed in \TEMPLATE\IMAGES, such as in the following example, which simply replaces gosearch.gif with FOLDER.GIF.

    <INPUT Type=TEXT id='idSearchString' size=25 style='vertical-align: 2' name='SearchString' display='inline' maxlength=255 ACCESSKEY=S class='ms-searchbox' onKeyDown="return SearchKeyDown(event, <%=strEncodedUrl%>);" title=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SearchTextToolTip),Response.Output);%>>
        <IMG SRC="/_layouts/images/blank.gif" width=4 height=1 alt="">
        <a target='_self' href='javascript:' onClick="javascript:SubmitSearchRedirect(<%=strEncodedUrl%>);javascript:return false;" title=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SearchImageToolTip),Response.Output);%> ACCESSKEY=O ID=onetIDGoSearch>
        <img border='0' src="/_layouts/images/FOLDER.GIF" style='vertical-align: 1'alt=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SearchImageToolTip),Response.Output);%>></a>
        &nbsp;
        </span>
        </nobr>
  6. At a command prompt, type the following commands to install the feature in the deployment and activate the Feature on a specified subsite.

       a. stsadm -o installfeature -filename NewSearchBox\feature.xml
        b. stsadm -o activatefeature -filename NewSearchBox\feature.xml -url http://Server/Site/Subsite
  7. Navigate to the home page of the specified subsite to see the changes made to the search box.

posted on 2007-10-19 17:36  AllenFeng  阅读(481)  评论(0编辑  收藏  举报