Adding an additional search to the WSS search page

Now, I wrote this post ages ago, then hesitated in posting it, the reason is because it actually shows you how to do something that I generally don’t recommend. Before releasing it I was going to write this big long post about the way I think about customisation and SharePoint, I might still do it, but it ended up being bigger than the Internet, and I got bored, and it caused a “Blog Jam” and I never got around to finishing it. In addition to this, it also got overtaken by the release of  898631 , need I say more.

It may come back, we shall see.

Now, back to the point, I would not normally recommend touching ANYTHING in the “Layouts” folder, however, sometimes customers really need to have a feature. When I’ve been faced with this, I’ve done it providing I consider the impact minimal, but told them at great length that it’s a bad idea and warned of the impact of such changes (we all know them, service packs, supportability, etc). Finally, the other reason I feel ok about posting is that we (Microsoft) have published many articles to MSDN that include modifying pages in the “Layouts” folder, so, it’s not like I’m the first.

Anyway, while this is a pretty minor change, it’s still made at your own risk, and will most likely be overwritten by the application of service packs, hotfixes, natural disasters, etc.

———————– Post Starts here ————————

In a Windows SharePoint Services site that is “connected” to a portal you get the ability to send a search submitted on a team site to the portal:


Sometimes you may want to:
– Refine the search, for example restricting it to just a specific content source
– Add an extra one.

The below instructions will take you through how to do it.

1. Open the following file:
C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\<locale ID>\searchresults.aspx

2. Search for the following code section:
<asp:PlaceHolder Runat=”server” ID=”PanelPortalSearch”>

3. Look for it’s closing tag (ie. </asp:PlaceHolder>)and insert the following immediately above it:
   <td class=”ms-vb”>
     <IMG SRC=”/_layouts/images/blank.gif” width=3 height=1 alt=””><img src=”/_layouts/images/rect.gif” alt=””><IMG SRC=”/_layouts/images/blank.gif” width=4 height=1 alt=””>
     var searchTerm

     searchTerm = ‘<a href=”/search.aspx?s=test&k=’ + ‘<% SPEncode.WriteScriptEncode(Response, m_strSearchTerm); %>’ + ‘”>Search Portal</a>’;

4. Save and test.

The result should look something like this:


Now lets take a closer look at the code, because you are going to need to change it to suit:

Section A
   <td class=”ms-vb”>
     <IMG SRC=”/_layouts/images/blank.gif” width=3 height=1 alt=””><img src=”/_layouts/images/rect.gif” alt=””><IMG SRC=”/_layouts/images/blank.gif” width=4 height=1 alt=””>
This bit basically just creates a new row in the table for me to place the new search link, as well as formatting it exactly like the standard link.

Section B
     var searchTerm
This bit kicks off the script we are going to write to output the correct link for doing the search

Section C
     searchTerm = ‘<a href=”/search.aspx?s=test&k=’ + ‘<% SPEncode.WriteScriptEncode(Response, m_strSearchTerm); %>’ + ‘”>Search Portal</a>’;
This is the meaty bit.

The section in the first quotes (‘) sets up the URL to the Portal search.aspx page, in this case the portal is on the same virtual server as my team site, note that this may not be the case, and you may need to modify this. It also hardcodes a specific scope for me to perform my search within, in this case the scope is called “Test”, you may need to change this to suit. For a full list of parameters you can feed to the Search.ASPX page see the SDK, section titled: “Using GET on the Search Page”.

The next section in quotes (‘) pulls back the search term submitted to the page, this is actually executed server side, as indicated by the “<% %>” tags.

The final section in quotes (‘) is simply the text you want on your link.

Section D
This is just the Javascript function that writes the contents of the variable setup in section A into the browser.

Finally, you need to put it inside the <asp:PlaceHolder> so that your link is hidden on sites that are not connected to the Portal. So there you go, I will be the first to admit that I’m a pretty average Javascript coder, so you may have a better approach. Thats exactly what the comments are for, look forward to them.

Comments (3)

  1. Dan Bauhaus says:

    Or if you don’t want to code and maintain customizations, you can use Coveo Enterprise Search for SharePoint which does these features and dozens of other ones out of the box.


  2. 机票 says:

















































































































































































  3. 条形码 says:

    your site have a lot of issue,I will introduce to my good friends,Thx 🙂

    <a href="; target=_blank>条形码</a> <a href="; target=_blank>条形码新闻</a> <a href="; target=_blank>条形码</a> <a href="; target=_blank>条形码新闻</a> <a href="; target=_blank>条形码</a> <a href=";“>; target=_blank>条形码地图</a> <a href="; target=_blank>条码地图</a> <a href="; target=_blank>条形码地图</a> <a href="; target=_blank>条码地图</a> <a href="; target=_blank>条形码</a> <a href="; target=_blank>条码</a> <a href="; target=_blank>条形码方案</a> <A href=";“>; target=_blank>条形码地图1</A> <A href="; target=_blank>条形码地图2</A> <A href="; target=_blank>条形码地图3</A> <A href="; target=_blank>条形码地图4</A> <A href="; target=_blank>条形码地图5</A> <A href="; target=_blank>条形码地图6</A> <A href="; target=_blank>条形码地图7</A> <A href="; target=_blank>条形码地图8</A> <A href="; target=_blank>条形码地图9</A> <a href="; target=_blank>条码地图2</a> <a href="; target=_blank>条码地图3</a> <a href="; target=_blank>条码地图4</a> <a href="; target=_blank>条码打印机</a> <a href="; target=_blank>条码扫描仪</a> <a href="; target=_blank>条形码软件</a> <a href="; target=_blank>条码色带</a> <a href="; target=_blank>条码标签</a> <a href="; target=_blank>条码软件</a> <a href="; target=_blank>条码</a> <a href="; target=_blank>条形码方案</a> <a href="; target=_blank>条码打印机</a> <a href="; target=_blank>条码识读器</a> <a href="; target=_blank>条码识读器…</a>