<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>entwicklungsgedanken &#187; cqwp</title>
	<atom:link href="http://www.entwicklungsgedanken.de/tag/cqwp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.entwicklungsgedanken.de</link>
	<description>Verschiedene Gedanken rund um die Softwareentwicklung</description>
	<lastBuildDate>Mon, 09 Jan 2012 14:47:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Add the icon (DocIcon) of the file-type to a custom xsl-template when using the ContentByQueryWebPart (CQWP)</title>
		<link>http://www.entwicklungsgedanken.de/2008/05/18/add-the-icon-of-the-file-type-to-a-custom-xsl-template-when-using-the-contentbyquerywebpart-cqwp/</link>
		<comments>http://www.entwicklungsgedanken.de/2008/05/18/add-the-icon-of-the-file-type-to-a-custom-xsl-template-when-using-the-contentbyquerywebpart-cqwp/#comments</comments>
		<pubDate>Sun, 18 May 2008 14:12:24 +0000</pubDate>
		<dc:creator>Eric Bartels</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePoint-Development]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[cqwp]]></category>
		<category><![CDATA[DocIcon]]></category>
		<category><![CDATA[FileType]]></category>
		<category><![CDATA[Icon]]></category>
		<category><![CDATA[MapToIcon]]></category>

		<guid isPermaLink="false">http://www.entwicklungsgedanken.de/?p=45</guid>
		<description><![CDATA[In one of my current projects it was required to show the recent documents inside the site collection along with its associated icon. Of course our friend the ContentByQueryWebPart (CQWP) comes in.But how do I get the icon of the document? The result Don&#8217;t do it again One could start to use a long list [...]]]></description>
			<content:encoded><![CDATA[<p>In one of my current projects it was required to show the recent documents inside the site collection along with its associated icon. Of course our friend the <code>ContentByQueryWebPart</code> (CQWP) comes in.<br /><strong>But how do I get the icon of the document?</strong></p>
<h3>The result</h3>
<p><img src="http://www.entwicklungsgedanken.de/wp-content/uploads/2008/05/cqwp-with-document-icon.png" alt="CQWP with the associated document icon" title="cqwp-with-document-icon" width="413" height="144" class="aligncenter size-full wp-image-46" /></p>
<h3>Don&#8217;t do it again</h3>
<p>One could start to use a long list inside an <code>xsl:choose</code> to fetch each extension&#8230; But why do a file-extension mapping again when this is already specified in <code>DOCICON.XML</code>?</p>
<h3>Give me my icon</h3>
<ol>
<li>Create your ContentByQueryWebPart (CQWP) and export it.</li>
<li>Export the webpart</li>
<li>Locate the <code>CommonViewFields</code>-property and change it from

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;CommonViewFields&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;string&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p> to</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;CommonViewFields&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;string&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>HTML_x0020_File_x0020_Type,Text;File_x0020_Type,Text<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</li>
<li>Edit the ItemStyle.xsl or even better create your own My_ItemsStyle.xsl and create a custom template which uses these new <code>ViewFields</code>.

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;TitleOnlyWithIcon&quot;</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;Row[@Style='TitleOnlyWithIcon']&quot;</span> <span style="color: #000066;">mode</span>=<span style="color: #ff0000;">&quot;itemstyle&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:variable</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SafeLinkUrl&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:call-template</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;OuterTemplate.GetSafeLink&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:with-param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;UrlColumnName&quot;</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;'LinkUrl'&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:call-template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:variable<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:variable</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;DisplayTitle&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:call-template</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;OuterTemplate.GetTitle&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:with-param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Title&quot;</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;@Title&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:with-param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;UrlColumnName&quot;</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;'LinkUrl'&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:call-template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:variable<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:variable</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;LinkTarget&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:if</span> <span style="color: #000066;">test</span>=<span style="color: #ff0000;">&quot;@OpenInNewWindow = 'True'&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>_blank<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:if<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:variable<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;item link-item&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #808080; font-style: italic;">&lt;!-- Here comes the icon --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;span</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;icon&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;img</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;/_layouts/images/{ddwrt:MapToIcon(string(@HTML_x005F_x0020_File_x005F_x0020_Type),string(@File_x005F_x0020_Type))}&quot;</span> <span style="color: #000066;">alt</span>=<span style="color: #ff0000;">&quot;{@DocIcon}&quot;</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;vertical-align: middle;margin-right:4px&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;{$SafeLinkUrl}&quot;</span> <span style="color: #000066;">target</span>=<span style="color: #ff0000;">&quot;{$LinkTarget}&quot;</span> <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;{@LinkToolTip}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;$DisplayTitle&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</li>
<li>Change the <code>ItemStyle</code>-property inside the webpart-definition to match your custom template. (<code>TitleOnlyWithIcon</code> in this case).</li>
<li>Import the webpart</li>
</ol>
<h3>Again there is some magic</h3>
<p>
If you refresh your page I&#8217;m sure you get an error. The magic here is to tell the xsl-stylesheet where to find the <code>MapToIcon</code>-function which resides inside the <code>ddwrt</code>-namespace.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">xmlns:ddwrt=&quot;http://schemas.microsoft.com/WebParts/v2/DataView/runtime&quot;</pre></div></div>

<p>
The <code>MapToIcon</code>-function does the mapping of the icon by taking the mapping-information from the <code>DOCICON.xml</code>. So even if your icon is not named like the SharePoint ones the icon will be found. My icon here was named <code>icon-pdf.gif</code> for the pdf-file.
</p>
<h3>Conclusion</h3>
<p>
The use of the <code>MapToIcon</code>-function is the best method to get the icons. No need for custom &#8220;<code>xsl:choose</code>-statements&#8221; or &#8220;<code>/_layouts/images/ic{@DocIcon}.gif</code>-hacks&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.entwicklungsgedanken.de/2008/05/18/add-the-icon-of-the-file-type-to-a-custom-xsl-template-when-using-the-contentbyquerywebpart-cqwp/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Problems with the ContentByQueryWebPart (CQWP) and its ItemXslLink-property</title>
		<link>http://www.entwicklungsgedanken.de/2008/04/08/problems-with-the-contentbyquerywebpart-cqwp-and-its-itemxsllink-property/</link>
		<comments>http://www.entwicklungsgedanken.de/2008/04/08/problems-with-the-contentbyquerywebpart-cqwp-and-its-itemxsllink-property/#comments</comments>
		<pubDate>Tue, 08 Apr 2008 19:12:59 +0000</pubDate>
		<dc:creator>Eric Bartels</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePoint-Development]]></category>
		<category><![CDATA[cqwp]]></category>
		<category><![CDATA[Exception]]></category>
		<category><![CDATA[HttpContext]]></category>
		<category><![CDATA[XslItemLink]]></category>

		<guid isPermaLink="false">http://www.entwicklungsgedanken.de/?p=41</guid>
		<description><![CDATA[If you ever tried to set the ItemXslLink (which is a normal property of the ContentByQueryWebPart) you will see that sometimes this simply doesn&#8217;t work. You get an exception! Object reference not set to an instance of an object Why? The CmsDataFormWebpart.MakeSiteRelativeUrl (which is called somewhere when setting this property) needs the HttpContext.Current which isn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>If you ever tried to set the <code>ItemXslLink</code> (which is a normal property of the <code>ContentByQueryWebPart</code>) you will see that sometimes this simply doesn&#8217;t work. You get an exception!</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">Object</span> reference not set to an instance of an <span style="color: #6666cc; font-weight: bold;">object</span></pre></div></div>

<h4>Why?</h4>
<p>The <code>CmsDataFormWebpart.MakeSiteRelativeUrl</code> (which is called somewhere when setting this property) needs the <code>HttpContext.Current</code> which isn&#8217;t available when using a <strong>console application</strong> or inside an <strong>event receiver</strong> (<a href="http://www.entwicklungsgedanken.de/2008/03/27/redirecting-from-newformaspx-to-dispformaspx-after-creating-a-new-item/">déjà vu!</a>).</p>
<h3>Solution</h3>
<p>Inside the <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3123533&#038;SiteID=1">MSDN-Forums</a> a user named <em>AlexUC</em> found a good workaround.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">==</span> HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    HttpRequest request <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HttpRequest <span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&quot;</span>, web<span style="color: #008000;">.</span><span style="color: #0000FF;">Url</span>, <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HttpContext <span style="color: #008000;">&#40;</span>request, <span style="color: #008000;">new</span> HttpResponse <span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> StringWriter <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Items</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;HttpHandlerSPWeb&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> web<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>
Perhaps this even works when one is inside an asynchronous-event inside an event receiver?! Perhaps one can redirect the user inside the <code>ItemAdded</code>-Method?!<br />
<strong>I will analyze this soon&#8230;</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.entwicklungsgedanken.de/2008/04/08/problems-with-the-contentbyquerywebpart-cqwp-and-its-itemxsllink-property/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

