Searching SharePoint through an IE8 Activity

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

   1: <?xml version=“1.0” encoding=“UTF-8”?>
   2:   <openServiceDescription xmlns=“http://www.microsoft.com/schemas/openservicedescription/1.0”>
   3:   <homepageUrl>https://portal.blackmarble.co.uk</homepageUrl>
   4:   <display>
   5:     <name>Find in Black Marble Portal</name>
   6:  <icon>https://portal.blackmarble.co.uk/_layouts/images/favicon.ico</icon>   
   7:   </display>
   8:   <activity category=“find”>
   9:   <activityAction context=“selection”>
  10:       <execute action=“https://portal.blackmarble.co.uk/search/Pages/results.aspx”>
  11:         <parameter name=“k” value=“{selection}” type=“text” />
  12:       </execute>
  13:     </activityAction>
  14:   </activity>
  15: </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:

   1: <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.

Leave a Reply

Your email address will not be published. Required fields are marked *