Select Page

I maintain a collection of documents in a Microsoft SharePoint library for a client. I’ve also created a separate set of HTML web pages that contain links to these documents. These are a set of individual “vanilla” HTML pages in a tabbed structure.

Screen shot showing tabbed structure

Problem
The client wanted to be able search across all the tabs to find individual PDFs, Word docs, or PowerPoint files, so I thought it would make sense to use the search that’s built into SharePoint. But I didn’t know exactly how to connect the web pages to the SharePoint search engine.

Solution
It took some research, and I finally found an example for something else relating to SharePoint searches. The example used a form, so I teased it apart and added a form field to the web page. The next challenge I had was directing the SharePoint search engine to just look at my library of documents.

Details
Here is the form and a list of common parameters. Parameter s was the one I needed:
1 <form action="URL for SharePoint search results page" method="get">
2 <input name="k" type="text" />
3 <input name="Search" type="submit" value="Search" />
4 <input name="s" type="hidden" value="This Site" />
5 <input name="u" type="hidden" value="URL for SharePoint library" />
6 <!-- uncomment if you want to sort by date
7 <input name="v" type="radio" checked="checked" value="date" />Sort by date
8 -->
9 </form>

List of parameters
s = Scope of search. Values are: This Site, All Sites, People (This may depend on the drop down values available on your site)
u = URL of SharePoint site to search
v = Order by relevance or date. Default is relevance.
k = Search key (the search text being looked for)

Additional parameters that I found but didn’t need:
start = Page start

For example, on line 5 of the code above, the URL for SharePoint library is the page that has your SharePoint search on it. In my example, it is: http://moss.example.com/sites/Library/Docs/Documents

To find the URL for line 1, do a search from your SharePoint library, and use everything before the file extension. For example, after doing a search for “cow,” you will find your search results URL looks something like this: http://moss.example.com/sites/Library/Docs/_layouts/OSSSearchResults.aspx?k=cow&cs=This{a5bdf8d0011d37eacb4818f08a39964e49b498fda098284cc705f141d11fed72}20Site&u=http{a5bdf8d0011d37eacb4818f08a39964e49b498fda098284cc705f141d11fed72}3A{a5bdf8d0011d37eacb4818f08a39964e49b498fda098284cc705f141d11fed72}2F{a5bdf8d0011d37eacb4818f08a39964e49b498fda098284cc705f141d11fed72}2Fmoss.example.com{a5bdf8d0011d37eacb4818f08a39964e49b498fda098284cc705f141d11fed72}2Fsites{a5bdf8d0011d37eacb4818f08a39964e49b498fda098284cc705f141d11fed72}2FLibrary{a5bdf8d0011d37eacb4818f08a39964e49b498fda098284cc705f141d11fed72}2FDocs

Copy everything before the .aspx file extension to use as the URL for the search results in the form action attribute. The URL for SharePoint search results page would be: http://moss.example.com/sites/Library/Docs/_layouts/OSSSearchResults.aspx

The finished form is:
<form action="http://moss.example.com/sites/Library/Docs/_layouts/OSSSearchResults.aspx" method="get">
<input name="k" type="text" />
<input name="Search" type="submit" value="Search" />
<input name="s" type="hidden" value="This Site" />
<input name="u" type="hidden" value="http://moss.example.com/sites/Library/Docs/Documents" />
</form>

This approach is useful if you have created HTML pages separately for your SharePoint document repository and want to access the built-in search capabilities.