Saturday, February 7, 2015

sandbox solutions are deprecated in SharePoint 2013 ?

This blog will talk about why and what exactly is deprecated for sandbox solution in SharePoint 2013

Why
Sandbox solution had many disadvantages and if we see our SharePoint 2010 development we hardly looked sandbox solution as solution for most of our requirements
Few disadvantages of sandbox solutions:
  1. Limited access to object model
  2. Learning curve to understand the sandbox architecture
  3. Not easy to create proxy for full trusted code.

What
Many blogs says sandbox solution are deprecated yes its true but not completely
Sandbox solution containing only declarative things (like Web Templates and Design )
are still supported and not deprecated and sandbox solutions containing code is deprecated.
so if your solution doesn’t have code…consider the sandbox as solution.

Custom itemstyle.xsl for Content Query Webpart in SharePoint

While using Content Query Web Part its always best practice to use custom Item Style so here we will see how to create new templates in itemxsl style and change the reference in .webpart to custom item xsl style
1. Navigate to Style library –> XSL style sheets –> Itemstyle.xsl
And download the local copy .
2. ItemStyle.xsl contains different templates e.g. Default, NoImage, TitleOnly, TitleWithbackground etc,So to create custom ItemStyle.xsl , save ItemStyle.xsl as CustomItemStyle.xsl . Delete all the templates and add the new template with different name say HRDocs
<xsl:stylesheet
version=”1.0″
exclude-result-prefixes=”x d xsl msxsl cmswrt”
xmlns:x=”http://www.w3.org/2001/XMLSchema”
xmlns:d=”http://schemas.microsoft.com/sharepoint/dsp”
xmlns:cmswrt=”http://schemas.microsoft.com/WebParts/v3/Publishing/runtime”
xmlns:xsl=”http://www.w3.org/1999/XSL/Transform” xmlns:msxsl=”urn:schemas-microsoft-com:xslt”>
<xsl:output method=”html”/>
<xsl:param name=”ItemsHaveStreams”>
<xsl:value-of select=”‘False’” />
</xsl:param>
<xsl:param name=”FeedTitle” />
<xsl:param name=”WPPropertyBinding-Title” />
<xsl:variable name=”OnClickTargetAttribute” select=”string(‘javascript:this.target=&quot;_blank&quot;’)” />
<xsl:variable name=”ImageWidth” />
<xsl:variable name=”ImageHeight” />
<xsl:template name=”HRDocs” match=”Row[@Style=HRDocs]” mode=”itemstyle”>
<xsl:variable name=”SafeLinkUrl”>
<xsl:call-template name=”OuterTemplate.GetSafeLink”>
<xsl:with-param name=”UrlColumnName” select=”‘LinkUrl’”/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name=”SafeImageUrl”>
<xsl:call-template name=”OuterTemplate.GetSafeStaticUrl”>
<xsl:with-param name=”UrlColumnName” select=”‘ImageUrl’”/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name=”DisplayTitle”>
<xsl:call-template name=”OuterTemplate.GetTitle”>
<xsl:with-param name=”Title” select=”@Title”/>
<xsl:with-param name=”UrlColumnName” select=”‘LinkUrl’”/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name=”LinkedInSafeImageUrl”>
<xsl:call-template name=”OuterTemplate.GetSafeLink”>
<xsl:with-param name=”UrlColumnName” select=”‘Linkedin’”/>
</xsl:call-template>
</xsl:variable>
<div>
<div>
<xsl:call-template name=”OuterTemplate.CallPresenceStatusIconTemplate”/> 
<div> 
<xsl:value-of select=”@documentname” />
</div>
<div>
<xsl:value-of select=”@docDescription” />
</div>
</div> </div> </xsl:template>
</xsl:stylesheet>
Things to take care while creating new template is to keep the same name for name and @style attributes( as below )
<xsl:template name=”HRDocs” match=”Row[@Style=HRDocs]“
and also add the <xsl:output method=”html”/> line  as added in above code to avoid the UI misalignement if any custom html is rendering null value.
3. Now upload this CustomItemStyle.xsl to same location ( Style Library –> XSL Style Sheets )
4. Now let’s make our CQWP to refer CustomItemStyle.xsl , open any page and add the CQWP and export the web part file which contains all the property tags , search for ItemXslLink
Which currently looks as
<property name=”ItemXslLink” type=”string”/>
Replace the above line with below
<property name=”ItemXslLink” type=”string”>/werkenbij/Style Library/XSL Style Sheets/CustomItemStyle.xsl</property>
Save the .webpart file as CustomCQWP.webpart and upload it to web part gallery [ Site Actions à Site Settings à Web parts (in Gallery)]
5. Add the web part on page , lets edit the web part to select the CustomItemStyle.xsl
Navigate to Presentation –>  Styles –>  Item Style and select CustomItemStyle.xsl from drop down.

That’s it guys your CQWP WITH CUSTOM Item style is ready to ship :)