Searching SharePoint Results from Windows Explorer using OSDX and Custom RSS File

Environment:

SharePoint 2013 Enterprise Search with Windows 7 Operating Systems

Introduction:

To understand what is a OSDX file and how to add an OSDX file as a search provider in Windows Explorer please refer the below links:

https://www.nothingbutsharepoint.com/sites/eusp/Pages/sharepoint-2010-search-locations-in-windows-7.aspx

http://technet.microsoft.com/en-us/library/ff899315(v=office.14).aspx

Problem:

When I use the OOB SharePoint RSS file to show the results in the windows explorer I was not able to map the custom managed properties to the windows attributes such as Summary,  thumbnail, etc.,

The OOB SharePoint RSS file located in the following location:

http://<Site>/_layouts/srchrss.aspx

Regarding this issue, when I approached some MVPs and Microsoft Windows Development team they replied that it is not possible to map the SharePoint managed properties with the windows explorer search result attributes.

Some of the articles are also explaining the same

http://msdn.microsoft.com/en-us/library/dd742951(v=VS.85).aspx

https://communities.netapp.com/blogs/TheSharePointGuy/2011/09/22/windows-7-sharepoint-search-connector

So what is the solution for this?

Solution:

Windows 7 is the first OS with the capability to use external search providers as federated search locations – and yes, this federated location can also be SharePoint!  In general, all search providers can be federated if it’s OpenSearch 1.0/1.1 compatible or, in other words, can provide the search results in RSS/Atom format.

So that means if I have to create my own RSS feeding file then my custom code should return the SharePoint search results in RSS/Atom format. So I started exploring what is the best way to get the search results. Then I found a interesting feature in SharePoint 2013 called “SharePoint 2013 Search REST API”. This new REST service is the best way to go in a variety of application scenarios. External Applications to SharePoint that require search functionality can also leverage this service as the endpoint for communication into the Search platform. The old search.asmx SOAP web service is marked as deprecated in SP2013, and the new Search REST service is the replacement.

Location of the Search Rest service

The Search REST service is located at the following URI: http://host/site/_api/search

See more about this from the below link

http://blogs.msdn.com/b/nadeemis/archive/2012/08/24/sharepoint-2013-search-rest-api.aspx

Using the above mentioned API I am supplying the keyword to the API and getting the XML output. From the XML output I am extracting the necessary XML Node values and populating the output in the format of RSS/Atom using the below code:

Front end Code

<%@ Page Language=”C#” AutoEventWireup=”true” CodeBehind=”SearchAppliedRSS.aspx.cs” Inherits=”SearchResultsRSS.Layouts.SearchResultsRSS.SearchAppliedRSS” ContentType=”text\xml” %>

<asp:Repeater ID=”ResultRSSRepeater” runat=”server”>

<HeaderTemplate>

<rss version=”2.0″>

<channel>

<title>Nucleus</title>

<link>Configure you site URL</link>

<description>

Nucleus Search Center Site.

</description>

</HeaderTemplate>

<ItemTemplate>

<item>

<title><%# RemoveIllegalCharacters(DataBinder.Eval(Container.DataItem, “Title”)) %></title>

<link>Item URL</link>

<description><%# RemoveIllegalCharacters(DataBinder.Eval(Container.DataItem, “Description”))%></description>

<category><%# RemoveIllegalCharacters(DataBinder.Eval(Container.DataItem, “Category”)) %></category>

<pubDate><%# RemoveIllegalCharacters(DataBinder.Eval(Container.DataItem, “LastModifiedTime”))%></pubDate>

<author><%# RemoveIllegalCharacters(DataBinder.Eval(Container.DataItem, “Author”))%></author>

</item>

</ItemTemplate>

<FooterTemplate>

</channel>

</rss>

</FooterTemplate>

</asp:Repeater>

Back end Code

protected void Page_Load(object sender, EventArgs e)

{

string keyword = Request.QueryString[“keyword”];

string query = “http://<Site Name>/_api/search/query?querytext='” + keyword + “‘&sourceid=’c9a51276-5b58-423c-88cb-a64297974cb4’&selectproperties=’Author,TCItemType,TCItemName,Description,LastModifiedTime'”;

WebRequest req = WebRequest.Create(query);

NetworkCredential myCred = new NetworkCredential(“<Admin Account User ID>”,”Password”,”Domain Name”);

req.Credentials = myCred;

WebResponse resp = req.GetResponse();

System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());

// process response..

XDocument oDataXML = XDocument.Load(sr, LoadOptions.None);

XNamespace atom = “http://www.w3.org/2005/Atom&#8221;;

XNamespace d = “http://schemas.microsoft.com/ado/2007/08/dataservices&#8221;;

XNamespace m = “http://schemas.microsoft.com/ado/2007/08/dataservices/metadata&#8221;;

List<XElement> items = oDataXML.Descendants(d + “query”)

.Elements(d + “PrimaryQueryResult”)

.Elements(d + “RelevantResults”)

.Elements(d + “Table”)

.Elements(d + “Rows”)

.Elements(d + “element”)

.ToList();

// Extracting the values from XML..

DataTable dt = new DataTable();

dt.Columns.Add(“Title”);

dt.Columns.Add(“Author”);

dt.Columns.Add(“Category”);

dt.Columns.Add(“Description”);

dt.Columns.Add(“LastModifiedTime”);

foreach (XElement item in items)

{

DataRow dr = dt.NewRow();

//XElement xItem = item.Element(d + “Cells”).Descendants(d + “Key”).First();

foreach (XElement xItem in item.Element(d + “Cells”).Descendants(d + “Key”))

{

if (xItem.Value == “TCItemName”)

{

dr[“Title”] = xItem.Parent.Element(d + “Value”).Value;

}

else if (xItem.Value == “Author”)

{

dr[“Author”] = xItem.Parent.Element(d + “Value”).Value;

}

else if (xItem.Value == “Description”)

{

dr[“Description”] = xItem.Parent.Element(d + “Value”).Value;

}

else if (xItem.Value == “LastModifiedTime”)

{

dr[“LastModifiedTime”] = xItem.Parent.Element(d + “Value”).Value;

}

dr[“Category”] = “Teamcenter Item”;

}

dt.Rows.Add(dr);

}

// data-bind to ListView..

ResultRSSRepeater.DataSource = dt;

ResultRSSRepeater.DataBind();

}

protected string RemoveIllegalCharacters(object input)

{

// cast the input to a string

string data = input.ToString();

// replace illegal characters in XML documents with their entity references

data = data.Replace(“&”, “&amp;”);

data = data.Replace(“\””, “&quot;”);

data = data.Replace(“‘”, “&apos;”);

data = data.Replace(“<“, “&lt;”);

data = data.Replace(“>”, “&gt;”);

return data;

}

Finally instead of configuring the SharePoint OOB search RSS file, I have configured the customized RSS Feed file which I have created using the above code in the OSDX file.

How to create RSS?

http://net.tutsplus.com/tutorials/asp-net/how-to-build-an-rss-feed-with-asp-net/

Now I am able to see the results with the format I have specified in the code. Please see the below screen:

search-result-in-we

Advertisements

About Joseph Velliah
As a SharePoint Developer my professional interests tend to be technical and SharePoint focused. I run a blog at "SP RIDER" where you can expect to read HOW TOs and scenarios that I run into during my day to day job. I hope my posts will give back a little to the community that is helped me.

Comments are closed.

%d bloggers like this: