Tuesday, November 30, 2010

Workflow .rules File blocked in SharePoint

We were recently working on a project which stored the Workflow Rules File (with .rules extension) in a SharePoint Document Library. The code programmatically extracted the .rules file from the SharePoint document library and used it further for business logic.

The approach makes the rules configurable, and described here.

While the code worked in our older MOSS 2007/Win 2003 world, it failed on SharePoint 2010-Win 2008 environment. The error was thrown while trying to access the file through code as well as SharePoint document library UI.

Issue 1: It initially gave a HTTP 404 Not Found Error while trying to access the .rules file

Resolution: .rules extension is blocked by IIS 7. You need to dig IIS log files to realize that its 404.7 error. To resolve, we need to enable .rules extension for our Web App. You can do the same by

a) Using IIS Management Console (inetmgr), Select Web Site, Click ‘Request Filtering’ and remove .rules extension

b) Modify Web.Config using Notepad or Visual Studio and configure fileExtensions node under requestFiltering.

Issue 2: Once the HTTP 404 error is resolved, it throws SharePoint error.

Resolution: In IIS, .rules extension is mapped to System.ServiceModel.Activation.HttpHandler and other handlers.

Using IIS Management Console, select Handler Mappings, and remove the mapping for .rules extension to System.ServiceModel.Activation.HttpHandler

I need to evaluate the impact of removing the handler. To be safe, I have renamed .rules to a dummy value .rules1 so it’s easier to revert. You can also modify web.config handlers node if you are comfortable with same.

Our code is now working after the above changes and  team able to proceed.

Friday, November 19, 2010

Add Custom Category to Search Refinement Panel

Goal: Display a custom Category(Facet) called Classification in the SharePoint 2010 Search Refinment Panel.

Initial Steps: Configure your custom column as Managed Property in Central Admin Search Settings. Only Managed Proprites can be displayed under Refinement Panel.

I will not discuss how to create Managed Property in this blog, but focus on Refinement Panel.

Next Steps: You need to edit the Web Part and configure its XML to display the custom Category.

MSND provides description of the XML syntax:

The above link is not sufficent and there are few additional things you need to know.

Use Default Configuration: The Web Part has a propety "Use Default Configuration" which you need to uncheck.

Unless you uncheck, you Custom XML wont be applied, and a lot of teams miss this setting.

Filter Category Definition: This is the XML input for the Refinement Panel Web Part. I create a XML file in Visual Studio and use the same for editing.

You need to add your custom Category. I added as following to the XML:

<Category Title="Classification" Description="Document Classification" Type="Microsoft.Office.Server.Search.WebControls.ManagedPropertyFilterGenerator" MetadataThreshold="1" NumberOfFiltersToDisplay="4" MaxNumberOfFilters="20" SortBy="Frequency" SortByForMoreFilters="Name" SortDirection="Descending" SortDirectionForMoreFilters="Ascending" ShowMoreLink="True" MappedProperty="classification" MoreLinkText="show more" LessLinkText="show fewer" />

While most of the properties are self explantory and described in above MSDN article, I need to highlight a few.

MappedProperty: specifies Name of managed property. It is case sensitive and seemed to accept only lower case only. Though I called my managed property "Classification" with caps C, I had to set it to "classification" with lower c to make it work.

MetadataThreshhold: Specifies the minimum number of times the property should be present in Search Results to be considered important to be display.

I had very few docs in my dev environment, and my Custom Category will randomly show up. I have now set it to 1 and it displays as expected.

Enable Data View Caching: Performance Optimization option in web part, I had to uncheck it for my changes to be reflected. I have now checked it again and works fine.

Hope this helps others to save time in configuring the web part.

Tuesday, November 16, 2010

Search Results Customization RAW XML

You are trying to customizing the Search Core Results Web Part to display a custom column in Search Results. You have modifed the XSLT as expected, but dont get the desired column in the results. You need to verify that the column values are returned by Search Engine (Crawl + Index + Query) as expected. After all, Search Core Results Web Part is only applying XSLT transformation to the input (Search Results it recieves in XML format). If Column values are not returned by Search Engine, the Search Results Web part cant display the same in Search Results.

How do you verify the RAW XML. Well, you can apply the following XSLT to view the source XML (Dont forget to copy and backup the original XSLT to a notepad file, you will need the same to revert back).

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xmp><xsl:copy-of select="*"/></xmp>

If the required column is in RAW XML but not displayed in results, the problem is in your XSLT.
If the required column is missing in RAW XML, the problem is elsewhere. You need to validate if you have created Managed/MetaData Properties, Done a full or incremental crawl, modified the Search Core Results Web Part Fetched Properties and added the managed property to SelectedColumns.