本例将展示创建并部署一个显示于网站页面上的搜索框控件的替代控件的基本过程。该替代控件指定了一个不同的图片文件用于在搜索框右侧。
步骤
-
通过拷贝默认的 /TEMPLATE/FEATURES/ContentLightup文件夹,在 Local_Drive
:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/FEATURES
下创建一个名为 NewSearchBox 的文件夹。
XML<? 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 > -
在 NewSearchBox 文件夹中,修改已有的 Feature.xml 文件,通过运行 guidgen.exe (位于 Local_Drive:/
Program Files/Microsoft Visual Studio 8/Common7/Tools
)来生成新的GUID。 - 在Controls子文件中,修改searcharea.xml文件,它引用了一个可替换的.ascx文件,如下。
XML
<? 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 > -
在
/TEMPLATE/CONTROLTEMPLATES下,
拷贝SearchArea.ascx 文件 , 并重命名拷贝得到的文件为mySearchArea.ascx。 - 在您拷贝得到的.ascx文件末尾,找到<img>标签,修改其src属性指向替换后的图片文件。为了测试,您可以使用安装在
/TEMPLATE/IMAGES
下的默认图片文件,下面的例子中,简单的用FOLDER.GIF替换了原来的gosearch.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>
</span >
</ nobr > -
在命令行中,输入下列命令来安装并在特定子网站上激活该Feature。
a. stsadm -o installfeature -filename NewSearchBox/feature.xml
b. stsadm -o activatefeature -filename NewSearchBox/feature.xml -url http://Server/Site/Subsite - 导航到该子网站中来查看对搜索框右侧图片的变更。