Tuesday, January 24, 2012

More... link in Content Query Webpart

Following requirements achieved  using content query web part with combination for XSL style sheet
1. More link to navigate all items
2. Add New item link to add new item and should open in a dialog window
3. Each item has to be hyperlinked and should open in a dialog window
Snapshot of final output
clip_image001

Implementation Details
Achieved by creating custom XSL template, and associated to Content Query web part
We can reuse this template with minor changes. Hope this template will save your time while implementing these kind of solutions
<xsl:template name="moreArticles" match="Row[@Style='moreArticles']" 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="LinkTarget">
<xsl:if test="@OpenInNewWindow = 'True'" >_blank</xsl:if>
</xsl:variable>
<div id="linkitem" class="item">
<xsl:if test="string-length($SafeImageUrl) != 0">
<div class="image-area-left">
<a href="{$SafeLinkUrl}" target="{$LinkTarget}">
<img class="image" src="{$SafeImageUrl}" alt="{@ImageUrlAltText}" />
</a>
</div>
</xsl:if>
<div class="item bullet link-item">
<xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/>
<!—following line of code for open item in dialog window-->
<a href="/departments/it/KnowledgeBase/_layouts/listform.aspx?PageType=4&amp;ListId={@ListId}&amp;ID={@ID}" onclick="EditLink2(this,ctx.ctxId);return false;" onfocus="OnLink(this)" target="_self">
<!--<a href="{$SafeLinkUrl}" target="{$LinkTarget}" title="{@LinkToolTip}">-->
<xsl:value-of select="$DisplayTitle"/>
</a>
<div class="description">
<xsl:value-of select="substring(@Description,1,200)" disable-output-escaping="yes" />
</div>
</div>
</div>
<xsl:if test="count(following-sibling::*)=0">
<div>
<!—following line of code for more link-->
<p align="right"><strong><a><xsl:attribute name="href">/departments/it/knowledgebase/pages/MoreArticles.aspx</xsl:attribute>More KB Articles...</a></strong></p>
<!—following line of code for Add New Item link-->
<p align="left"><img src="/PublishingImages/kbImages/addImg.png" alt=""/><strong><a><xsl:attribute name="onclick">javascript:NewItem2(event, &quot;/departments/it/knowledgebase/_layouts/listform.aspx?PageType=8&amp;ListId={8386e5d5-f918-4c9c-9e70-c39943dcbc70}&amp;RootFolder=&quot;);javascript:return false;</xsl:attribute> <xsl:attribute name="href">/departments/it/knowledgebase/_layouts/listform.aspx?PageType=8&amp;ListId={8386e5d5-f918-4c9c-9e70-c39943dcbc70}&amp;RootFolder=</xsl:attribute>Add New KB Article</a></strong></p>
</div>
</xsl:if>
</xsl:template>

Custom Site map provider


SharePoint provides global navigation display multiple level of navigation with some limitations

Scenario:
clip_image001
In the above screen Corporate is sub site. And IT, HR, Admin and Corporate Matter are the document libraries. We need one more level of menu with folders of each library.
We can’t achieve this scenario by increasing the StaticDisplayLevels to 2 in the Global navigation menu in the master page.
We take custom site map provider approach to achieve the functionality
1. Create notepad file and name it as CustomSiteMap.sitemap
2. Open the document create nodes like :
<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
<siteMapNode title="" url="">
<siteMapNode title="Corporate" url="/Pages/Corporate.aspx">
<siteMapNode title="IT" url="/Lists/IT/AllItems.aspx">
<siteMapNode title="Hydra" url="/Lists/HR/AllItems.aspx"/>
</siteMapNode>
<siteMapNode title="HR" url="/Lists/HR/AllItems.aspx"/>
<siteMapNode title="Admin" url="/Lists/admin/AllItems.aspx"/>
<siteMapNode title="Corporate Matters" url="/Lists/cormatter/AllItems.aspx"/>
</siteMapNode>
</siteMapNode>
</siteMap>

3. Save the file in 14hive/_Layouts/<CustomSiteProvider>/
4. Open targeted applications’ web.config file find for <providers> tag
5. Make this entry : <add name="CustomGlobalNavSiteMapProvider" siteMapFile="/_layouts/ CustomSiteProvider / CustomSiteMap.sitemap" type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
6. Save and close the web.config
7. Open targeted application master page in SP designer
8. Try to simulate following snippet
<SharePoint:AspMenu
ID="TopNavigationMenuV4"
Runat="server"
EnableViewState="false"
DataSourceID="topSiteMap"
AccessKey="<%$Resources:wss,navigation_accesskey%>"
UseSimpleRendering="true"
UseSeparateCss="false"
Orientation="Horizontal"
StaticDisplayLevels="1"
MaximumDynamicDisplayLevels="3"
SkipLinkText=""
CssClass="s4-tn" Width="1024px">
</SharePoint:AspMenu>
<SharePoint:DelegateControl runat="server" ControlId="CustomXmlContentMapProvide" Id="topNavigationDelegate">
<Template_Controls>
<asp:SiteMapDataSource
ShowStartingNode="False"
SiteMapProvider="CustomGlobalNavSiteMapProvider"
id="topSiteMap"
runat="server"/>
</Template_Controls>
</SharePoint:DelegateControl>

9. Publish the master page.
10. Browse the application, and we can see custom global navigation