Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. Show all posts

Thursday, December 29, 2011

Adding XSL to a SharePoint Visual Studio Solution

When working with custom SharePoint search results web parts, inheriting from CoreResultsWebpart you’ll often use XSL to transform the search results display (this is not limited to this type of web part, you can use for list views too).  You could deploy the web part and configure the XSL after deployment or you could include the link to your XSL in your web part and package the XSL with your Visual Studio 2010 project.  To do the latter, from your Visual Studio Project, right click the name of the project in the Solution Explorer pane, select Add, and select SharePoint Mapped Folder.

image

In resulting window, select the folder at path Template\LAYOUTS\XSL to map.  Once mapped, I suggest adding a custom folder so it’s clear that this is custom XSL and then either upload your existing *.xsl file or create a new one and add your XSL (Side Note, SharePoint Designer does a great job of generating XSL based on any sample XML).

image

In the inherited class’ ConfigureDataSourceProperties set the XslLink property to the path of the XSL in the hive (“/_layouts/xsl/xyzcustom” in this case).

protected override void ConfigureDataSourceProperties()
{
...
this.XslLink = "/_layouts/xsl/xyzcustom/mmsearch.xsl";

....

Now, wherever you deploy the web part and add to a page, it will use your custom XSL.

Using this method, the XSL can not be overridden, If you want to overide after adding the web part, instead add to your web part's properties like this.



<?xml version="1.0" encoding="utf-8"?>
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="XYZSearchBuilder, $SharePoint.Project.AssemblyFullName$" />
<importErrorMessage>$Resources:core,ImportErrorMessage;</importErrorMessage>
</metaData>
<data>
<properties>
<property name="Title" type="string">My Core Search Results</property>
<property name="Description" type="string">Inherits from Core Results Web Part. This web part provides a fixed query builder configuration to set keyword values to provide results containg the currently logged in user. The web part also provides configuration to sort results by a managed property (reduce storage may need to be set).</property>
<property name="XslLink" type="string">/_layouts/xsl/xyzcustom/xyzsearch.xsl</property>
</properties>
</data>
</webPart>
</webParts>

Wednesday, January 19, 2011

SharePoint 2010 Acknowledgment Solution

Visual studio 2010 code here (code download) for a SharePoint 2010 Acknowledgement Solution.

Solution deploys an acknowledgement page using HTTP module to check SharePoint 2010 user profile every time user goes to site and presents users with acknowledgement page they must accept prior to accessing site.

It requires you add a new User Profile field named XYZACKNOW which the solution updates to capture that the user accepted.

Check out the featureactivated events to see how solution updates your web.config.

Includes web application scoped feature to deploy httpmodule and site collection scoped feature to deploy the aspx page which contains CEWP where you can put your own disclaimer – note: page has css inline to hide the SP 2010 ribbon bar and other components same way new modal dialog windows hide page components.

Hopefully code is self-explanatory.