Searching SharePoint through an IE8 Activity

Posted by Rik Hepworth on Thursday, March 6, 2008

IE8 Activities look cool. They’re almost like favlets from where I stand, but they offer a very simple way for users to access online services and pass simple parameters.

I decided I wanted to play, and we use SharePoint heavily here at Black Marble. The obvious thing to do was to create an activity which would allow the user to search for the selected text using SharePoint search.

Activities are defined through XML. Essentially, you give it a name, an icon and define the actions that can be performed. There are execute and preview actions, but the small preview window doesn’t really lend itself to SharePoint search (I tried!).

Here is the xml for our sharepoint search activity. Note that I’ve replaced our hostnames. I called this file SharePointSearch.xml

 <?xml version="1.0" encoding="UTF-8"?>
<openServiceDescription xmlns="http://www.microsoft.com/schemas/openservicedescription/1.0"\>
<homepageUrl>https://portal.blackmarble.co.uk</homepageUrl>
<display>
  <name>Find in Black Marble Portal</name>
  <icon>https://portal.blackmarble.co.uk/\_layouts/images/favicon.ico</icon> 
</display>
<activity category="find"\>
  <activityAction context="selection"\>
    <execute action="https://portal.blackmarble.co.uk/search/Pages/results.aspx"\>
      <parameter name="k" value\="{selection}" type="text" />
    </execute>
  </activityAction>
</activity>
</openServiceDescription>

So what does that lot do? Well most of it seems pretty self explanatory. The key to the activitiy is in the section which defines the custom action. That has a url which IE8 will call and a list of parameters into which information is passed. A simple search in SharePoint uses the ‘k’ parameter to pass in the search term, so I have set that here.

So now we have our file, how do we get it into the browser. Well, I copied the xml file into the LAYOUTS folder in the SharePoint installation folder on the hard disk of the server, which is reference via _layouts in a url. I then added a Content Editor web part onto one of my pages and pasted the code to add the action into the source view:

<p>Search Portal easily from IE8 with our custom activity.</p><button onclick="BLOCKED SCRIPTwindow.external.addService('/_layouts/SharePointSearch.xml')">Add Portal Search Activity</button>

This simply shows a short paragraph and a button. When the user clicks the button, IE8 asks whether it should install the activity and hey presto, a new menu item appears under ‘More Activities’ on the context menu. When I highlight text in my browser I can now quickly search our SharePoint for any relevant content.