<?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>Developit</title>
	<atom:link href="http://developit.nu/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://developit.nu</link>
	<description>En WordPressblogg till</description>
	<lastBuildDate>Wed, 18 Aug 2010 09:30:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to change the SQL Replication Agent History Cleanup Job</title>
		<link>http://developit.nu/?p=84</link>
		<comments>http://developit.nu/?p=84#comments</comments>
		<pubDate>Wed, 18 Aug 2010 09:30:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Okategoriserade]]></category>

		<guid isPermaLink="false">http://developit.nu/?p=84</guid>
		<description><![CDATA[How to change the SQL Replication Agent History Cleanup Job
Chris Skorlinski
Microsoft SQL Server Escalation Services
By default the SQL Replication Agent History cleanup job runs every 10 minutes and deletes any historical data older the 48 hours.  If you’re only running SQL Server Replication Agent a few times each day, you can reduce the frequency of [...]]]></description>
			<content:encoded><![CDATA[<h3>How to change the SQL Replication Agent History Cleanup Job</h3>
<p>Chris Skorlinski<br />
Microsoft SQL Server Escalation Services</p>
<p>By default the SQL Replication Agent History cleanup job runs every 10 minutes and deletes any historical data older the 48 hours.  If you’re only running SQL Server Replication Agent a few times each day, you can reduce the frequency of this cleanup job and increase the retention period for historical data without impacting SQL Server Replication performance.  The additional data may be helpful with tracking down subscribers with slow synchronization times.</p>
<p>To adjust the SQL Replication Agent History cleanup job:</p>
<p>1) Right-click on the &#8216;Agent history clean up: distribution&#8217; cleanup Job in SQL Server Agent and select Properties.</p>
<p><a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-34-30-metablogapi/6406.image_5F00_2AA42922.png"><img title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-34-30-metablogapi/4530.image_5F00_thumb_5F00_4A5302EA.png" border="0" alt="image" width="244" height="64" /></a></p>
<p>2) On the Schedules page, adjust the Job run frequency as needed.  For example, if you only synchronize your subscribers once a day, you can set the cleanup to also run once a day.</p>
<p>3) On the Steps page, click Edit to bring up the TSQL command.  You can increase the retention parameter to keep &gt; 48 hours for Replication topologies which synchronize infrequently.  Don’t set this to high or so much historical data will be stored the distribution database performance is impacted.  If you need longer then say 1 week of data, consider moving the history data to an archived database.</p>
<blockquote><p> <strong>EXEC dbo.sp_MShistory_cleanup @history_retention = 48</strong></p></blockquote>
<p>The following posting below contains detailed information on the Merge session history tables along with scripts to pull out long running subscribers.</p>
]]></content:encoded>
			<wfw:commentRss>http://developit.nu/?feed=rss2&amp;p=84</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Phone 7 Design Resources – UI Guide and Design Templates</title>
		<link>http://developit.nu/?p=82</link>
		<comments>http://developit.nu/?p=82#comments</comments>
		<pubDate>Wed, 28 Jul 2010 09:39:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Okategoriserade]]></category>

		<guid isPermaLink="false">http://developit.nu/?p=82</guid>
		<description><![CDATA[With the Windows Phone Developer Tools in Beta and Windows Phone 7 in ,now is the time for you to build Windows Phone 7 apps in earnest. We have refreshed our developer documentation to help you build those apps, and we have two, new design-focused documents to help you make them look beautiful.
First up, the [...]]]></description>
			<content:encoded><![CDATA[<p>With the <a href="http://go.microsoft.com/fwlink/?LinkID=189554">Windows Phone Developer Tools</a> in <a href="http://windowsteamblog.com/windows_phone/b/wpdev/archive/2010/07/12/windows-phone-developer-tools-beta-released.aspx">Beta</a> and Windows Phone 7 in <a href="http://windowsteamblog.com/windows_phone/b/windowsphone/archive/2010/07/18/a-windows-phone-7-milestone.aspx"></a>,now is the time for you to build Windows Phone 7 apps in earnest. We have refreshed our <a href="http://msdn.microsoft.com/en-us/library/ff402535(VS.92).aspx">developer documentation</a> to help you build those apps, and we have two, new design-focused documents to help you make them look beautiful.</p>
<p>First up, the <strong><a href="http://go.microsoft.com/fwlink/?LinkID=183218">UI Design and Interaction Guide for Windows Phone 7 v2.0</a> </strong>has been updated from the ground up for beta. With additional information and a new layout we hope you will find more readable, this guide provides detailed information about UI elements and controls, UI system behaviors, and the interaction model for the touch interface based on the design system internally named Metro. Designers and developers should read this guide to learn about the dos and don’ts of UI implementations for their Windows Phone apps. We&#8217;ve made it easier to find specific guidance by putting it in bold in the right-hand column of each page.</p>
]]></content:encoded>
			<wfw:commentRss>http://developit.nu/?feed=rss2&amp;p=82</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming the Task Bar in Windows 7 with WPF 4 Article Series</title>
		<link>http://developit.nu/?p=80</link>
		<comments>http://developit.nu/?p=80#comments</comments>
		<pubDate>Sat, 26 Jun 2010 10:24:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Okategoriserade]]></category>

		<guid isPermaLink="false">http://developit.nu/?p=80</guid>
		<description><![CDATA[Last week we published an article by VB MVP Alessandro Del Sole on how to utilize a cool Windows 7 Task Bar feature from WPF. Well this week we published another one on Jump Lists and Ale has promised to deliver even more! So yesterday we added a dedicated page to the Visual Basic Developer [...]]]></description>
			<content:encoded><![CDATA[<p>Last week we <a href="http://msdn.microsoft.com/en-us/vbasic/ff699128.aspx" target="_blank">published an article</a> by VB MVP <a href="http://community.visual-basic.it/Alessandro">Alessandro Del Sole</a> on how to utilize a cool Windows 7 Task Bar feature from WPF. Well this week we <a href="http://msdn.microsoft.com/en-us/vbasic/ff770767.aspx" target="_blank">published another one on Jump Lists</a> and Ale has promised to deliver even more! So yesterday we added a dedicated page to the <a href="http://msdn.com/vbasic" target="_blank">Visual Basic Developer Center</a> that has a list of articles, samples and resources for programming in WPF and Windows 7.</p>
<p><strong><a href="http://msdn.microsoft.com/en-us/vbasic/ff770717.aspx" target="_blank"></a><a href="http://msdn.microsoft.com/en-us/vbasic/ff770717.aspx" target="_blank"><img src="http://i.msdn.microsoft.com/ee402630.Windows_lg(en-us,MSDN.10).png" border="0" alt="Programming the Task Bar in Windows 7 with WPF 4, Part One – Thumbnail Buttons" /></a><span style="font-size: medium;"><a href="http://msdn.microsoft.com/en-us/vbasic/ff770717.aspx" target="_blank">Programming Windows 7 with WPF 4</a></span></strong></p>
<p>Right now we have these articles for you to read, but check <a href="http://msdn.microsoft.com/en-us/vbasic/ff770717.aspx" target="_blank">this page</a> for more coming soon.</p>
<p><a href="http://services.social.microsoft.com/feeds/FeedItem?feedId=aab35b35-2a42-43e6-b6f1-ca1cb0c752a5&amp;itemId=97969647-2927-4537-919d-445cc9e770f9&amp;title=Programming+the+Task+Bar+in+Windows+7+with+WPF+4%2c+Part+One+%e2%80%93+Thumbnail+Buttons&amp;uri=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2fvbasic%2fff699128.aspx&amp;k=ZeDpct2OyB%2fc6DcLXI4ExpVD36zslkmiZFDR%2bndg7Q8%3d">Programming the Task Bar in Windows 7 with WPF 4, Part One – Thumbnail Buttons</a><br />
Learn how to create interactive thumbnail buttons for your applications that appear on the Windows 7 taskbar using Windows Presentation Foundation.</p>
<p><a href="http://services.social.microsoft.com/feeds/FeedItem?feedId=aab35b35-2a42-43e6-b6f1-ca1cb0c752a5&amp;itemId=fa729cb5-0cd1-41ce-aca0-8f1877054b53&amp;title=Programming+the+Task+Bar+in+Windows+7+with+WPF+4%2c+Part+Two+%e2%80%93+Jump+Lists&amp;uri=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2fvbasic%2fff770767.aspx&amp;k=l0blyxyEy%2fq0byDURPP2DZQ4jq%2b0nfD8eqHQblgfkhM%3d">Programming the Task Bar in Windows 7 with WPF 4, Part Two – Jump Lists</a><br />
Learn how to program the the Windows 7 Jump List which provides an enhanced user experience offering easy access to common tasks, recent files and custom items related to your applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://developit.nu/?feed=rss2&amp;p=80</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recap: TechEd 2010 in New Orleans &#8211; We&#8217;re Jazzed Ya&#8217;ll Were Here!</title>
		<link>http://developit.nu/?p=78</link>
		<comments>http://developit.nu/?p=78#comments</comments>
		<pubDate>Thu, 24 Jun 2010 20:50:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Okategoriserade]]></category>

		<guid isPermaLink="false">http://developit.nu/?p=78</guid>
		<description><![CDATA[Wow! What a week! I remember the first time I saw a TechEd backpack was back in 2003, where the words “New Orleans” caught my eye. And after 7 years of waiting, my career-long dream came true of attending a Microsoft conference back home.
Earlier this month, TechEd returned to New Orleans for the first time [...]]]></description>
			<content:encoded><![CDATA[<p>Wow! What a week! I remember the first time I saw a TechEd backpack was back in 2003, where the words “New Orleans” caught my eye. And after 7 years of waiting, my career-long dream came true of attending a Microsoft conference back home.</p>
<p>Earlier this month, TechEd returned to New Orleans for the first time since Hurricane Katrina, bringing 10,500 attendees to the area. And now considering the oil disaster in the gulf (I must admit I agree with The Daily Show that something is trying to kill N.O.), there was no better time for an economic boost for the city. TechEd even caught <a href="http://www.nola.com/business/index.ssf/2010/06/microsoft_conference_being_hel.html">the attention of the major local newspaper</a> (The Times-Picayune), describing cloud computing and the technical in-depth training TechEd provided. But Visual Studio 201? Opps! =D</p>
<p>The best part of TechEd for me was being a local among the locals. I’ve said for years that “Community is walking among the people”, but having this sense of Community^2 was incredible. I felt like I’ve known local attendees all my life, and for non-locals, I found myself with every conversation playing tour guide, making sure they had the most enjoyable TechEd experience possible. Fortunately, a local told me about <a href="http://www.nomenu.com/">http://www.nomenu.com/</a> which was a lifesaver in giving people French Quarter restaurant recommendations.</p>
<p><strong>Highlights</strong></p>
<ul>
<li>In my opinion, <strong>the unsung hero of TechEd was <a href="http://www.linkedin.com/in/tiffanywi">Tiffany Ingargiola</a></strong>, an IT Pro at New Horizons in New Orleans. She was the go-to local person for so many of us trying to organize events, but needed a contact on the ground. And she’s awesome to follow on <a href="http://twitter.com/tiffanywi">twitter</a>.</li>
<li>Instead of purchasing a center-stage booth, <strong><a href="http://www.devexpress.com/Home/Announces/tech-ed-2010.xml">DevExpress decided to purchase the smallest booth possible and donate the rest to build a house</a></strong></li>
<li><strong><a href="http://www.microsoft.com/Presspass/Features/2010/jun10/06-8HomeBuilding.mspx">GeekGive.org ran its first successful event</a> </strong>by participating in a Habitat for Humanity build the Friday before TechEd, where I got to work side-by-side with my local area <a href="http://peterkellner.net/">MVP Peter Kellner</a>.</li>
<li>I successfully nominated my undergrad professor from Miss State<strong>, <a href="http://www.cse.msstate.edu/~dreese/">Associated Dean of Engineering Dr. Donna Reese</a>, to speak at the Women in Tech luncheon</strong> about how to retain women in CS programs. Over 400 women attended the event.</li>
<li><strong>The attendee party hosted *the* Zydeco band of New Orleans</strong> <strong><a href="http://rockindopsie.com/">Rockin’ Dopsie, Jr, and the Zydeco Twisters</a></strong>. I don’t think the attendees realized how much of a treat it was to have the band that plays during the Lundi Gras cerebration every year, where a United States Coast Guard ship delivers The King of Rex to the Riverwalk stage for the Mayor of New Orleans to hand over control of the city to for Mardi Gras Day. Afterwards, I got a chance to shake his hand and let him know what an honor it was to meet him.</li>
</ul>
<p><strong>Lowlights</strong></p>
<ul>
<li>N.O. was under a heat wave advisory for that week. <strong>Heat index was between 110-115(!) most days.</strong></li>
<li>On Tuesday, there was a <strong>city-wide Internet outage</strong> for nearly 30 minutes. I never heard what caused outage.</li>
<li>The convention center food wasn’t quite Cajun. <strong>“Cajun meatloaf” just isn’t right.</strong> But, I said it was to encourage folks to support local merchants by eating at local shops across the street. =D</li>
<li><strong>The effects of the Oil Spill were readily apparent</strong>. Just a few blocks away from TechEd was the annual Oyster Festival, where locals held a jazz funeral. Additionally, on that Thursday, <a href="http://www.miamiherald.com/2010/06/10/1672719/oil-spill-threatens-134-year-old.html">a 134-year old Oyster bar closed </a>.</li>
</ul>
<p><strong>GeekGive.org Habitat build</strong></p>
<p>Last year at TechEd, <a href="http://www.platinumbay.com/about.aspx">MVP Steve Andrews</a>, <a href="http://twitter.com/m_rosenberg">MVP Mark Rosenberg</a>, <a href="http://www.ineta.org/default.aspx">INETA members</a> and I chatted about what we could do to help New Orleans. We came up with a concept similar to GiveCamp, but instead of donating code, we’ll donate volunteer hours. Driven by Steve Andrews, he created <a href="http://geekgive.org/">GeekGive.org</a> for conference attendees to volunteer their time at a local charity before the conference starts.</p>
]]></content:encoded>
			<wfw:commentRss>http://developit.nu/?feed=rss2&amp;p=78</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Demos not to miss next week at NAB: 3D video in Silverlight! 1080p H.264 running on a Netbook!</title>
		<link>http://developit.nu/?p=76</link>
		<comments>http://developit.nu/?p=76#comments</comments>
		<pubDate>Thu, 15 Apr 2010 21:20:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Okategoriserade]]></category>

		<guid isPermaLink="false">http://developit.nu/?p=76</guid>
		<description><![CDATA[Yesterday we announced our news for NAB next week in Las Vegas. Today we wanted to point out some other cool experiences to check out in Las Vegas.   First we are showing the industry’s most exciting demo of live 3D HD streaming using IIS Smooth Streaming and Silverlight. Content is coming from Germany from TVN, [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday we announced our news for NAB next week in Las Vegas. Today we wanted to point out some other cool experiences to check out in Las Vegas.   First we are showing the industry’s most exciting demo of live 3D HD streaming using IIS Smooth Streaming and Silverlight. Content is coming from Germany from TVN, encoded by an Inlet encoder and then delivered via Level 3.</p>
<p>There will be two technology previews shown. The first one will use the Silverlight player to decode the 3D content and dynamically apply anaglyph (red-cyan) transformations to the video. The video will play back on a conventional display using red-cyan glasses.   The 2<sup>nd</sup> demo will use Silverlight to play the video without transformation and output to a Panasonic 3D plasma display. THX Media Director was instrumental in making the 2<sup>nd</sup> demo possible. Here is a diagram of the demo flow:</p>
]]></content:encoded>
			<wfw:commentRss>http://developit.nu/?feed=rss2&amp;p=76</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Automatic Properties, Collection Initializers, and Implicit Line Continuation support with VB 2010</title>
		<link>http://developit.nu/?p=74</link>
		<comments>http://developit.nu/?p=74#comments</comments>
		<pubDate>Tue, 06 Apr 2010 15:15:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Okategoriserade]]></category>

		<guid isPermaLink="false">http://developit.nu/?p=74</guid>
		<description><![CDATA[ [In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]
This is the eighteenth in a series of blog posts I’m doing on the upcoming VS 2010 and .NET 4 release.
A few days ago I blogged about two new language features coming with C# 4.0: [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-family: arial; font-size: x-small;"> [<em>In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: </em><a href="http://www.twitter.com/scottgu" target="_blank">twitter.com/scottgu</a>]</p>
<p>This is the eighteenth in a <a href="http://weblogs.asp.net/scottgu/archive/2009/08/25/vs-2010-and-net-4-series.aspx" target="_blank">series of blog posts</a> I’m doing on the upcoming VS 2010 and .NET 4 release.</p>
<p>A few days ago I blogged about two new language features coming with C# 4.0: <a href="http://weblogs.asp.net/scottgu/archive/2010/04/02/optional-parameters-and-named-arguments-in-c-4-and-a-cool-scenario-w-asp-net-mvc-2.aspx" target="_blank">optional parameters and named arguments</a>. </p>
<p>Today I’m going to post about a few of my favorite new features being added to VB with VS 2010: Auto-Implemented Properties, Collection Initializers, and Implicit Line Continuation support.</p>
<h3><span style="text-decoration: underline;">Auto-Implemented Properties</span></h3>
<p>Prior to VB 2010, implementing properties within a class using VB required you to explicitly declare the property as well as implement a backing field variable to store its value. </p>
<p>For example, the code below demonstrates how to implement a “Person” class using VB 2008 that exposes two public properties &#8211; “Name” and “Age”:</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_0F33D07F.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_55448D92.png" border="0" alt="image" width="392" height="470" /></a> </p>
<p>While explicitly declaring properties like above provides maximum flexibility, I’ve always found writing this type of boiler-plate get/set code tedious when you are simply storing/retrieving the value from a field.  You <em>can</em> use VS code snippets to help automate the generation of it – but it still generates a lot of code that feels redundant.  C# 2008 introduced a cool new feature called <a href="http://weblogs.asp.net/scottgu/archive/2007/03/08/new-c-orcas-language-features-automatic-properties-object-initializers-and-collection-initializers.aspx" target="_blank">automatic properties</a> that helps cut down the code quite a bit for the common case where properties are simply backed by a field.  VB 2010 also now supports this same feature. </p>
<p>Using the auto-implemented properties feature of VB 2010 we can now implement our Person class using just the code below:</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_546C27A8.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_3A97F179.png" border="0" alt="image" width="272" height="163" /></a></p>
<p>When you declare an auto-implemented property, the VB compiler automatically creates a private field to store the property value as well as generates the associated Get/Set methods for you.  As you can see above – the code is much more concise and easier to read.</p>
<p>The syntax supports optionally initializing the properties with default values as well if you want to:</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_65042296.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_3953589A.png" border="0" alt="image" width="384" height="154" /></a></p>
<p>You can learn more about VB 2010’s automatic property support from <a href="http://msdn.microsoft.com/en-us/library/dd293589(v=VS.100).aspx" target="_blank">this MSDN page</a>.</p>
<h3><span style="text-decoration: underline;">Collection Initializers </span></h3>
<p>VB 2010 also now supports using collection initializers to easily create a collection and populate it with an initial set of values.  You identify a collection initializer by declaring a collection variable and then use the <strong>From</strong> keyword followed by braces { } that contain the list of initial values to add to the collection. </p>
<p>Below is a code example where I am using the new collection initializer feature to populate a “Friends” list of Person objects with two people, and then bind it to a GridView control to display on a page:</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_31C7E92D.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_10D47686.png" border="0" alt="image" width="614" height="204" /></a></p>
<p>You can learn more about VB 2010’s collection initializer support from <a href="http://msdn.microsoft.com/en-us/library/dd293617(v=VS.100).aspx" target="_blank">this MSDN page</a>.</p>
<h3><span style="text-decoration: underline;">Implicit Line Continuation Support</span></h3>
<p>Traditionally, when a statement in VB has been split up across multiple lines, you had to use a line-continuation underscore character (_) to indicate that the statement wasn’t complete. </p>
<p>For example, with VB 2008 the below LINQ query needs to append a “_” at the end of each line to indicate that the query is not complete yet:</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_1B259AE6.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_21003E7F.png" border="0" alt="image" width="618" height="217" /></a></p>
<p>The VB 2010 compiler and code editor now adds support for what is called “implicit line continuation support” – which means that it is smarter about auto-detecting line continuation scenarios, and as a result no longer needs you to explicitly indicate that the statement continues in many, many scenarios.  This means that with VB 2010 we can now write the above code with no “_” at all:</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_4DA8F858.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_57FA1CB8.png" border="0" alt="image" width="615" height="218" /></a></p>
<p>The implicit line continuation feature also works well when <a href="http://blogs.msdn.com/vbteam/archive/2010/03/26/editing-xml-literals-embedded-expressions-in-visual-basic-2010-avner-aharoni.aspx" target="_blank">editing XML Literals within VB</a> (which is pretty cool).</p>
<p>You can learn more about VB 2010’s Implicit Line Continuation support and many of the scenarios it supports from <a href="http://msdn.microsoft.com/en-us/library/865x40k4(v=VS.100).aspx" target="_blank">this MSDN page</a> (scroll down to the “Implicit Line Continuation” section to find details).</p>
<h3><span style="text-decoration: underline;">Summary</span></h3>
<p>The above three VB language features are but a few of the new language and code editor features coming with VB 2010.  <a href="http://msdn.microsoft.com/en-us/library/we86c8x2(VS.100).aspx" target="_blank">Visit this site</a> to learn more about some of the other VB language features coming with the release. </p>
<p>Also subscribe to the <a href="http://blogs.msdn.com/vbteam/default.aspx" target="_blank">VB team’s blog</a> to learn more and stay up-to-date with the posts they the team regularly publishes.</p>
<p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://developit.nu/?feed=rss2&amp;p=74</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using jQuery to Insert a New Database Record</title>
		<link>http://developit.nu/?p=72</link>
		<comments>http://developit.nu/?p=72#comments</comments>
		<pubDate>Sun, 28 Mar 2010 11:14:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Okategoriserade]]></category>

		<guid isPermaLink="false">http://developit.nu/?p=72</guid>
		<description><![CDATA[The goal of this blog entry is to explore the easiest way of inserting a new record into a database using jQuery and .NET. I’m going to explore two approaches: using Generic Handlers and using a WCF service (In a future blog entry I’ll take a look at OData and WCF Data Services).
Create the ASP.NET [...]]]></description>
			<content:encoded><![CDATA[<p>The goal of this blog entry is to explore the easiest way of inserting a new record into a database using jQuery and .NET. I’m going to explore two approaches: using Generic Handlers and using a WCF service (In a future blog entry I’ll take a look at OData and WCF Data Services).</p>
<h3>Create the ASP.NET Project</h3>
<p>I’ll start by creating a new empty ASP.NET application with Visual Studio 2010. Select the menu option <strong>File, New Project</strong> and select the <strong>ASP.NET Empty Web Application</strong> project template.</p>
<p><a href="http://stephenwalther.com/blog/images/stephenwalther_com/blog/WindowsLiveWriter/UsingjQuerytoInsertaNewDatabaseRecord_A51D/clip_image002_2.jpg"><img title="clip_image002" src="http://stephenwalther.com/blog/images/stephenwalther_com/blog/WindowsLiveWriter/UsingjQuerytoInsertaNewDatabaseRecord_A51D/clip_image002_thumb.jpg" border="0" alt="clip_image002" width="628" height="336" /></a></p>
<h3>Setup the Database and Data Model</h3>
<p>I’ll use my standard MoviesDB.mdf movies database. This database contains one table named Movies that looks like this:</p>
<p><a href="http://stephenwalther.com/blog/images/stephenwalther_com/blog/WindowsLiveWriter/UsingjQuerytoInsertaNewDatabaseRecord_A51D/clip_image004_2.jpg"><img title="clip_image004" src="http://stephenwalther.com/blog/images/stephenwalther_com/blog/WindowsLiveWriter/UsingjQuerytoInsertaNewDatabaseRecord_A51D/clip_image004_thumb.jpg" border="0" alt="clip_image004" width="396" height="149" /></a></p>
<p>I’ll use the ADO.NET Entity Framework to represent my database data:</p>
<ol>
<li>Select the menu option <strong>Project, Add New Item </strong>and select the <strong>ADO.NET Entity Data Model</strong> project item. Name the data model MoviesDB.edmx and click the <strong>Add</strong> button.</li>
<li>In the <strong>Choose Model Contents</strong> step, select <strong>Generate from database</strong> and click the <strong>Next</strong> button.</li>
<li>In the <strong>Choose Your Data Connection</strong> step, leave all of the defaults and click the <strong>Next</strong> button.</li>
<li>In the <strong>Choose Your Data Objects</strong> step, select the Movies table and click the <strong>Finish</strong> button.</li>
</ol>
<p>Unfortunately, Visual Studio 2010 cannot spell movie correctly <img src='http://developit.nu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  You need to click on Movy and change the name of the class to <strong>Movie</strong>. In the Properties window, change the <strong>Entity Set Name</strong> to <strong>Movies</strong>.</p>
<p><a href="http://stephenwalther.com/blog/images/stephenwalther_com/blog/WindowsLiveWriter/UsingjQuerytoInsertaNewDatabaseRecord_A51D/clip_image006_2.jpg"><img title="clip_image006" src="http://stephenwalther.com/blog/images/stephenwalther_com/blog/WindowsLiveWriter/UsingjQuerytoInsertaNewDatabaseRecord_A51D/clip_image006_thumb.jpg" border="0" alt="clip_image006" width="219" height="204" /></a></p>
<h3>Using a Generic Handler</h3>
<p>In this section, we’ll use jQuery with an ASP.NET generic handler to insert a new record into the database. A generic handler is similar to an ASP.NET page, but it does not have any of the overhead. It consists of one method named ProcessRequest().</p>
<p>Select the menu option <strong>Project, Add New Item</strong> and select the <strong>Generic Handler</strong> project item. Name your new generic handler InsertMovie.ashx and click the <strong>Add</strong> button.</p>
<p>Modify your handler so it looks like Listing 1:</p>
<p><strong>Listing 1 – InsertMovie.ashx</strong></p>
<div>
<div><a onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;" href="#">view plain</a><a onclick="dp.sh.Toolbar.Command('CopyToClipboard',this);return false;" href="#">copy to clipboard</a><a onclick="dp.sh.Toolbar.Command('PrintSource',this);return false;" href="#">print</a><a onclick="dp.sh.Toolbar.Command('About',this);return false;" href="#">?</a></div>
</div>
<li>using System.Web;   </li>
<li>  </li>
<li>namespace WebApplication1 {   </li>
<li>    /// &lt;summary&gt;   </li>
<li>    /// Inserts a new movie into the database   </li>
<li>    /// &lt;/summary&gt;   </li>
<li>    public class InsertMovie : IHttpHandler {   </li>
<li>  </li>
<li>        private MoviesDBEntities _dataContext = new MoviesDBEntities();   </li>
<li>  </li>
<li>        public void ProcessRequest(HttpContext context) {   </li>
<li>            context.Response.ContentType = &#8221;text/plain&#8221;;   </li>
<li>  </li>
<li>            // Extract form fields   </li>
<li>            var title = context.Request["title"];   </li>
<li>            var director = context.Request["director"];   </li>
<li>  </li>
<li>            // Create movie to insert   </li>
<li>            var movieToInsert = new Movie { Title = title, Director = director };   </li>
<li>  </li>
<li>            // Save new movie to DB   </li>
<li>            _dataContext.AddToMovies(movieToInsert);   </li>
<li>            _dataContext.SaveChanges();   </li>
<li>  </li>
<li>            // Return success   </li>
<li>            context.Response.Write(&#8221;success&#8221;);   </li>
<li>        }   </li>
<li>  </li>
<li>        public bool IsReusable {   </li>
<li>            get {   </li>
<li>                return true;   </li>
<li>            }   </li>
<li>        }   </li>
<li>  </li>
<li>  </li>
<li>  </li>
<li>    }   </li>
<li>}  </li>
<pre>using System.Web;

namespace WebApplication1 {
    /// &lt;summary&gt;
    /// Inserts a new movie into the database
    /// &lt;/summary&gt;
    public class InsertMovie : IHttpHandler {

        private MoviesDBEntities _dataContext = new MoviesDBEntities();

        public void ProcessRequest(HttpContext context) {
            context.Response.ContentType = "text/plain";

            // Extract form fields
            var title = context.Request["title"];
            var director = context.Request["director"];

            // Create movie to insert
            var movieToInsert = new Movie { Title = title, Director = director };

            // Save new movie to DB
            _dataContext.AddToMovies(movieToInsert);
            _dataContext.SaveChanges();

            // Return success
            context.Response.Write("success");
        }

        public bool IsReusable {
            get {
                return true;
            }
        }

    }
}</pre>
<p>In Listing 1, the ProcessRequest() method is used to retrieve a title and director from form parameters. Next, a new Movie is created with the form values. Finally, the new movie is saved to the database and the string “success” is returned.</p>
<h4>Using jQuery with the Generic Handler</h4>
<p>We can call the InsertMovie.ashx generic handler from jQuery by using the standard jQuery post() method. The following HTML page illustrates how you can retrieve form field values and post the values to the generic handler:</p>
<p><strong>Listing 2 – Default.htm</strong></p>
<div>
<div><a onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;" href="#">view plain</a><a onclick="dp.sh.Toolbar.Command('CopyToClipboard',this);return false;" href="#">copy to clipboard</a><a onclick="dp.sh.Toolbar.Command('PrintSource',this);return false;" href="#">print</a><a onclick="dp.sh.Toolbar.Command('About',this);return false;" href="#">?</a></div>
</div>
<li>&lt;!DOCTYPE html PUBLIC &#8221;-//W3C//DTD XHTML 1.0 Transitional//EN&#8221; &#8221;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#8221;&gt;  </li>
<li>&lt;html xmlns=&#8221;http://www.w3.org/1999/xhtml&#8221;&gt;  </li>
<li>&lt;head&gt;  </li>
<li>    &lt;title&gt;Add Movie&lt;/title&gt;  </li>
<li>  </li>
<li>    &lt;script src=&#8221;http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js&#8221; type=&#8221;text/javascript&#8221;&gt;&lt;/script&gt;    </li>
<li>&lt;/head&gt;  </li>
<li>&lt;body&gt;  </li>
<li>  </li>
<li>&lt;form&gt;  </li>
<li>    &lt;label&gt;Title:&lt;/label&gt;  </li>
<li>    &lt;input name=&#8221;title&#8221; /&gt;  </li>
<li>  </li>
<li>    &lt;br /&gt;  </li>
<li>  </li>
<li>    &lt;label&gt;Director:&lt;/label&gt;  </li>
<li>    &lt;input name=&#8221;director&#8221; /&gt;  </li>
<li>&lt;/form&gt;  </li>
<li>  </li>
<li>&lt;button id=&#8221;btnAdd&#8221;&gt;Add Movie&lt;/button&gt;  </li>
<li>  </li>
<li>  </li>
<li>&lt;script type=&#8221;text/javascript&#8221;&gt;  </li>
<li>  </li>
<li>    $(&#8221;#btnAdd&#8221;).click(function () {   </li>
<li>        $.post(&#8221;InsertMovie.ashx&#8221;, $(&#8221;form&#8221;).serialize(), insertCallback);   </li>
<li>    });   </li>
<li>  </li>
<li>    function insertCallback(result) {   </li>
<li>        if (result == &#8221;success&#8221;) {   </li>
<li>            alert(&#8221;Movie added!&#8221;);   </li>
<li>        } else {   </li>
<li>            alert(&#8221;Could not add movie!&#8221;);   </li>
<li>        }   </li>
<li>    }   </li>
<li>  </li>
<li>  </li>
<li>&lt;/script&gt;  </li>
<li>  </li>
<li>&lt;/body&gt;  </li>
<li>&lt;/html&gt;  </li>
<pre>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
    &lt;title&gt;Add Movie&lt;/title&gt;

    &lt;script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;form&gt;
    &lt;label&gt;Title:&lt;/label&gt;
    &lt;input name="title" /&gt;

    &lt;br /&gt;

    &lt;label&gt;Director:&lt;/label&gt;
    &lt;input name="director" /&gt;
&lt;/form&gt;

&lt;button id="btnAdd"&gt;Add Movie&lt;/button&gt;

&lt;script type="text/javascript"&gt;

    $("#btnAdd").click(function () {
        $.post("InsertMovie.ashx", $("form").serialize(), insertCallback);
    });

    function insertCallback(result) {
        if (result == "success") {
            alert("Movie added!");
        } else {
            alert("Could not add movie!");
        }
    }

&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;</pre>
<p> </p>
<p>When you open the page in Listing 2 in a web browser, you get a simple HTML form:</p>
<p><a href="http://stephenwalther.com/blog/images/stephenwalther_com/blog/WindowsLiveWriter/UsingjQuerytoInsertaNewDatabaseRecord_A51D/clip_image008_2.jpg"><img title="clip_image008" src="http://stephenwalther.com/blog/images/stephenwalther_com/blog/WindowsLiveWriter/UsingjQuerytoInsertaNewDatabaseRecord_A51D/clip_image008_thumb.jpg" border="0" alt="clip_image008" width="321" height="254" /></a></p>
<p>Notice that the page in Listing 2 includes the jQuery library. The jQuery library is included with the following SCRIPT tag:</p>
<blockquote><p>&lt;script src=&#8221;http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js&#8221; type=&#8221;text/javascript&#8221;&gt;&lt;/script&gt;</p></blockquote>
<p>The jQuery library is included on the Microsoft Ajax CDN so you can always easily include the jQuery library in your applications. You can learn more about the CDN at this website:</p>
<blockquote><p><a href="http://www.asp.net/ajaxLibrary/cdn.ashx">http://www.asp.net/ajaxLibrary/cdn.ashx</a></p></blockquote>
<p>When you click the <strong>Add Movie</strong> button, the jQuery post() method is called to post the form data to the InsertMovie.ashx generic handler. Notice that the form values are serialized into a URL encoded string by calling the jQuery serialize() method. The serialize() method uses the name attribute of form fields and not the id attribute.</p>
<h4>Notes on this Approach</h4>
<p>This is a very low-level approach to interacting with .NET through jQuery – but it is simple and it works! And, you don’t need to use any JavaScript libraries in addition to the jQuery library to use this approach.</p>
<p>The signature for the jQuery post() callback method looks like this:</p>
<blockquote><p>callback(data, textStatus, XmlHttpRequest)</p></blockquote>
<p>The second parameter, textStatus, returns the HTTP status code from the server. I tried returning different status codes from the generic handler with an eye towards implementing server validation by returning a status code such as 400 Bad Request when validation fails (see <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html">http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html</a> ). I finally figured out that the callback is not invoked when the textStatus has any value other than “success”.</p>
<h3>Using a WCF Service</h3>
<p>As an alternative to posting to a generic handler, you can create a WCF service.</p>
<p>You create a new WCF service by selecting the menu option Project, Add New Item and selecting the <strong>Ajax-enabled WCF Service</strong> project item. Name your WCF service InsertMovie.svc and click the <strong>Add</strong> button.</p>
<p><a href="http://stephenwalther.com/blog/images/stephenwalther_com/blog/WindowsLiveWriter/UsingjQuerytoInsertaNewDatabaseRecord_A51D/clip_image010_2.jpg"><img title="clip_image010" src="http://stephenwalther.com/blog/images/stephenwalther_com/blog/WindowsLiveWriter/UsingjQuerytoInsertaNewDatabaseRecord_A51D/clip_image010_thumb.jpg" border="0" alt="clip_image010" width="628" height="355" /></a></p>
<p>Modify the WCF service so that it looks like Listing 3:</p>
<p><strong>Listing 3 – InsertMovie.svc</strong></p>
<div>
<div><a onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;" href="#">view plain</a><a onclick="dp.sh.Toolbar.Command('CopyToClipboard',this);return false;" href="#">copy to clipboard</a><a onclick="dp.sh.Toolbar.Command('PrintSource',this);return false;" href="#">print</a><a onclick="dp.sh.Toolbar.Command('About',this);return false;" href="#">?</a></div>
</div>
<li>using System.ServiceModel;   </li>
<li>using System.ServiceModel.Activation;   </li>
<li>  </li>
<li>namespace WebApplication1 {   </li>
<li>  </li>
<li>    [ServiceBehavior(IncludeExceptionDetailInFaults=true)]   </li>
<li>    [ServiceContract(Namespace = "")]   </li>
<li>    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]   </li>
<li>    public class MovieService {   </li>
<li>  </li>
<li>        private MoviesDBEntities _dataContext = new MoviesDBEntities();   </li>
<li>  </li>
<li>        [OperationContract]   </li>
<li>        public bool Insert(string title, string director) {   </li>
<li>            // Create movie to insert   </li>
<li>            var movieToInsert = new Movie { Title = title, Director = director };   </li>
<li>  </li>
<li>            // Save new movie to DB   </li>
<li>            _dataContext.AddToMovies(movieToInsert);   </li>
<li>            _dataContext.SaveChanges();   </li>
<li>  </li>
<li>            // Return movie (with primary key)   </li>
<li>            return true;   </li>
<li>        }   </li>
<li>  </li>
<li>    }   </li>
<li>}  </li>
<pre>using System.ServiceModel;
using System.ServiceModel.Activation;

namespace WebApplication1 {

    [ServiceBehavior(IncludeExceptionDetailInFaults=true)]
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class MovieService {

        private MoviesDBEntities _dataContext = new MoviesDBEntities();

        [OperationContract]
        public bool Insert(string title, string director) {
            // Create movie to insert
            var movieToInsert = new Movie { Title = title, Director = director };

            // Save new movie to DB
            _dataContext.AddToMovies(movieToInsert);
            _dataContext.SaveChanges();

            // Return movie (with primary key)
            return true;
        }

    }
}</pre>
<p> </p>
<p>The WCF service in Listing 3 uses the Entity Framework to insert a record into the Movies database table. The service always returns the value true.</p>
<p>Notice that the service in Listing 3 includes the following attribute:</p>
<blockquote><p>[ServiceBehavior(IncludeExceptionDetailInFaults=true)]</p></blockquote>
<p>You need to include this attribute if you want to get detailed error information back to the client. When you are building an application, you should always include this attribute. When you are ready to release your application, you should remove this attribute for security reasons.</p>
<h4>Using jQuery with the WCF Service</h4>
<p>Calling a WCF service from jQuery requires a little more work than calling a generic handler from jQuery. Here are some good blog posts on some of the issues with using jQuery with WCF:</p>
<ul>
<li><a href="http://encosia.com/2008/06/05/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax/">http://encosia.com/2008/06/05/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax/</a></li>
<li><a href="http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/">http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/</a></li>
<li><a href="http://weblogs.asp.net/scottgu/archive/2007/04/04/json-hijacking-and-how-asp-net-ajax-1-0-mitigates-these-attacks.aspx">http://weblogs.asp.net/scottgu/archive/2007/04/04/json-hijacking-and-how-asp-net-ajax-1-0-mitigates-these-attacks.aspx</a></li>
<li><a href="http://www.west-wind.com/Weblog/posts/896411.aspx">http://www.west-wind.com/Weblog/posts/896411.aspx</a></li>
<li><a href="http://www.west-wind.com/weblog/posts/324917.aspx">http://www.west-wind.com/weblog/posts/324917.aspx</a></li>
<li><a href="http://professionalaspnet.com/archive/tags/WCF/default.aspx">http://professionalaspnet.com/archive/tags/WCF/default.aspx</a></li>
</ul>
<p>The primary requirement when calling WCF from jQuery is that the request use JSON:</p>
<ul>
<li>The request must include a content-type:application/json header.</li>
<li>Any parameters included with the request must be JSON encoded.</li>
</ul>
<p>Unfortunately, jQuery does not include a method for serializing JSON (Although, oddly, jQuery does include a parseJSON() method for deserializing JSON). Therefore, we need to use an additional library to handle the JSON serialization.</p>
<p>The page in Listing 4 illustrates how you can call a WCF service from jQuery.</p>
<p><strong>Listing 4 – Default2.aspx</strong></p>
<div>
<div><a onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;" href="#">view plain</a><a onclick="dp.sh.Toolbar.Command('CopyToClipboard',this);return false;" href="#">copy to clipboard</a><a onclick="dp.sh.Toolbar.Command('PrintSource',this);return false;" href="#">print</a><a onclick="dp.sh.Toolbar.Command('About',this);return false;" href="#">?</a></div>
</div>
<li>&lt;!DOCTYPE html PUBLIC &#8221;-//W3C//DTD XHTML 1.0 Transitional//EN&#8221; &#8221;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#8221;&gt;  </li>
<li>&lt;html xmlns=&#8221;http://www.w3.org/1999/xhtml&#8221;&gt;  </li>
<li>&lt;head&gt;  </li>
<li>    &lt;title&gt;Add Movie&lt;/title&gt;  </li>
<li>  </li>
<li>    &lt;script src=&#8221;http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js&#8221; type=&#8221;text/javascript&#8221;&gt;&lt;/script&gt;    </li>
<li>    &lt;script src=&#8221;Scripts/json2.js&#8221; type=&#8221;text/javascript&#8221;&gt;&lt;/script&gt;  </li>
<li>  </li>
<li>&lt;/head&gt;  </li>
<li>&lt;body&gt;  </li>
<li>  </li>
<li>&lt;form&gt;  </li>
<li>    &lt;label&gt;Title:&lt;/label&gt;  </li>
<li>    &lt;input id=&#8221;title&#8221; /&gt;  </li>
<li>  </li>
<li>    &lt;br /&gt;  </li>
<li>  </li>
<li>    &lt;label&gt;Director:&lt;/label&gt;  </li>
<li>    &lt;input id=&#8221;director&#8221; /&gt;  </li>
<li>&lt;/form&gt;  </li>
<li>  </li>
<li>&lt;button id=&#8221;btnAdd&#8221;&gt;Add Movie&lt;/button&gt;  </li>
<li>  </li>
<li>  </li>
<li>&lt;script type=&#8221;text/javascript&#8221;&gt;  </li>
<li>  </li>
<li>    $(&#8221;#btnAdd&#8221;).click(function () {   </li>
<li>        // Convert the form into an object   </li>
<li>        var data = { title: $(&#8221;#title&#8221;).val(), director: $(&#8221;#director&#8221;).val() };   </li>
<li>  </li>
<li>        // JSONify the data   </li>
<li>        data = JSON.stringify(data);   </li>
<li>  </li>
<li>        // Post it   </li>
<li>        $.ajax({   </li>
<li>            type: &#8221;POST&#8221;,   </li>
<li>            contentType: &#8221;application/json; charset=utf-8&#8243;,   </li>
<li>            url: &#8221;MovieService.svc/Insert&#8221;,   </li>
<li>            data: data,   </li>
<li>            dataType: &#8221;json&#8221;,   </li>
<li>            success: insertCallback    </li>
<li>        });   </li>
<li>    });   </li>
<li>  </li>
<li>  </li>
<li>    function insertCallback(result) {   </li>
<li>        // unwrap result   </li>
<li>        resultresult = result["d"];   </li>
<li>           </li>
<li>        if (result === true) {   </li>
<li>            alert(&#8221;Movie added!&#8221;);   </li>
<li>        } else {   </li>
<li>            alert(&#8221;Could not add movie!&#8221;);   </li>
<li>        }   </li>
<li>    }   </li>
<li>  </li>
<li>  </li>
<li>&lt;/script&gt;  </li>
<li>  </li>
<li>&lt;/body&gt;  </li>
<li>&lt;/html&gt;  </li>
<pre>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
    &lt;title&gt;Add Movie&lt;/title&gt;

    &lt;script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="Scripts/json2.js" type="text/javascript"&gt;&lt;/script&gt;

&lt;/head&gt;
&lt;body&gt;

&lt;form&gt;
    &lt;label&gt;Title:&lt;/label&gt;
    &lt;input id="title" /&gt;

    &lt;br /&gt;

    &lt;label&gt;Director:&lt;/label&gt;
    &lt;input id="director" /&gt;
&lt;/form&gt;

&lt;button id="btnAdd"&gt;Add Movie&lt;/button&gt;

&lt;script type="text/javascript"&gt;

    $("#btnAdd").click(function () {
        // Convert the form into an object
        var data = { title: $("#title").val(), director: $("#director").val() };

        // JSONify the data
        data = JSON.stringify(data);

        // Post it
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "MovieService.svc/Insert",
            data: data,
            dataType: "json",
            success: insertCallback
        });
    });

    function insertCallback(result) {
        // unwrap result
        result = result["d"];

        if (result === true) {
            alert("Movie added!");
        } else {
            alert("Could not add movie!");
        }
    }

&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;</pre>
<p>There are several things to notice about Listing 4. First, notice that the page includes both the jQuery library and Douglas Crockford’s JSON2 library:</p>
<blockquote><p>&lt;script src=&#8221;Scripts/json2.js&#8221; type=&#8221;text/javascript&#8221;&gt;&lt;/script&gt;</p></blockquote>
<p>You need to include the JSON2 library to serialize the form values into JSON. You can download the JSON2 library from the following location:</p>
<blockquote><p><a href="http://www.json.org/js.html">http://www.json.org/js.html</a></p></blockquote>
<p>When you click the button to submit the form, the form data is converted into a JavaScript object:</p>
<blockquote><p>// Convert the form into an object</p>
<p>var data = { title: $(&#8221;#title&#8221;).val(), director: $(&#8221;#director&#8221;).val() };</p></blockquote>
<p>Next, the data is serialized into JSON using the JSON2 library:</p>
<blockquote><p>// JSONify the data</p>
<p>var data = JSON.stringify(data);</p></blockquote>
<p>Finally, the form data is posted to the WCF service by calling the jQuery ajax() method:</p>
<blockquote><p>// Post it</p>
<p>$.ajax({</p>
<p>  type: &#8221;POST&#8221;,</p>
<p>  contentType: &#8221;application/json; charset=utf-8&#8243;,</p>
<p>  url: &#8221;MovieService.svc/Insert&#8221;,</p>
<p>  data: data,</p>
<p>  dataType: &#8221;json&#8221;,</p>
<p>  success: insertCallback</p>
<p>});</p></blockquote>
<p>You can’t use the standard jQuery post() method because you must set the content-type of the request to be application/json. Otherwise, the WCF service will reject the request for security reasons. For details, see the Scott Guthrie blog post:</p>
<blockquote><p><a href="http://weblogs.asp.net/scottgu/archive/2007/04/04/json-hijacking-and-how-asp-net-ajax-1-0-mitigates-these-attacks.aspx">http://weblogs.asp.net/scottgu/archive/2007/04/04/json-hijacking-and-how-asp-net-ajax-1-0-mitigates-these-attacks.aspx</a></p></blockquote>
<p>The insertCallback() method is called when the WCF service returns a response. This method looks like this:</p>
<blockquote><p>function insertCallback(result) {</p>
<p>  // unwrap result</p>
<p>  result = result["d"];</p>
<p>  if (result === true) {</p>
<p>      alert(&#8221;Movie added!&#8221;);</p>
<p>  } else {</p>
<p>    alert(&#8221;Could not add movie!&#8221;);</p>
<p>  }</p>
<p>}</p></blockquote>
<p>When we called the jQuery ajax() method, we set the dataType to JSON. That causes the jQuery ajax() method to deserialize the response from the WCF service from JSON into a JavaScript object automatically. The following value is passed to the insertCallback method:</p>
<blockquote><p>{&#8221;d&#8221;:true}</p></blockquote>
<p>For security reasons, a WCF service always returns a response with a “d” wrapper. The following line of code removes the “d” wrapper:</p>
<blockquote><p>// unwrap result</p>
<p>result = result["d"];</p></blockquote>
<p>To learn more about the “d” wrapper, I recommend that you read the following blog posts:</p>
<ul>
<li><a href="http://encosia.com/2009/02/10/a-breaking-change-between-versions-of-aspnet-ajax/">http://encosia.com/2009/02/10/a-breaking-change-between-versions-of-aspnet-ajax/</a></li>
<li><a href="http://encosia.com/2009/06/29/never-worry-about-asp-net-ajaxs-d-again/">http://encosia.com/2009/06/29/never-worry-about-asp-net-ajaxs-d-again/</a></li>
</ul>
<h3>Summary</h3>
<p>In this blog entry, I explored two methods of inserting a database record using jQuery and .NET. First, we created a generic handler and called the handler from jQuery. This is a very low-level approach. However, it is a simple approach that works.</p>
<p>Next, we looked at how you can call a WCF service using jQuery. This approach required a little more work because you need to serialize objects into JSON. We used the JSON2 library to perform the serialization.</p>
<p>In the next blog post, I want to explore how you can use jQuery with OData and WCF Data Services</p>
]]></content:encoded>
			<wfw:commentRss>http://developit.nu/?feed=rss2&amp;p=72</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a Windows Phone 7 Twitter Application using Silverlight</title>
		<link>http://developit.nu/?p=71</link>
		<comments>http://developit.nu/?p=71#comments</comments>
		<pubDate>Fri, 19 Mar 2010 23:03:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Okategoriserade]]></category>

		<guid isPermaLink="false">http://developit.nu/?p=71</guid>
		<description><![CDATA[ On Monday I had the opportunity to present the MIX 2010 Day 1 Keynote in Las Vegas (you can watch a video of it here).  In the keynote I announced the release of the Silverlight 4 Release Candidate (we’ll ship the final release of it next month) and the VS 2010 RC tools for Silverlight [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-family: arial; font-size: x-small;"> On Monday I had the opportunity to present the <a href="http://live.visitmix.com/MIX10/Sessions/KEY01" target="_blank">MIX 2010 Day 1 Keynote</a> in Las Vegas (you can watch a video of it <a href="http://live.visitmix.com/MIX10/Sessions/KEY01" target="_blank">here</a>).  In the keynote I announced the release of the Silverlight 4 Release Candidate (we’ll ship the final release of it next month) and the VS 2010 RC tools for Silverlight 4.  I also had the chance to talk for the first time about how Silverlight and XNA can now be used to build Windows Phone 7 applications.</p>
<p>During my talk I did two quick Windows Phone 7 coding demos using Silverlight – a quick “Hello World” application and a “Twitter” data-snacking application.  Both applications were easy to build and only took a few minutes to create on stage.  Below are the steps you can follow yourself to build them on your own machines as well.</p>
<p><em>[Note: In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: </em><a href="http://www.twitter.com/scottgu" target="_blank">twitter.com/scottgu</a><em></em><em>]</em></p>
<h3><span style="text-decoration: underline;">Building a “Hello World” Windows Phone 7 Application</span></h3>
<p>First make sure you’ve installed the <a href="http://go.microsoft.com/fwlink/?LinkID=185584">Windows Phone Developer Tools CTP</a> – this includes the Visual Studio 2010 Express for Windows Phone development tool (which will be free forever and is the only thing you need to develop and build Windows Phone 7 applications) as well as an add-on to the VS 2010 RC that enables phone development within the full VS 2010 as well.</p>
<p>After you’ve downloaded and installed the <a href="http://go.microsoft.com/fwlink/?LinkID=185584" target="_blank">Windows Phone Developer Tools CTP</a>, launch the <em>Visual Studio 2010 Express for Windows Phone</em> that it installs or launch the <em>VS 2010 RC </em>(if you have it already installed)<em>,</em> and then choose “File”-&gt;”New Project.”  Here, you’ll find the usual list of project template types along with a new category: “Silverlight for Windows Phone”. The first CTP offers two application project templates. The first is the “Windows Phone Application” template &#8211; this is what we’ll use for this example. The second is the “Windows Phone List Application” template &#8211; which provides the basic layout for a master‑details phone application:</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_0942A287.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_00DECD30.png" border="0" alt="image" width="764" height="487" /></a></p>
<p>After creating a new project, you’ll get a view of the design surface and markup. Notice that the design surface shows the phone UI, letting you easily see how your application will look while you develop. For those familiar with Visual Studio, you’ll also find the familiar ToolBox, Solution Explorer and Properties pane.</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_669E640B.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_732C1127.png" border="0" alt="image" width="627" height="390" /></a> </p>
<p>For our HelloWorld application, we’ll start out by adding a TextBox and a Button from the Toolbox. Notice that you get the same design experience as you do for Silverlight on the web or desktop. You can easily resize, position and align your controls on the design surface. Changing properties is easy with the Properties pane. We’ll change the name of the TextBox that we added to <em>username</em> and change the page title text to “Hello world.”</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_11965211.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_3ABDEA4F.png" border="0" alt="image" width="848" height="525" /></a></p>
<p>We’ll then write some code by double‑clicking on the button and create an event handler in the code-behind file (MainPage.xaml.cs).</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_0E34BA69.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_3834B891.png" border="0" alt="image" width="638" height="400" /></a></p>
<p>We’ll start out by changing the title text of the application. The project template included this title as a TextBlock with the name <em>textBlockListTitle</em> (note that the current name incorrectly includes the word “list”; that will be fixed for the final release.)  As we write code against it we get intellisense showing the members available.  Below we’ll set the Text property of the title TextBlock to “Hello “ + the Text property of the TextBox username:</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_6549A55F.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_569EF97A.png" border="0" alt="image" width="587" height="202" /></a></p>
<p>We now have all the code necessary for a Hello World application.  We have two choices when it comes to deploying and running the application. We can either deploy to an actual device itself or use the built‑in phone emulator:</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_03B3E649.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_69DFB019.png" border="0" alt="image" width="449" height="134" /></a></p>
<p>Because the phone emulator is actually the phone operating system running in a virtual machine, we’ll get the same experience developing in the emulator as on the device. For this sample, we’ll just press F5 to start the application with debugging using the emulator.  Once the phone operating system loads, the emulator will run the new “Hello world” application exactly as it would on the device:</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_7430D479.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_59F06B55.png" border="0" alt="image" width="351" height="584" /></a></p>
<p>Notice that we can change several settings of the emulator experience with the emulator toolbar – which is a floating toolbar on the top right.  This includes the ability to re-size/zoom the emulator and two rotate buttons.  Zoom lets us zoom into even the smallest detail of the application:</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_46CF3EA9.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_6CC4EEFF.png" border="0" alt="image" width="352" height="603" /></a></p>
<p>The orientation buttons allow us easily see what the application looks like in landscape mode (orientation change support is just built into the default template):</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_3673C6F0.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_5C697746.png" border="0" alt="image" width="541" height="274" /></a></p>
<p>Note that the emulator can be reused across F5 debug sessions &#8211; that means that we don’t have to start the emulator for every deployment. We’ve added a dialog that will help you from accidentally shutting down the emulator if you want to reuse it.  Launching an application on an already running emulator should only take ~3 seconds to deploy and run.</p>
<p>Within our Hello World application we’ll click the “username” textbox to give it focus.  This will cause the software input panel (SIP) to open up automatically.  We can either type a message or – since we are using the emulator – just type in text.  Note that the emulator works with Windows 7 multi-touch so, if you have a touchscreen, you can see how interaction will feel on a device just by pressing the screen.</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_292D3DDD.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_681EBE78.png" border="0" alt="image" width="348" height="588" /></a></p>
<p>We’ll enter “MIX 10” in the textbox and then click the button – this will cause the title to update to be “Hello MIX 10”:</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_7922EC5B.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_17F9603A.png" border="0" alt="image" width="370" height="621" /></a></p>
<p>We provide the same Visual Studio experience when developing for the phone as other .NET applications. This means that we can set a breakpoint within the button event handler, press the button again and have it break within the debugger:</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_56EAE0D5.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_6EA2183B.png" border="0" alt="image" width="923" height="343" /></a></p>
<h3><span style="text-decoration: underline;">Building a “Twitter” Windows Phone 7 Application using Silverlight</span></h3>
<p> </p>
<p>Rather than just stop with “Hello World” let’s keep going and evolve it to be a basic Twitter client application.</p>
<p>We’ll return to the design surface and add a ListBox, using the snaplines within the designer to fit it to the device screen and make the best use of phone screen real estate.  We’ll also rename the Button “Lookup”:</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_226A0E8D.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_79EB2C78.png" border="0" alt="image" width="845" height="527" /></a></p>
<p>We’ll then return to the Button event handler in Main.xaml.cs, and remove the original “Hello World” line of code and take advantage of the WebClient networking class to asynchronously download a Twitter feed. This takes three lines of code in total: (1) declaring and creating the WebClient, (2) attaching an event handler and then (3) calling the asynchronous DownloadStringAsync method.</p>
<p>In the DownloadStringAsync call, we’ll pass a Twitter Uri plus a query string which pulls the text from the “username” TextBox. This feed will pull down the respective user’s most frequent posts in an XML format. When the call completes, the DownloadStringCompleted event is fired and our generated event handler twitter_DownloadStringCompleted will be called:</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_0A832767.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_254F4D73.png" border="0" alt="image" width="1033" height="208" /></a></p>
<p>The result returned from the Twitter call will come back in an XML based format.  To parse this we’ll use LINQ to XML. LINQ to XML lets us create simple queries for accessing data in an xml feed. To use this library, we’ll first need to add a reference to the assembly (right click on the References folder in the solution explorer and choose “Add Reference):</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_36537B56.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_63686824.png" border="0" alt="image" width="486" height="412" /></a></p>
<p>We’ll then add a “using System.Xml.Linq” namespace reference at the top of the code-behind file at the top of Main.xaml.cs file:</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_26643692.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_7394301D.png" border="0" alt="image" width="539" height="123" /></a></p>
<p>We’ll then add a simple helper class called TwitterItem to our project. TwitterItem has three string members – UserName, Message and ImageSource:</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_4BEDB3F3.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_6006D07C.png" border="0" alt="image" width="432" height="147" /></a></p>
<p>We’ll then implement the <em>twitter_DownloadStringCompleted</em> event handler and use LINQ to XML to parse the returned XML string from Twitter.  What the query is doing is pulling out the three key pieces of information for each Twitter post from the username we passed as the query string. These are the ImageSource for their profile image, the Message of their tweet and their UserName. For each Tweet in the XML, we are creating a new TwitterItem in the IEnumerable&lt;XElement&gt; returned by the Linq query. </p>
<p>We then assign the generated TwitterItem sequence to the ListBox’s ItemsSource property:</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_3068B1F0.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_683AF613.png" border="0" alt="image" width="946" height="352" /></a></p>
<p>We’ll then do one more step to complete the application. In the Main.xaml file, we’ll add an ItemTemplate to the ListBox. For the demo, I used a simple template that uses databinding to show the user’s profile image, their tweet and their username.</p>
<blockquote>
<pre>&lt;ListBox Height="521" HorizonalAlignment="Left" Margin="0,131,0,0" Name="listBox1" VerticalAlignment="Top" Width="476"&gt;</pre>
<pre>    &lt;ListBox.ItemTemplate&gt;
        &lt;DataTemplate&gt;
           &lt;StackPanel Orientation="Horizontal" Height="132"&gt;
              &lt;Image Source="{Binding ImageSource}" Height="73" Width="73" VerticalAlignment="Top" Margin="0,10,8,0"/&gt;
              &lt;StackPanel Width="370"&gt;
                 &lt;TextBlock Text="{Binding UserName}" Foreground="#FFC8AB14" FontSize="28" /&gt;
                 &lt;TextBlock Text="{Binding Message}" TextWrapping="Wrap" FontSize="24" /&gt;
              &lt;/StackPanel&gt;
           &lt;/StackPanel&gt;
        &lt;/DataTemplate&gt;
     &lt;/ListBox.ItemTemplate&gt;</pre>
<pre>&lt;/ListBox&gt;</pre>
</blockquote>
<p>Now, pressing F5 again, we are able to reuse the emulator and re-run the application. Once the application has launched, we can type in a Twitter username and press the  Button to see the results. Try my Twitter user name (scottgu) and you’ll get back a result of TwitterItems in the Listbox:</p>
<p><a href="http://weblogs.asp.net/blogs/scottgu/image_67629029.png"><img title="image" src="http://weblogs.asp.net/blogs/scottgu/image_thumb_661DF74A.png" border="0" alt="image" width="435" height="734" /></a></p>
<p>Try using the mouse (or if you have a touchscreen device your finger) to scroll the items in the Listbox – you should find that they move very fast within the emulator.  This is because the emulator is hardware accelerated – and so gives you the same fast performance that you get on the actual phone hardware.</p>
<h3><span style="text-decoration: underline;">Summary</span></h3>
<p>Silverlight and the <em><a href="http://go.microsoft.com/fwlink/?LinkID=185584">VS 2010 Tools for Windows Phone</a></em> (and the corresponding <a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=86370108-4c14-42ee-8855-226e5dd9b85b&amp;utm_source=feedburner&amp;utm_medium=feed&amp;utm_campaign=Feed:+MicrosoftDownloadCenter+(Microsoft+Download+Center)"><em>Expression Blend Tools for Windows Phone</em></a>) make building Windows Phone applications both really easy and fun. </p>
<p>At MIX this week a number of great partners (including Netflix, FourSquare, Seesmic, Shazaam, Major League Soccer, Graphic.ly, Associated Press, Jackson Fish and more) showed off some killer application prototypes they’ve built over the last few weeks.  You can watch <a href="http://live.visitmix.com/MIX10/Sessions/KEY01" target="_blank">my full day 1 keynote</a> to see them in action. I think they start to show some of the promise and potential of using Silverlight with Windows Phone 7.  I’ll be doing more blog posts in the weeks and months ahead that cover that more.</p>
<p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://developit.nu/?feed=rss2&amp;p=71</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DevTeach 2010 Recap</title>
		<link>http://developit.nu/?p=69</link>
		<comments>http://developit.nu/?p=69#comments</comments>
		<pubDate>Fri, 12 Mar 2010 11:26:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Okategoriserade]]></category>

		<guid isPermaLink="false">http://developit.nu/?p=69</guid>
		<description><![CDATA[DevTeach is finally winding down and my sessions are all done. It’s been a great conference, as always. I have been speaking at DevTeach since the second year and it’s always a great time chatting with Canadians about software development. This year I had the pleasure of kicking off the conference on Tuesday morning with [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.devteach.com/" target="_blank">DevTeach</a> is finally winding down and my sessions are all done. It’s been a great conference, as always. I have been speaking at DevTeach since the second year and it’s always a great time chatting with Canadians about software development. This year I had the pleasure of kicking off the conference on Tuesday morning with the Keynote. I did a Lap around Visual Studio 2010 and I showed fun IDE features and extensibility, showed off a couple of my favorite language enhancements, new Entity Framework 4 &amp; WCF Data Services, new WPF designer and data binding, and Silverlight and SharePoint 2010 tools. It was fun and I think people were pumped.</p>
<p>Here’s some good links to check out for VS2010:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx" target="_blank">Visual Studio 2010 and .NET Framework 4 Release Candidate</a></li>
<li><a href="http://msdn.microsoft.com/en-us/vstudio/dd441784.aspx">Visual Studio 2010 Walkthroughs</a></li>
<li><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=752CB725-969B-4732-A383-ED5740F02E93&amp;displaylang=en">Visual Studio 2010 and .NET Framework 4 Training Kit</a></li>
<li><a href="http://msdn.microsoft.com/vstudio/dd238515.aspx">Visual Studio 2010 Samples</a></li>
<li><a href="http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx">Visual Studio 2010 Product Information</a></li>
</ul>
<p>Right after the Keynote I had a session that I’ve spoken about many times before (always a crowd pleaser) on <strong>VB10 / C#4 language features</strong> which are covered in these walkthroughs, articles and videos, on MSDN:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/ee461504(VS.100).aspx">Creating and Using Dynamic Objects (C# and Visual Basic)</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/dd409610(VS.100).aspx">Embedding Types from Managed Assemblies (C# and Visual Basic)</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/dd264738(VS.100).aspx">Use Named and Optional Arguments in Office Programming (C# Programming Guide)</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/dd293646(VS.100).aspx">Create a Collection Used by a Collection Initializer</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/dd293683(VS.100).aspx">Create an Add Extension Method Used by a Collection Initializer</a></li>
<li><a href="http://msdn.microsoft.com/en-us/magazine/ee336029.aspx" target="_blank">Generic Co- and Contravariance in Visual Basic 2010</a></li>
<li><a href="http://msdn.microsoft.com/#vblang">VS 2010 VB Language Features Video Series</a></li>
<li><a href="http://msdn.microsoft.com/#c4">C# 4.0 Video Series</a></li>
</ul>
<p>I also did an off-the-cuff talk yesterday with Jon Aneja at lunch on using<strong> Open XML and XML Literals in VB </strong>to manipulate Office document formats.</p>
<ul>
<li><a href="http://blogs.msdn.com/bethmassi/archive/2009/08/17/devproconnections-article-taking-advantage-of-linq-and-xml-in-microsoft-office-2007.aspx">Article: Taking Advantage of LINQ and XML in Microsoft Office 2007</a></li>
<li><a href="http://blogs.msdn.com/bethmassi/archive/2009/09/23/mail-merging-into-a-single-word-document-using-xml-literals.aspx">Article: Mail Merging Into a Single Word Document Using XML Literals</a></li>
<li><a href="http://blogs.msdn.com/bethmassi/archive/2009/09/24/merging-text-photos-into-a-word-document-using-open-xml-sdk.aspx">Article: Merging Text &amp; Photos into a Word Document using Open XML SDK</a></li>
<li><a href="http://blogs.msdn.com/bethmassi/archive/2009/04/07/dnrtv-showing-off-the-open-xml-sdk-and-linq.aspx">Screencast: Showing off the Open XML SDK and LINQ </a></li>
<li><a href="http://blogs.msdn.com/bethmassi/archive/2009/04/20/dnrtv-more-fun-with-office-and-xml-literals.aspx">Screencast: More Fun with Office and XML Literals </a></li>
<li>Code: <a href="http://code.msdn.microsoft.com/openxmlvb">Working with Open XML in Visual Basic</a></li>
</ul>
<p>My last session was today on <strong>Building Office Productivity Solutions with Visual Studio 2010</strong> and according to the evals it went well just like my language talk. We created an OBA for good old Northwind Traders, bringing them into the 21st century. <img src='http://developit.nu/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />   I showed the new features of VS2010 that makes Office development easier focusing on RAD data binding (including WPF) and designers, ribbon and the other available designers, as well as SharePoint 2010 tools around workflow and visual web parts.</p>
<p>My main goal was to provide a real-world scenario and architecture but keep the demo code manageable and simple while also introducing folks to all the RAD designers available. This way you can take apart the sample easily and reuse just the pieces you need. Check out the code and all the articles here: <a href="http://code.msdn.microsoft.com/OBANorthwind">http://code.msdn.microsoft.com/OBANorthwind</a> and check out the <a href="http://msdn.com/vsto" target="_blank">VSTO Developer Center</a> for more awesome resources: <a href="http://msdn.com/vsto"><strong>http://msdn.com/vsto</strong></a><strong> </strong></p>
<p>Some of the new features that make Office development and deployment easier are covered in these walkthroughs:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/ee342218(VS.100).aspx">Office Programming (C# and Visual Basic)</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/ee317478(VS.100).aspx">Embedding Type Information from Microsoft Office Assemblies (C# and Visual Basic)</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/dd465290(VS.100).aspx">Deploying Multiple Office Solutions in a Single ClickOnce Installer</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/dd465291(VS.100).aspx">Copying a Document to the End User Computer after a ClickOnce Installation</a></li>
<li><a href="http://msdn.microsoft.com/en-us/vstudio/dd441784.aspx#Sharepoint">SharePoint Development in Visual Studio 2010</a></li>
</ul>
<p>Here are some pictures from the conference which was held at a really nice Microsoft facility in Mississauga</p>
]]></content:encoded>
			<wfw:commentRss>http://developit.nu/?feed=rss2&amp;p=69</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Loading XAML Workflows in WF4</title>
		<link>http://developit.nu/?p=67</link>
		<comments>http://developit.nu/?p=67#comments</comments>
		<pubDate>Sun, 07 Mar 2010 20:17:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Okategoriserade]]></category>

		<guid isPermaLink="false">http://developit.nu/?p=67</guid>
		<description><![CDATA[Most of the time I used compiled workflows in Windows Workflow Foundation 4. Its nice and easy, you design the workflow, compile it and at runtime there is a .NET type you use to create and run workflows. The main drawback is that this approach isn’t very flexible, sometimes you want to be able to [...]]]></description>
			<content:encoded><![CDATA[<p>Most of the time I used compiled workflows in Windows Workflow Foundation 4. Its nice and easy, you design the workflow, compile it and at runtime there is a .NET type you use to create and run workflows. The main drawback is that this approach isn’t very flexible, sometimes you want to be able to change your workflow definition at runtime or store it in a database so recompiling isn’t an option.</p>
<p>Fortunately we can also load a workflow from the XAML file itself and execute the resulting workflow activity. This is done using the ActivityXamlServices class that will let us load the XAML file and return an activity, to be exact it returns a DynamicActivity as a wrapper around your definition.</p>
<p>The simplest option is just to call Load() passing in the file name like this:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet">
<pre>Activity workflow = ActivityXamlServices.Load("YourWorkflow.xaml");</pre>
</div>
</div>
<p> </p>
<p>If you are using activities, or other types, from the local assembly this is going to fail though and you need a slightly more verbose way of doing thing like this:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet">
<pre>var settings = new XamlXmlReaderSettings()</pre>
<pre>{</pre>
<pre>    LocalAssembly = typeof(SendForManualApproval).Assembly</pre>
<pre>};</pre>
<pre>var reader = new XamlXmlReader("YourWorkflow.xaml", settings);</pre>
<pre>Activity workflow = ActivityXamlServices.Load(reader);</pre>
</div>
</div>
<p> </p>
<p>We need to use the XamlXmlReaderSettings to indicate what the local assembly reference in the XAML is.</p>
]]></content:encoded>
			<wfw:commentRss>http://developit.nu/?feed=rss2&amp;p=67</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
