<?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>eCraft Labs - Microsoft Technologies at eCraft</title>
	<atom:link href="http://labs.ecraft.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://labs.ecraft.com</link>
	<description>Just another eCraft - We create less software. site</description>
	<lastBuildDate>Thu, 08 Sep 2011 12:25:41 +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>Assembly 2011 Summer</title>
		<link>http://labs.ecraft.com/2011/08/13/assembly-2011-summer/</link>
		<comments>http://labs.ecraft.com/2011/08/13/assembly-2011-summer/#comments</comments>
		<pubDate>Sat, 13 Aug 2011 13:12:50 +0000</pubDate>
		<dc:creator>Petteri Lehtonen</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Assembly]]></category>
		<guid isPermaLink="false">http://Assembly-2011-Summer</guid>
		<description><![CDATA[The Assembly demo party is a demoscene and gaming event in Finland. The most recent Assembly was held from the 4th to 7th August 2011 at Hartwall Areena in Helsinki. The first Assembly was held from July 24th to July 26th 1992, in Kauniainen. It was organized by the Amiga demo groups Complex and Rebels, [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Flabs.ecraft.com%2F2011%2F08%2F13%2Fassembly-2011-summer%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Flabs.ecraft.com%2F2011%2F08%2F13%2Fassembly-2011-summer%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>The Assembly demo party is a demoscene and gaming event in Finland. The most recent Assembly was held from the 4th to 7th August 2011 at Hartwall Areena in Helsinki.</p>
<p>The first Assembly was held from July 24th to July 26th 1992, in Kauniainen. It was organized by the Amiga demo groups Complex and Rebels, and the PC demo group Future Crew. The staff grew into a large non-profit group of individuals known as Assembly Organizing. Through the 1990s, Assembly grew so large that even exposition halls no longer sufficed, and only the largest of sports arenas met the partygoers&#8217; needs. In 1999 they rented the largest sports arena in the country, Hartwall Areena in Helsinki, with over 5000 visitors and 3500 computers on the ice rink and it has been held there ever since. As of 2011 the party has been held for 20 consecutive years.</p>
<p><span id="more-49"></span></p>
<p>Ever since becoming a Microsoft Student Partner in 2007 i have been helping out Microsoft to demonstrate it’s technologies for Assembly guests on the Microsoft stand. Assembly has always been great fun with interesting people so I decided to participate this year too. Microsoft also had a competition that  was giving away a free Windows Phone 7 to the best entry made on that platform that was participating on the Real Wild competition. I figured there wouldn&#8217;t be many entries like that so i decided to also participate. <img src='http://labs.ecraft.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I only had 4 hours to make my demo, so don&#8217;t expect anything spectacular (from which i was listening lectures for 2 hours).</p>
<p>Demos are basically a bunch of code put together that display graphics and music. Mine is called NeuralWorld and it&#8217;s a copy of a similar android screensaver, with some twists <img src='http://labs.ecraft.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . It works on both Silverlight on the web and Windows Phone and should you need it’s source code for something feel free to ask.</p>
<p>It starts with flashing squares and does it for 10 seconds I&#8217;m doing this with a DispatcherTimer ticking every on 100milliseconds and then randomly selecting 20 background items to flash on random colour. After it becomes 8 differently coloured worms running across the screen. I did this by having 8 different storyboards animating the worms. Every time a worm gets over the edge i randomly select a new starting point and begin the animation again. Lastly my demo ends with all backgrouditems dropping in from the sky. I ran into some serious performance issues while doing this and it seems that DispatcherTimer cannot tick as fast as i would want it to. For better results i should have probably used XNA. Finally to make it better i should have also added some music in it, but i couldn’t find anything that would fit <img src='http://labs.ecraft.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>At the end i missed the deadline for the competition with few hours so i couldn’t participate in it, but still learnt few things while doing it so there’s no reason to be disappointed. Here’s a video of the final demo!</p>
<div class="wlWriterEditableSmartContent" style="margin: 0px; float: none; padding: 0px;">
<div style="margin: 0px; padding: 0px;">
<div><a href="http://www.youtube.com/watch?v=8X-cFdnpPcY" target="_new"><img style="border-style: none;" src="http://labs.ecraft.com/Content/Assembly-2011-Summer_A6A4/video1d511f132126.jpg" alt="" /></a></div>
</div>
<div style="width: 625px; clear: both; font-size: .8em;">NeuralWorld</div>
</div>
<p>&nbsp;</p>
<h2></h2>
<p><span style="color: #000000;">PICTURES FROM THE EVENT</span></p>
<p><img style="padding-left: 0px; padding-right: 0px; padding-top: 0px; border-width: 0px;" src="http://labs.ecraft.com/Content/Assembly-2011-Summer_A6A4/assembly_lauantai_19.jpg" alt="assembly_lauantai_19" width="632" height="423" border="0" /></p>
<p>&nbsp;</p>
<p><span style="color: #000000;"><img style="padding-left: 0px; padding-right: 0px; padding-top: 0px; border-width: 0px;" src="http://labs.ecraft.com/Content/Assembly-2011-Summer_A6A4/3809.jpg" alt="3809" width="638" height="427" border="0" /></span></p>
<p>&nbsp;</p>
<p><span style="color: #000000;"><img style="padding-left: 0px; padding-right: 0px; padding-top: 0px; border-width: 0px;" src="http://labs.ecraft.com/Content/Assembly-2011-Summer_A6A4/_MG_5907-copy.jpg" alt="_MG_5907 copy" width="640" height="428" border="0" /></span></p>
<p><img style="padding-left: 0px; padding-right: 0px; padding-top: 0px; border-width: 0px;" src="http://labs.ecraft.com/Content/Assembly-2011-Summer_A6A4/_MG_5377-copy.jpg" alt="_MG_5377 copy" width="641" height="429" border="0" /></p>
<p><img style="padding-left: 0px; padding-right: 0px; padding-top: 0px; border-width: 0px;" src="http://labs.ecraft.com/Content/Assembly-2011-Summer_A6A4/assembly_torstai_12.jpg" alt="assembly_torstai_12" width="646" height="432" border="0" /></p>
<p><img style="padding-left: 0px; padding-right: 0px; padding-top: 0px; border-width: 0px;" src="http://labs.ecraft.com/Content/Assembly-2011-Summer_A6A4/assembly_torstai_24.jpg" alt="assembly_torstai_24" width="649" height="434" border="0" /></p>
<p><img style="padding-left: 0px; padding-right: 0px; padding-top: 0px; border-width: 0px;" src="http://labs.ecraft.com/Content/Assembly-2011-Summer_A6A4/DSC_7520.jpg" alt="DSC_7520" width="654" height="440" border="0" /></p>
<p><img style="padding-left: 0px; padding-right: 0px; padding-top: 0px; border-width: 0px;" src="http://labs.ecraft.com/Content/Assembly-2011-Summer_A6A4/DSC_7764.jpg" alt="DSC_7764" width="657" height="442" border="0" /></p>
<p><img style="padding-left: 0px; padding-right: 0px; padding-top: 0px; border-width: 0px;" src="http://labs.ecraft.com/Content/Assembly-2011-Summer_A6A4/DSC_7994.jpg" alt="DSC_7994" width="657" height="442" border="0" /></p>
<p><img style="padding-left: 0px; padding-right: 0px; padding-top: 0px; border-width: 0px;" src="http://labs.ecraft.com/Content/Assembly-2011-Summer_A6A4/DSC_7196.jpg" alt="DSC_7196" width="659" height="443" border="0" /></p>
<p><span style="color: #000000;">Loads more can be found from here:</span></p>
<p><a href="http://www.assembly.galleria.fi/kuvat/Assembly+Summer+2011/">http://www.assembly.galleria.fi/kuvat/Assembly+Summer+2011/</a></p>
<p>&nbsp;</p>
<p>Cheers,</p>
<p>Petteri Lehtonen</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.ecraft.com/2011/08/13/assembly-2011-summer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating an Epic Wedding Reception with Silverlight 4</title>
		<link>http://labs.ecraft.com/2011/07/31/creating-an-epic-wedding-reception-with-silverlight-4/</link>
		<comments>http://labs.ecraft.com/2011/07/31/creating-an-epic-wedding-reception-with-silverlight-4/#comments</comments>
		<pubDate>Sun, 31 Jul 2011 20:35:45 +0000</pubDate>
		<dc:creator>Petteri Lehtonen</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Silverlight]]></category>
		<guid isPermaLink="false">http://Creating-an-Epic-Wedding-Reception-with-Silverlight-4</guid>
		<description><![CDATA[This might no be very useful information when creating line of business applications, but I thought that it is cool enough that it’s worth sharing. It all started when my brother decided to get married and organize a party after the ceremony&#8230; you know the usual wedding stuff&#8230; As a best man i wanted to [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Flabs.ecraft.com%2F2011%2F07%2F31%2Fcreating-an-epic-wedding-reception-with-silverlight-4%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Flabs.ecraft.com%2F2011%2F07%2F31%2Fcreating-an-epic-wedding-reception-with-silverlight-4%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>This might no be very useful information when creating line of business applications, but I thought that it is cool enough that it’s worth sharing.</p>
<p>It all started when my brother decided to get married and organize a party after the ceremony&#8230; you know the usual wedding stuff&#8230; As a best man i wanted to do something to make this wedding stand out from the rest. Since i pretty much suck at everything not computer related so that&#8217;s what I had to go for. <img src='http://labs.ecraft.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><span id="more-28"></span></p>
<h3>Idea</h3>
<p>People will be arriving to the party after church and i wanted to provide them something to do while they are getting seated and waiting for others to arrive. (They are mainly regular Finnish people, so they are not yet drunk enough to actually talk to other people yet). So I&#8217;m going to automatically take pictures from people arriving to the party and project them on a wall to a virtual wedding album made with Silverlight.</p>
<h3>What do you need</h3>
<ul>
<li>Server laptop that&#8217;s taking the pictures and hosting them on IIS.</li>
<li>Client laptop that&#8217;s getting the images.</li>
<li>Webcam to take the pictures.</li>
<li>Router or a hub of some kind to create a network between these machines.</li>
<li>Bit of craziness to do something like this.</li>
</ul>
<h3>How to do it</h3>
<p>The Server laptop was a Macbook with Windows 7 and IIS configured with pretty much the default settings. Only thing i needed to change was some file rights for the client to be able to access the files. It  also needs some software to take the images from the Webcam periodically. I ended up using Yawcam, but i wouldn&#8217;t recommend it since it only allows you to take 640&#215;480 images even though my webcams max supported resolution was 1280&#215;800 (1.3MP). I set Yawcam to take images every 10 seconds and put them directly on the folder that was mapped to the IIS.</p>
<p>Client was also a Windows 7 laptop and i was running the Silverlight app directly from Visual Studio development server. For the wedding album i needed ready made control of a popular “Silverlight book implementation” and i found this <a title="http://www.rajneeshnoonia.com/blog/2011/06/page-flip-with-deep-zoom/" href="http://www.rajneeshnoonia.com/blog/2011/06/page-flip-with-deep-zoom/">http://www.rajneeshnoonia.com/blog/2011/06/page-flip-with-deep-zoom/</a> . There are better looking similar controls but this had a method for turning the page i could call programmatically, which was my only requirement. By default that control looks quite horrible so time for some Photoshop magic :).</p>
<h3>Steps</h3>
<ol>
<li>Make the huge shadows a lot smaller</li>
<li>Add some “weddingish” silk to the background</li>
<li>Make the pages look like a stylish paper</li>
<li>Start page with the lovely couple and some text to greet the guests</li>
<li>Another page to display the images from arriving guests</li>
</ol>
<p>And here’s how they ended up looking, first the page with the couple and the text’s i but this page to come up every once a while.</p>
<p><a href="http://labs.ecraft.com/Content/Creating-an-epic-wedding-reception-with-_11358/image.png"><img style="padding-left: 0px; padding-right: 0px; padding-top: 0px; border-width: 0px;" src="http://labs.ecraft.com/Content/Creating-an-epic-wedding-reception-with-_11358/image_thumb.png" alt="image" width="837" height="503" border="0" /></a></p>
<p>And the page to display images from guest’s. The content in them is created during runtime and you can browse trough the album like you would do on an regular photoalbum.</p>
<p><a href="http://labs.ecraft.com/Content/Creating-an-epic-wedding-reception-with-_11358/image_3.png"><img style="padding-left: 0px; padding-right: 0px; padding-top: 0px; border-width: 0px;" src="http://labs.ecraft.com/Content/Creating-an-epic-wedding-reception-with-_11358/image_thumb_3.png" alt="image" width="838" height="508" border="0" /></a></p>
<p>To add the chewing gum code to make it work i used an empty stroryboard that takes 20 seconds to complete and once it completes i get new images from the server and display them on the right position. There’s nothing fancy about the code, but here&#8217;s how to do one item:</p>
<pre class="brush: csharp; gutter: true">Storyboard sb = new Storyboard();
        int i = 0;
        public MainPage()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
            sb.Duration = new Duration(new TimeSpan(0, 0, 20));
           &nbsp;<a href="http://sb.Com" title="http://sb. " target="_blank">sb.Com</a>pleted += new EventHandler(sb_Completed);
        }
        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            sb.Begin();
        }
        void sb_Completed(object sender, EventArgs e)
        {
            //THE BACKGROUND FOR THE PAGE
            Image recr = new Image();
            BitmapImage bmi = new BitmapImage(new Uri("3 sivu.png", UriKind.Relative));
            recr.Source = bmi;
            //THE LIVE IMAGE FROM GUESTS MARGINS TAKEN FROM BACKGROUND IMAGE
            Image live1 = new Image();
            BitmapImage livebitmap = new BitmapImage(new Uri("http://10.0.1.150/" + i + ".jpg", UriKind.Absolute));
            live1.Source = livebitmap;
            live1.Stretch = Stretch.Fill;
            live1.Margin = new Thickness(27, 156, 26, 163);
            i++;
            Grid newchild = new Grid();
            newchild.Children.Add(recr);
            newchild.Children.Add(live1);
            BookItem newitem = new BookItem();
            newitem.Content = newchild;
            kirja.Items.Add(newitem);
            kirja.TurnPage(true);
            sb.Begin();
            }
        }</pre>
<p>All content to the book is created at runtime. The book control accepts a Grid as it’s BookItem&#8217;s content so i just created a grid and put my two images inside it. Every time the storyboard ends i start it again and add +1 to the index number so i always get new images from the webcam server. I set up YawCam to take images corresponding to this. My webcam server ended up taking approx. 1500 images from the wedding, in the 4~ hours it was running, and I’m hoping the guests had as much fun looking at them that I had creating this whole thing. <img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" src="http://labs.ecraft.com/Content/Creating-an-epic-wedding-reception-with-_11358/wlEmoticon-smile.png" alt="Iloiset kasvot" /></p>
<p>Should you have any questions i would be happy to answer them.</p>
<p>Cheers,</p>
<p>Petteri Lehtonen</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.ecraft.com/2011/07/31/creating-an-epic-wedding-reception-with-silverlight-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create Waterfall charts in QlikView</title>
		<link>http://labs.ecraft.com/2011/03/16/how-to-create-waterfall-charts-in-qlikview/</link>
		<comments>http://labs.ecraft.com/2011/03/16/how-to-create-waterfall-charts-in-qlikview/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 19:58:48 +0000</pubDate>
		<dc:creator>Niklas Lindman</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Charts]]></category>
		<category><![CDATA[QlikView]]></category>
		<category><![CDATA[Waterfall Chart]]></category>
		<guid isPermaLink="false">http://How-to-create-Waterfall-charts-in-QlikView</guid>
		<description><![CDATA[Every now and then customers want waterfall charts in our QlikView applications. As this is not a standard chart type in QlikView, it is not completely straightforward. This is how we have done it. The Source Data In this example, we will use this oversimplified source data. BU PrevYear CurrentYear ALL 369 388 BU1 62 [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Flabs.ecraft.com%2F2011%2F03%2F16%2Fhow-to-create-waterfall-charts-in-qlikview%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Flabs.ecraft.com%2F2011%2F03%2F16%2Fhow-to-create-waterfall-charts-in-qlikview%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Every now and then customers want <a title="Waterfall chart - Wikipedia" href="http://en.wikipedia.org/wiki/Waterfall_chart">waterfall charts</a> in our QlikView applications. As this is not a standard chart type in QlikView, it is not completely straightforward. This is how we have done it.</p>
<h3><span id="more-47"></span></h3>
<h3>The Source Data</h3>
<p>In this example, we will use this oversimplified source data.</p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="64">BU</td>
<td width="62">PrevYear</td>
<td width="81">CurrentYear</td>
</tr>
<tr>
<td>ALL</td>
<td>369</td>
<td>388</td>
</tr>
<tr>
<td>BU1</td>
<td>62</td>
<td>68</td>
</tr>
<tr>
<td>BU2</td>
<td>83</td>
<td>85</td>
</tr>
<tr>
<td>BU3</td>
<td>82</td>
<td>79</td>
</tr>
<tr>
<td>BU4</td>
<td>73</td>
<td>78</td>
</tr>
<tr>
<td>BU5</td>
<td>22</td>
<td>23</td>
</tr>
<tr>
<td>BU6</td>
<td>29</td>
<td>28</td>
</tr>
<tr>
<td>BU7</td>
<td>18</td>
<td>27</td>
</tr>
</tbody>
</table>
<p>It is as easy to use data with different years on different rows. However, in order to keep the expressions as readable as possible, we use this really simple data.</p>
<h3>The Waterfall Definition</h3>
<p>In this example, the waterfall dimensions are defined in Excel, in order to make it easier to modify them, even for users without any QlikView knowledge. A part of the Excel file looks like this:</p>
<table style="font-size: 8pt;" width="637" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="65">BU</td>
<td width="80">Waterfall1</td>
<td width="70">OrderBy</td>
<td width="140">WaterfallFormatting</td>
<td width="110">OffsetRowsBack</td>
<td width="80">ActMultiplier</td>
<td width="90">PrevMultiplier</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>ALL</td>
<td>Prev Year</td>
<td>0</td>
<td>Base</td>
<td>0</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<td>BU1</td>
<td>BU 1</td>
<td>1</td>
<td>RedGreen</td>
<td>1</td>
<td>1</td>
<td>-1</td>
</tr>
<tr>
<td>BU2</td>
<td>BU 2</td>
<td>2</td>
<td>RedGreen</td>
<td>2</td>
<td>1</td>
<td>-1</td>
</tr>
<tr>
<td>BU3</td>
<td>BU 3</td>
<td>3</td>
<td>RedGreen</td>
<td>3</td>
<td>1</td>
<td>-1</td>
</tr>
<tr>
<td>BU4</td>
<td>BU 4</td>
<td>4</td>
<td>RedGreen</td>
<td>4</td>
<td>1</td>
<td>-1</td>
</tr>
<tr>
<td>BU5</td>
<td>BU 5</td>
<td>5</td>
<td>RedGreen</td>
<td>5</td>
<td>1</td>
<td>-1</td>
</tr>
<tr>
<td>BU6</td>
<td>BU 6</td>
<td>6</td>
<td>RedGreen</td>
<td>6</td>
<td>1</td>
<td>-1</td>
</tr>
<tr>
<td>BU7</td>
<td>BU 7</td>
<td>7</td>
<td>RedGreen</td>
<td>7</td>
<td>1</td>
<td>-1</td>
</tr>
<tr>
<td>ALL</td>
<td>Curr Year</td>
<td>8</td>
<td>Base</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>The fields in this sheet are:</p>
<ul>
<li>BU
<ul>
<li>Defines the Business Units to be shown in the graph. In other words, this is the part that tells which data to show for each bar.</li>
</ul>
</li>
<li>Waterfall1
<ul>
<li>Used as a Dimension in the graph. The text in this field is shown as the dimension below the bars in the graph.</li>
</ul>
</li>
<li>OrderBy
<ul>
<li>The order in which the columns are shown in the graph.</li>
</ul>
</li>
<li>WaterfallFormatting
<ul>
<li>The color of the bar. RedGreen is used for bars that are red if the numbers are negative and green if the bars are positive. Other formatting can be applied here too, as long as it is defined in the graph in QlikView.</li>
</ul>
</li>
<li>OffsetRowsBack
<ul>
<li>The sum of the previous x rows are used as offset to get the starting point for the current bar. If this is 0, the bar will start from 0.</li>
</ul>
</li>
<li>ActMultiplier
<ul>
<li>The actual value of the account is multiplied by this value. In this example, the Act value is not taken into account in the “Plan” bar, as it is 0.</li>
</ul>
</li>
<li>PrevMultiplier
<ul>
<li>The Previous year’s value of the BU is multiplied by this value. In this example, the Previous year’s value is not taken into account in the “Act” bar, as it is 0. As we want to show the difference between Actual and Previous values, most PrevMultipliers here are -1, making the bar value Actual – Previous Year.</li>
</ul>
</li>
</ul>
<p>As you can see, every waterfall has a distinct column for defining the bars in the waterfall. If a new waterfall is added, just one new column needs to be added in this sheet.</p>
<h3>The Waterfall in QlikView</h3>
<p>In QlikView, the graph is created as a bar chart with offsets to make it a waterfall diagram.</p>
<h4>Dimensions</h4>
<p>On the dimensions tab, we use Waterfall1 as the dimension, as defined in the Excel file. As we may have multiple waterfalls defined in the same table, it is important that we check <em>Suppress When Value Is Null</em>. This is because we want to show the values for just this waterfall.</p>
<h4>Expressions</h4>
<p>On the Expression tab, there is just one expression, which looks like this:</p>
<pre>Sum(CurrentYear)*ActMultiplier
+
Sum(PrevYear)*PrevMultiplier</pre>
<p>This sums together the Actual value (considering the <em>ActMultiplier</em>), the Previous Year’s value (considering the <em>PrevMultiplier</em>).</p>
<h5>Offset</h5>
<p>The bar offset is defined as:</p>
<pre>rangesum (above(Column(1),1,only(OffsetRowsBack)))</pre>
<p>This sums the previous columns together, in order to define the starting point for the current column. In other words, this is the part that makes the chart a waterfall chart.</p>
<h5>Coloring</h5>
<p>The background color of the bar is defined as:</p>
<pre><span class="kwrd">if</span>(only(WaterfallFormatting)=<span class="rem">'Base',</span>
    Blue(),
    <span class="kwrd">if</span>(column(1) &lt;0,Red(),Green())
)</pre>
<p>Which makes the bar the selected color.</p>
<p>In this case, the final waterfall graph will look like this:</p>
<p><a href="http://labs.ecraft.com/Content/HowtomakeWaterfallgraphsinQlikView_FF84/Waterfall_3.png"><img style="border: 0px;" src="http://labs.ecraft.com/Content/HowtomakeWaterfallgraphsinQlikView_FF84/Waterfall_thumb_3.png" alt="Waterfall" width="450" height="272" border="0" /></a></p>
<p>The QlikView example file can be found <a href="/Content/downloads/WaterfallExample.qvw.zip">here</a> and the source data can be found <a href="/Content/downloads/WaterfallExampleSourceData.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.ecraft.com/2011/03/16/how-to-create-waterfall-charts-in-qlikview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More SharePoint Event Handler Gotchas</title>
		<link>http://labs.ecraft.com/2010/12/20/more-sharepoint-event-handler-gotchas/</link>
		<comments>http://labs.ecraft.com/2010/12/20/more-sharepoint-event-handler-gotchas/#comments</comments>
		<pubDate>Mon, 20 Dec 2010 17:02:51 +0000</pubDate>
		<dc:creator>Andreas Finne</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Gotcha]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<guid isPermaLink="false">http://More-SharePoint-Event-Handler-Gotchas</guid>
		<description><![CDATA[In a previous post, I wrote about a few gotchas that you may come across when doing event handlers in SharePoint. After writing that one, I&#8217;ve come across a few more. These are related to number fields. Gotcha number one, which is not that weird actually, but is good to know about, is that number [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Flabs.ecraft.com%2F2010%2F12%2F20%2Fmore-sharepoint-event-handler-gotchas%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Flabs.ecraft.com%2F2010%2F12%2F20%2Fmore-sharepoint-event-handler-gotchas%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>In a <a href="http://labs.ecraft.com/Blogs/SharePoint-Event-Handler-Gotchas">previous post</a>, I wrote about a few gotchas that you may come across when doing event handlers in SharePoint. After writing that one, I&#8217;ve come across a few more. These are related to number fields.</p>
<p>Gotcha number one, which is not that weird actually, but is good to know about, is that number columns are always stored as doubles. I had a column defined to include numbers from 0 and up, with zero decimals. The error occurred in my event handler, when I tried to do <span style="font-family: Consolas;">int.Parse(properties.AfterProperties[&lt;field name&gt;].ToString())</span>. This failed miserably. When inspecting the actual result of the <span style="font-family: Consolas;">.ToString()</span>, it turned out to be <span style="font-family: Consolas;">“1.000000000000”</span>, and not <span style="font-family: Consolas;">“1”</span>, as expected.</p>
<p>Gotcha number two, which is a bit stranger, turned up after I had found out about gotcha number one. Both <span style="font-family: Consolas;">properties.AfterProperties[&lt;field name&gt;]</span> and <span style="font-family: Consolas;">properties.ListItem[&lt;field name&gt;]</span> return <span style="font-family: Consolas;">object</span>s, BUT the underlying type for the <span style="font-family: Consolas;">AfterProperties</span> is <span style="font-family: Consolas;">string</span>, while the <span style="font-family: Consolas;">ListItem</span> properties are the real type, in this case double. So, the <span style="font-family: Consolas;">properties.ListItem[&lt;field name&gt;]</span> could be cast directly to a double, while the <span style="font-family: Consolas;">properties.AfterProperties[&lt;field name&gt;]</span> had to go through a <span style="font-family: Consolas;">double.Parse(properties.AfterProperties[&lt;field name&gt;] .ToString())</span>.</p>
<p>Well, that’s it for now. I have a few more “gotcha”-posts, and a couple of “did you know that”-posts waiting to be written, so stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.ecraft.com/2010/12/20/more-sharepoint-event-handler-gotchas/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>IPv4 address conversion for log reporting in TMG 2010</title>
		<link>http://labs.ecraft.com/2010/11/09/ipv4-address-conversion-for-log-reporting-in-tmg-2010/</link>
		<comments>http://labs.ecraft.com/2010/11/09/ipv4-address-conversion-for-log-reporting-in-tmg-2010/#comments</comments>
		<pubDate>Tue, 09 Nov 2010 13:27:15 +0000</pubDate>
		<dc:creator>alexosipov</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[IPv4]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[TMG 2010]]></category>
		<guid isPermaLink="false">http://IPv4-address-conversion-for-log-reporting-in-TMG-2010</guid>
		<description><![CDATA[Both ISA Server 2004/2006 and TMG 2010 can store logs in SQL Server (MSDE/Express Edition) which is recommended configuration. Unlike ISA Server which stores IP address as bigint type TMG 2010 stores them as GUIDs for IPv4 and IPv6 compatibility. So, a function is needed to see IPv4 addresses in easily readable way. CREATE FUNCTION [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Flabs.ecraft.com%2F2010%2F11%2F09%2Fipv4-address-conversion-for-log-reporting-in-tmg-2010%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Flabs.ecraft.com%2F2010%2F11%2F09%2Fipv4-address-conversion-for-log-reporting-in-tmg-2010%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Both ISA Server 2004/2006 and TMG 2010 can store logs in SQL Server (MSDE/Express Edition) which is recommended configuration.</p>
<p>Unlike ISA Server which stores IP address as bigint type TMG 2010 stores them as GUIDs for IPv4 and IPv6 compatibility.</p>
<p>So, a function is needed to see IPv4 addresses in easily readable way.</p>
<pre class="brush: sql; gutter: true">CREATE FUNCTION [dbo].[GuidToIPv4]
(
@guid VARCHAR(36)
)
RETURNS VARCHAR(15)
AS
BEGIN
 DECLARE @hex VARCHAR(8)
 SET @hex = LEFT(@guid, 8 )
 RETURN CONVERT(VARCHAR(3), sys.fn_replvarbintoint(sys.fn_cdc_hexstrtobin(LEFT(@hex, 2))), 0) + '.' +
  CONVERT(VARCHAR(3), sys.fn_replvarbintoint(sys.fn_cdc_hexstrtobin(SUBSTRING(@hex, 3, 2))), 0) + '.' +
  CONVERT(VARCHAR(3), sys.fn_replvarbintoint(sys.fn_cdc_hexstrtobin(SUBSTRING(@hex, 5, 2))), 0) + '.' +
  CONVERT(VARCHAR(3), sys.fn_replvarbintoint(sys.fn_cdc_hexstrtobin(RIGHT(@hex, 2))), 0)
END
GO</pre>
<p>Actually, IPv4 address forms a GUID where first 8 characters naturally make 4 bytes in hex &#8211; 1.1.1.1 makes 01010101-FFFF-0000-0000-000000000000 and 255.255.255.255 makes FFFFFFFF-FFFF-0000-0000-000000000000, so if you read hex fluently &#8211; here you go. <img src='http://labs.ecraft.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://labs.ecraft.com/2010/11/09/ipv4-address-conversion-for-log-reporting-in-tmg-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SharePoint Dispose Checker Tool</title>
		<link>http://labs.ecraft.com/2010/09/09/sharepoint-dispose-checker-tool/</link>
		<comments>http://labs.ecraft.com/2010/09/09/sharepoint-dispose-checker-tool/#comments</comments>
		<pubDate>Thu, 09 Sep 2010 13:42:38 +0000</pubDate>
		<dc:creator>Andreas Finne</dc:creator>
				<category><![CDATA[Apps]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[Tools]]></category>
		<guid isPermaLink="false">http://SharePoint-Dispose-Checker-Tool</guid>
		<description><![CDATA[When using the SharePoint object model, it is important to properly dispose of instantiated objects of certain classes to avoid memory leaks. The most common objects that need to be disposed are SPSite and SPWeb. However, there are certain situations where it is not obvious that an instance is even created. The SharePoint Dispose Checker [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Flabs.ecraft.com%2F2010%2F09%2F09%2Fsharepoint-dispose-checker-tool%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Flabs.ecraft.com%2F2010%2F09%2F09%2Fsharepoint-dispose-checker-tool%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>When using the SharePoint object model, it is important to properly dispose of instantiated objects of certain classes to avoid memory leaks. The most common objects that need to be disposed are SPSite and SPWeb. However, there are certain situations where it is not obvious that an instance is even created.</p>
<p>The SharePoint Dispose Checker Tool checks your assemblies against the dispose patterns listed in <a href="http://blogs.msdn.com/b/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx">Roger Lamb’s SharePoint Developer Blog</a> to check whether any of the patterns are in your code without being disposed.</p>
<p>The tool is run from the command prompt with your assembly as argument, or alternatively, a path to a folder containing several assemblies. If the PDB-files are in the same folder, the output will include additional source information about the problems detected.</p>
<p>Check it out at <a href="http://code.msdn.microsoft.com/SPDisposeCheck">http://code.msdn.microsoft.com/SPDisposeCheck</a></p>
]]></content:encoded>
			<wfw:commentRss>http://labs.ecraft.com/2010/09/09/sharepoint-dispose-checker-tool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SharePoint: Run with elevated privileges</title>
		<link>http://labs.ecraft.com/2010/06/22/sharepoint-run-with-elevated-privileges/</link>
		<comments>http://labs.ecraft.com/2010/06/22/sharepoint-run-with-elevated-privileges/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 10:06:55 +0000</pubDate>
		<dc:creator>Andreas Finne</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<guid isPermaLink="false">http://SharePoint-Run-with-elevated-privileges</guid>
		<description><![CDATA[When developing using the SharePoint object model, certain operations has to be run with elevated privileges. For instance, setting information into the property bag of a site needs to be done with elevated privileges. This post shows how this is done, and also includes a helper method for making it easier and shorter to do [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Flabs.ecraft.com%2F2010%2F06%2F22%2Fsharepoint-run-with-elevated-privileges%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Flabs.ecraft.com%2F2010%2F06%2F22%2Fsharepoint-run-with-elevated-privileges%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>When developing using the SharePoint object model, certain operations has to be run with elevated privileges. For instance, setting information into the property bag of a site needs to be done with elevated privileges. This post shows how this is done, and also includes a helper method for making it easier and shorter to do this.</p>
<p>There is a method called <span style="font-family: Consolas;"><strong>SPSecurity.RunWithElevatedPrivileges</strong></span> in the object model that takes a delegate as argument. The delegate is then run with more permissions. An important note regarding this: You must not use old references to <span style="font-family: Consolas;"><strong>SPWeb</strong></span> or <span style="font-family: Consolas;"><strong>SPSite</strong></span> instances inside your delegate, since they are “contaminated” with lower permissions. What you have to do is to create new <span style="font-family: Consolas;"><strong>SPSite</strong></span> and <span style="font-family: Consolas;"><strong>SPWeb</strong></span> instances using the Ids of the sites and webs you already have a reference to, like this:</p>
<pre class="brush: csharp; gutter: true">SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (SPSite site = new SPSite(SPContext.Current.Site.ID))
    {
        using (SPWeb elevatedWeb = site.OpenWeb(webId))
        {
            //Your code here
        }
    }
});</pre>
<p>If you need to do these kind of operations in several locations, this is a lot of repeating code to include. A colleague of mine made a small helper method that does the setup for elevated privileges for you. Here’s the short code snippet:</p>
<pre class="brush: csharp; gutter: true">private delegate void CodeToRunElevated(SPWeb elevatedWeb);
private static void RunElevated(Guid webId, CodeToRunElevated secureCode)
{
    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
        using (SPSite site = new SPSite(SPContext.Current.Site.ID))
        {
            using (SPWeb elevatedWeb = site.OpenWeb(webId))
            {
               secureCode(elevatedWeb);
            }
        }
    });
}</pre>
<p>To invoke this, you call on the method with the Id of your web as one argument, and a delegate taking an <span style="font-family: Consolas;"><strong>SPWeb</strong></span> as the other. When the method is invoked, the <strong><span style="font-family: Consolas;">SPWeb</span></strong> argument will be “uncontaminated” and pushed to elevated privileges. This example sets the name, title, and description of a site.</p>
<pre class="brush: csharp; gutter: true">RunElevated(web.ID, delegate(SPWeb elevatedWeb)
{
   &nbsp;<a href="http://elevatedWeb.Name" title="http://elevatedWeb. " target="_blank">elevatedWeb.Name</a> = siteTitle;
    elevatedWeb.Title = siteTitle;
    elevatedWeb.Description = siteDescription;
    elevatedWeb.Update();
});</pre>
]]></content:encoded>
			<wfw:commentRss>http://labs.ecraft.com/2010/06/22/sharepoint-run-with-elevated-privileges/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>We’re hiring in Vaasa</title>
		<link>http://labs.ecraft.com/2010/06/17/we%e2%80%99re-hiring-in-vaasa/</link>
		<comments>http://labs.ecraft.com/2010/06/17/we%e2%80%99re-hiring-in-vaasa/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 15:46:08 +0000</pubDate>
		<dc:creator>jorgen westerling</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[developers]]></category>
		<category><![CDATA[jobs]]></category>
		<category><![CDATA[Vaasa]]></category>
		<guid isPermaLink="false">http://Were-hiring-in-Vaasa</guid>
		<description><![CDATA[We have been on the quiet side on the blog lately, but fortunately that’s because we’ve been super busy with customer work. This means we need more dev muscle. Sorry for spamming the blog with a recruitment plug, but if you are a guru dev looking for a change of scenery in the Vaasa region, [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Flabs.ecraft.com%2F2010%2F06%2F17%2Fwe%25e2%2580%2599re-hiring-in-vaasa%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Flabs.ecraft.com%2F2010%2F06%2F17%2Fwe%25e2%2580%2599re-hiring-in-vaasa%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>We have been on the quiet side on the blog lately, but fortunately that’s because we’ve been super busy with customer work. This means we need more dev muscle.</p>
<p>Sorry for spamming the blog with a recruitment plug, but if you are a guru dev looking for a change of scenery in the Vaasa region, have a look at our job posting on our <a href="http://ecraft.com/en/get-a-job/software-guru-to-vaasa/" target="_blank">main web site here</a>. Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.ecraft.com/2010/06/17/we%e2%80%99re-hiring-in-vaasa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SharePoint Event Handler Gotchas</title>
		<link>http://labs.ecraft.com/2010/04/21/sharepoint-event-handler-gotchas/</link>
		<comments>http://labs.ecraft.com/2010/04/21/sharepoint-event-handler-gotchas/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 14:13:40 +0000</pubDate>
		<dc:creator>Andreas Finne</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Gotcha]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<guid isPermaLink="false">http://SharePoint-Event-Handler-Gotchas</guid>
		<description><![CDATA[In a previous SharePoint project, I implemented a few event handlers that get called whenever an item in a list gets changed (or added/deleted). There were a few problems along the way that took a bit of searching before I found solutions. This post documents a few of the things that are good to know. [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Flabs.ecraft.com%2F2010%2F04%2F21%2Fsharepoint-event-handler-gotchas%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Flabs.ecraft.com%2F2010%2F04%2F21%2Fsharepoint-event-handler-gotchas%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>In a previous SharePoint project, I implemented a few event handlers that get called whenever an item in a list gets changed (or added/deleted). There were a few problems along the way that took a bit of searching before I found solutions. This post documents a few of the things that are good to know.</p>
<p><span id="more-10"></span></p>
<p>The event handlers that I implemented where all of the synchronous <span style="font-family: Consolas;">ItemUpdating</span> kind. There are also asynchronous events, like for instance <span style="font-family: Consolas;">ItemUpdated</span>, but for the scenario at hand, I wanted to have some special handling depending on certain values of an item.</p>
<p>The event handler is of the form</p>
<pre class="brush: csharp; gutter: true">public override void ItemUpdating(SPItemEventProperties properties)</pre>
<p>The <span style="font-family: Consolas;">properties</span> object contains the collections <span style="font-family: Consolas;">BeforeProperties</span> and <span style="font-family: Consolas;">AfterProperties</span> that helps you to find out what has changed for your item,  i.e. compare<br />
<span style="font-family: Consolas;">properties.BeforeProperties[&lt;field name&gt;].ToString()</span> to<br />
<span style="font-family: Consolas;">properties.AfterProperties[&lt;field name&gt;].ToString()</span>. You can also modify the value of the fields in <span style="font-family: Consolas;">AfterProperties</span> to affect what is actually stored in the list.</p>
<p>Here comes the first gotcha; the <span style="font-family: Consolas;">BeforeProperties</span> are only populated for document libraries. If you have an event handler on a custom list, the <span style="font-family: Consolas;">BeforeProperties</span> collection is empty. So in order to check the current value of a field, you have to use <span style="font-family: Consolas;">properties.ListItem[&lt;field name&gt;]</span> instead.</p>
<p>Second gotcha; be aware of the internal name of fields. They have a sneaky behaviour in this case. As usual you should use the internal name of the field instead of the display name when accessing the field, i.e. <span style="font-family: Consolas;">“Evaluation_x0020_Date”</span> instead of <span style="font-family: Consolas;">“Evaluation Date”</span>. However, you can do <span style="font-family: Consolas;">properties.ListItem[“Evaluation Date”]</span> to get the current value of the field, BUT to get the new value from <span style="font-family: Consolas;">AfterProperties</span>, you have to do <span style="font-family: Consolas;">properties.AfterProperties[“Evaluation_x0020_Date”]</span>. Here comes the even sneakier behaviour; if you try to do <span style="font-family: Consolas;">properties.AfterProperties[“Evaluation Date”]</span>, it doesn’t fail, but returns null. Usually, if you try to access a field that does not exist, an exception is thrown. However, “Evaluation Date” passes as a valid field name, but the value cannot be found.</p>
<p>The third problem I had was related to date fields. In my event handler, I wanted to make sure that a certain date field remained unchanged if some other condition was met. The easiest solution would of course be</p>
<p><span class="Apple-style-span" style="font-family: Consolas, Monaco, monospace; font-size: 12px; line-height: 18px; white-space: pre;">properties.AfterProperties[“Decision Date”] = properties.BeforeProperties[“Decision Date”]</span></p>
<p>As already stated in the first gotcha, the <span style="font-family: Consolas;">BeforeProperties</span> is not populated for lists, so the statement was revised to</p>
<p><span class="Apple-style-span" style="font-family: Consolas, Monaco, monospace; font-size: 12px; line-height: 18px; white-space: pre;">properties.AfterProperties[“Decision Date”] = properties.ListItem[“Decision Date”]</span></p>
<p>Now, this is still too simple, if you read the gotcha number two, you know that we have to use the internal name. Taking this into account, the third revision of the line is</p>
<pre class="brush: csharp; gutter: true">properties.AfterProperties[“Decision_x0020_Date”] = properties.ListItem[“Decision_x0020_Date”]</pre>
<p>This still doesn’t work. Even though all the properties are strings, and it is the same field, the formats of the strings are somehow still incompatible. The data type in this case was a datetime. It turns out that the format that comes out of the <span style="font-family: Consolas;">ListItem</span> is in the format the SharePoint site uses, while the <span style="font-family: Consolas;">AfterProperties</span> need the date in ISO8601 format. The fourth and final iteration (that actually works) of the line ended up as</p>
<pre class="brush: csharp; gutter: true">properties.AfterProperties[“Decision_x0020_Date”] = Microsoft.SharePoint.Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Parse(properties.ListItem[“Decision_x0020_Date”].ToString()))</pre>
<p>Short and concise.</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.ecraft.com/2010/04/21/sharepoint-event-handler-gotchas/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>SQL access with integrated security from SharePoint</title>
		<link>http://labs.ecraft.com/2010/04/15/sql-access-with-integrated-security-from-sharepoint/</link>
		<comments>http://labs.ecraft.com/2010/04/15/sql-access-with-integrated-security-from-sharepoint/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 08:07:48 +0000</pubDate>
		<dc:creator>Andreas Finne</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Gotcha]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[SQL]]></category>
		<guid isPermaLink="false">http://SQL-access-with-integrated-security-from-SharePoint</guid>
		<description><![CDATA[When creating custom webparts or other custom features in SharePoint that retrieves data from a SQL server, there are a few gotchas and pitfalls that you should be aware of. I spent a few hours battling a couple of problems, so I thought I’d document the things I found out here to spread the knowledge. [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Flabs.ecraft.com%2F2010%2F04%2F15%2Fsql-access-with-integrated-security-from-sharepoint%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Flabs.ecraft.com%2F2010%2F04%2F15%2Fsql-access-with-integrated-security-from-sharepoint%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>When creating custom webparts or other custom features in SharePoint that retrieves data from a SQL server, there are a few gotchas and pitfalls that you should be aware of. I spent a few hours battling a couple of problems, so I thought I’d document the things I found out here to spread the knowledge.</p>
<p><span id="more-39"></span></p>
<p>I was creating a custom webpart that retrieved data from a SQL server. On my development machine, I used a test SQL user with username and password directly in the connection string in the web.config and things worked as they should. The problems started when I deployed my solution to the test server.</p>
<p>On the test server, I changed the connection string to use integrated security instead, and when trying to access the page, I was greeted with an error message stating that I was not allowed to have a connection string with the words Integrated Security in it. This happens since SharePoint adds a tag mapping that replaces the normal SqlClient assembly with SharePoint’s own. Apparently that SqlClient does not support integrated security. So, what I had to do was to add the following line to my web.config in the tagMappings-section:</p>
<pre class="brush: xml; gutter: true">&lt;remove tagType=”System.Web.UI.WebControls.SqlDataSource, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” /&gt;</pre>
<pre><span class="Apple-style-span" style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; white-space: normal;">After I added this line, things worked ok when I tried the page on the test server. However, when I asked a colleague to try out the page from his machine, another issue arose. He was greeted with the message: <strong>Login failed for user ‘NT AUTHORITY\ANONYMOUS LOGON’</strong>. This happens since SharePoint by default tries to impersonate the user browsing the site, so when using integrated security (if your environment is set up for impersonation multi-hop) SharePoint actually connects to the database as you. If impersonation-forwarding is not supported, you are instead greeted with the previously mentioned login failed message.</span></pre>
<p>What I actually wanted to do in my webpart was to connect to the database as the SharePoint service user, not using impersonation. To fix this, I created two helper methods that turns off impersonation temporarily.</p>
<pre class="brush: csharp; gutter: true">private WindowsImpersonationContext ctx = null;
public void UseAppPoolIdentity()
{
  try
  {
    if (!WindowsIdentity.GetCurrent().IsSystem)
    {
      ctx = WindowsIdentity.Impersonate(System.IntPtr.Zero);
    }
  } catch { }
}
public void ReturnToImpersonatingCurrentUser()
{
  try
  {
    if (ctx != null) { ctx.Undo(); }
  }
  catch { }
}</pre>
<p>These calls are then placed around the code that should be run as the service user, for instance when retrieving information from the SQL database, like this:</p>
<pre class="brush: csharp; gutter: true">UseAppPoolIdentity();
// Code to retrieve data
ReturnToImpersonatingCurrentUser();</pre>
]]></content:encoded>
			<wfw:commentRss>http://labs.ecraft.com/2010/04/15/sql-access-with-integrated-security-from-sharepoint/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

