<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><!--RSS generated by Windows SharePoint Services V3 RSS Generator on 7/11/2009 10:15:55 AM--><rss version="2.0">
  <channel>
    <title>Weblog Ton Stegeman [MVP]: Posts</title>
    <link>http://www.tonstegeman.com/Blog/Lists/Posts/AllPosts.aspx</link>
    <description>RSS feed for the Posts list.</description>
    <lastBuildDate>Sat, 11 Jul 2009 18:15:55 GMT</lastBuildDate>
    <generator>Windows SharePoint Services V3 RSS Generator</generator>
    <ttl>60</ttl>
    <image>
      <title>Weblog Ton Stegeman [MVP]: Posts</title>
      <url>/Blog/_layouts/images/homepage.gif</url>
      <link>http://www.tonstegeman.com/Blog/Lists/Posts/AllPosts.aspx</link>
    </image>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/tonstegeman" type="application/rss+xml" /><item>
      <title>SharePoint Filter web parts: using a context filter in a page layout</title>
      <link>http://www.tonstegeman.com/Blog/Lists/Posts/ViewPost.aspx?ID=114</link>
      <description><![CDATA[<div><b>Body:</b> <div class=ExternalClass2C9F6746E6684F7797532D2456BC6C40><p>For our e-office intranet I was working on a number of page layouts. In this page layout I wanted to use the out of the box Page Field Filter web part. After creating a new page using that page layout, the page crashed immediatly, showing the error message “<em><strong>An unexpected error has occurred</strong></em>”. After switching off customErrors in web.config, the error message was “<strong><em>The Hidden property cannot be set on Web Part 'g_8271d6f6_a902_4fa4_88ce_ca9ae1b0d463', since it is a standalone Web Part.</em></strong>”. </p> <p>Context filter web parts are not visible at runtime, the only show up when the page is in edit mode. The web parts are using the hidden property to hide themselves. The way this is done does not work when using the web part directly in a page layout, resulting in this error message. I decided to change the <a href="http://eoffice.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=21389">Page Column Filter web part</a> I released on CodePlex, to make this work.</p> <p>In this web part I created a new override of the <strong>Hidden</strong> property. If there is a web part zone in which the web part is used, it behaves normally. If there is no web part zone, the property always returns false to prevent the web part from throwing the error message above. Here’s the code:</p> <div><pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none">[Browsable(<span style="color:#0000ff">false</span>)]
<span style="color:#0000ff">public</span> <span style="color:#0000ff">override</span> <span style="color:#0000ff">bool</span> Hidden
{
    get
    {
        <span style="color:#0000ff">if</span> (<span style="color:#0000ff">base</span>.WebPartManager == <span style="color:#0000ff">null</span>)
        {
            <span style="color:#0000ff">return</span> <span style="color:#0000ff">base</span>.Hidden;
        }
        <span style="color:#0000ff">if</span> (<span style="color:#0000ff">this</span>.Zone == <span style="color:#0000ff">null</span>)
        {
            <span style="color:#0000ff">return</span> <span style="color:#0000ff">false</span>;
        }
        <span style="color:#0000ff">return</span> !<span style="color:#0000ff">base</span>.WebPartManager.DisplayMode.AllowPageDesign;
    }
    set
    {
        <span style="color:#0000ff">base</span>.Hidden = <span style="color:#0000ff">value</span>;
    }
}
</pre></div>
<p>Because our web part now returns false when used in a page layout, we need another way to hide the web part at runtime. To do this I also created another override of the Visible property. Here is the code:</p>
<div><pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none">[Browsable(<span style="color:#0000ff">false</span>)]
<span style="color:#0000ff">public</span> <span style="color:#0000ff">override</span> <span style="color:#0000ff">bool</span> Visible
{
    get
    {
        <span style="color:#0000ff">if</span> (<span style="color:#0000ff">base</span>.WebPartManager == <span style="color:#0000ff">null</span>)
        {
            <span style="color:#0000ff">return</span> <span style="color:#0000ff">base</span>.Visible;
        }
        <span style="color:#0000ff">if</span> (<span style="color:#0000ff">this</span>.Zone != <span style="color:#0000ff">null</span>)
        {
            <span style="color:#0000ff">return</span> <span style="color:#0000ff">true</span>;
        }
        <span style="color:#0000ff">return</span> <span style="color:#0000ff">base</span>.WebPartManager.DisplayMode.AllowPageDesign;
    }
    set
    {
        <span style="color:#0000ff">base</span>.Visible = <span style="color:#0000ff">value</span>;
    }
}
</pre></div>
<p>Please note that this code snippet always returns true if there is a web part zone. If you do not do this, your web part will throw an error when the web part is used in a web part zone (by adding it to the page through the web part gallery).</p>
<p>Now our context filter web part works as expected when used as a normal web part and when used in a page layout.</p></div></div>
<div><b>Published:</b> 5/22/2009 8:56 AM</div>
]]></description>
      <author>Ton Stegeman</author>
      <pubDate>Fri, 22 May 2009 16:56:06 GMT</pubDate>
      <guid isPermaLink="true">http://www.tonstegeman.com/Blog/Lists/Posts/ViewPost.aspx?ID=114</guid>
    </item>
    <item>
      <title>DevDays 2009: Ask the experts</title>
      <link>http://www.tonstegeman.com/Blog/Lists/Posts/ViewPost.aspx?ID=113</link>
      <description><![CDATA[<div><b>Body:</b> <div class=ExternalClass071B22D26CF34308A6DAD9464BD23632><p>Together with <a href="http://blog.mastykarz.nl/ask-the-expert-devdays-09/">Waldek</a>, I will be at the Dutch DevDays next week. We will both be in the Ask the Experts area trying to answer your SharePoint questions. So if you have any, please stop by and give us a hard time :-). Hope to see you there!</p> <p><a href="/blog/Lists/Posts/Attachments/113/image_2_19A324EA.png"><img title=image style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px" height=104 alt=image src="/blog/Lists/Posts/Attachments/113/image_thumb_19A324EA.png" width=244 border=0></a></p></div></div>
<div><b>Published:</b> 5/22/2009 8:45 AM</div>
<div><b>Attachments:</b> <a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/113/image_2_19A324EA.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/113/image_2_19A324EA.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/113/image_thumb_19A324EA.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/113/image_thumb_19A324EA.png</a><br><a href=""></a></div>
]]></description>
      <author>Ton Stegeman</author>
      <pubDate>Fri, 22 May 2009 16:44:35 GMT</pubDate>
      <guid isPermaLink="true">http://www.tonstegeman.com/Blog/Lists/Posts/ViewPost.aspx?ID=113</guid>
    </item>
    <item>
      <title>SharePoint fabulous 40: fixing the Board of Directors template</title>
      <link>http://www.tonstegeman.com/Blog/Lists/Posts/ViewPost.aspx?ID=112</link>
      <description><![CDATA[<div><b>Body:</b> <div class=ExternalClass2C3CCE3A134D47DA8D6427E80A961DFD><p>Today I was looking at the Board of Directors template, which is one of the <a href="http://www.microsoft.com/downloads/details.aspx?familyid=5807b5ef-57a1-47cb-8666-78c1363f127d&amp;displaylang=en&amp;Hash=GbJuelRy68fiLb2SKbsVt3yvO1kNG7mwOno1YCRF44N5g7dcbNMJ0n2QAqlK6uncybW7oP%2btMim6dZnexe9MEA%3d%3d">Windows SharePoint Services 3.0 Application Templates</a> (also known as the fabulous 40). This template contains an event calendar for board events. When you add a new board event to that list, a SharePoint Designer workflow creates a new Meeting minutes document. Another workflow adds a new discussion to the discussion board. The display form of the board event contains a number of DataForm web parts that show the content related to the board event, as is shown in the screenshot below:</p> <p><a href="/blog/Lists/Posts/Attachments/112/image_2_6B48D2AD.png"><img title=image style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px" height=235 alt=image src="/blog/Lists/Posts/Attachments/112/image_thumb_6B48D2AD.png" width=244 border=0></a> </p> <p>The list of discussion items shows the discussion item created by the SharePoint Designer “Create Discusion” workflow. The link however points to the details page (dispform.aspx) of the discussion item, instead of the page that shows the thread (flat.aspx or thread.aspx). Another problem is that this view always show 0 replies. This is because the discussion item is created using the “Create List Item” activity in the workflow. This way an item is added to the discussion board, but it is not a discussion. You can see that by navigating to the list and opening the item from the summary view. You are now also redirected to the dispform.aspx page and if you reply to the discussion, replies are added to the list as new items, instead of as a reply to the initial item. The screenshot below shows the issues:</p> <p><a href="/blog/Lists/Posts/Attachments/112/image_4_6B48D2AD.png"><img title=image style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px" height=239 alt=image src="/blog/Lists/Posts/Attachments/112/image_thumb_1_6B48D2AD.png" width=303 border=0></a> </p> <p>The idea of the workflow that creates a discussion item for every board event is nice, but it does not work properly. There are 2 ways to fix this. The nicest way is to create a new activity for SharePoint Designer workflows that creates a new discussion item and use that in de workflow. <a href="http://blogit.create.pt/blogs/ricardocosta/archive/2007/11/02/Custom-Action-for-Sharepoint-Designer.aspx">This blog post</a> by Ricardo Costa shows how to do that. Another option is to create a workflow in Visual Studio that creates a new discussion item using <em>SPUtility.CreateNewDiscussion</em>. Then you replace the out of the box <em>Create Discussion</em> workflow in your template. In both cases you will need to create the discussion item and link that to the meeting event (using the <em>Meeting</em> lookup field). Here is the code how to do that:</p> <div><pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"><span style="color:#0000ff">foreach</span> (SPList list <span style="color:#0000ff">in</span> workflowProperties.Web.Lists)
{
    <span style="color:#008000">// Check if this list is a discussion board.</span>
    <span style="color:#0000ff">if</span> (list.BaseTemplate == SPListTemplateType.DiscussionBoard)
    {
        <span style="color:#008000">// Start a new discussion on the title of the event.</span>
        SPListItem newDiscussion = SPUtility.CreateNewDiscussion(list.Items, workflowProperties.Item.Title);

        <span style="color:#008000">// Update the lookup field to the event, if the field is available.</span>
        <span style="color:#0000ff">if</span> (list.Fields.ContainsField(<span style="color:#006080">&quot;Meeting&quot;</span>))
        {
            newDiscussion[<span style="color:#006080">&quot;Meeting&quot;</span>] = workflowProperties.Item.ID;
        }

        <span style="color:#008000">// Update the discussion item.</span>
        newDiscussion.Update();

        <span style="color:#008000">// Just add a new discussion thread to the first discussion board found.</span>
        <span style="color:#0000ff">break</span>;
    }
}
</pre></div>
<p>Last thing you will need to do is to fix the link in the dataview web part. Instead of dispform.aspx, the item needs to point to either the flat.aspx or the threaded.aspx page. Open the dispform.aspx page of the Calendar list.</p>
<p>Search in the XSLT of the <em>Discussion</em> web part for the &lt;td&gt; that renders the hyperlink to the <em>dispform.aspx</em> page using the ID of the item. Replace that &lt;a&gt; with this code:</p>
<div><pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"><span style="color:#0000ff">&lt;</span><span style="color:#800000">a</span> <span style="color:#ff0000">href</span><span style="color:#0000ff">=&quot;../../Lists/Team%20Discussion/Threaded.aspx?RootFolder=Lists%2FTeam%20Discussion%2F{@Title}&quot;</span><span style="color:#0000ff">&gt;&lt;</span><span style="color:#800000">xsl:value-of</span> <span style="color:#ff0000">select</span><span style="color:#0000ff">=&quot;@Title&quot;</span> <span style="color:#0000ff">/&gt;&lt;/</span><span style="color:#800000">a</span><span style="color:#0000ff">&gt;</span></pre></div>
<p>That’s it, now the discussion board in the Board of Directors template works as it should.</p></div></div>
<div><b>Published:</b> 5/21/2009 3:11 AM</div>
<div><b>Attachments:</b> <a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/112/image_2_6B48D2AD.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/112/image_2_6B48D2AD.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/112/image_4_6B48D2AD.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/112/image_4_6B48D2AD.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/112/image_thumb_1_6B48D2AD.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/112/image_thumb_1_6B48D2AD.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/112/image_thumb_6B48D2AD.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/112/image_thumb_6B48D2AD.png</a><br><a href=""></a></div>
]]></description>
      <author>Ton Stegeman</author>
      <pubDate>Thu, 21 May 2009 11:11:19 GMT</pubDate>
      <guid isPermaLink="true">http://www.tonstegeman.com/Blog/Lists/Posts/ViewPost.aspx?ID=112</guid>
    </item>
  </channel>
</rss>
