<?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>PeterKellner.net &#187; .NET 4.0</title>
	<atom:link href="http://peterkellner.net/category/net-4-0/feed/" rel="self" type="application/rss+xml" />
	<link>http://peterkellner.net</link>
	<description>Microsoft Focused, JavaScript,HTML5 (ExtJS, SenchaTouch &#38; Windows 8 Metro)</description>
	<lastBuildDate>Fri, 11 May 2012 16:43:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Building an Sencha&#8217;s ExtJS 4.0 MVC Application With Microsoft&#8217;s ASP.NET MVC3 Series / Basics</title>
		<link>http://peterkellner.net/2011/11/04/building-an-senchas-extjs-4-0-mvc-application-with-microsofts-asp-net-mvc3-series-basics/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=building-an-senchas-extjs-4-0-mvc-application-with-microsofts-asp-net-mvc3-series-basics</link>
		<comments>http://peterkellner.net/2011/11/04/building-an-senchas-extjs-4-0-mvc-application-with-microsofts-asp-net-mvc3-series-basics/#comments</comments>
		<pubDate>Fri, 04 Nov 2011 18:47:01 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[MVC3]]></category>
		<category><![CDATA[Sencha]]></category>
		<category><![CDATA[SenchaMVC]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/11/04/building-an-senchas-extjs-4-0-mvc-application-with-microsofts-asp-net-mvc3-series-basics/</guid>
		<description><![CDATA[


Part 1 (this)
Basics (mostly server side)


Part 2
ExtJS Client Side Details



&#160;
Introduction

If you have a problem like this involving ASP.NET or Sencha Tools, more information about our consulting services are here


In this series of articles, we will take the reference application build by the Sencha product team for using Sencha’s MVC pattern running with an ASP.NET 4.0 [...]]]></description>
			<content:encoded><![CDATA[<table width="362" border="1" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td valign="top" width="199">Part 1 (this)</td>
<td valign="top" width="161"><a href="http://peterkellner.net/2011/11/04/building-an-senchas-extjs-4-0-mvc-application-with-microsofts-asp-net-mvc3-series-basics/">Basics (mostly server side)</a></td>
</tr>
<tr>
<td valign="top" width="219">Part 2</td>
<td valign="top" width="170"><a href="http://peterkellner.net/2012/04/20/details-on-the-extjs-application-to-build-simple-crud-operation-using-models-and-stores/">ExtJS Client Side Details</a></td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>Introduction</p>
<div>
<div class="peterkellnerpromo"><a href="http://peterkellner.net/open-source-javascript-extjs-and-jquery/" target="_blank">If you have a problem like this involving ASP.NET or Sencha Tools, more information about our consulting services are here</a></div>
</div>
<div>
<p>In this series of articles, we will take the reference application build by the <a href="http://sencha.com">Sencha</a> product team for using <a href="http://www.sencha.com/learn/the-mvc-application-architecture/">Sencha’s MVC pattern</a> running with an ASP.NET 4.0 project (IIS in production).  The first article takes the reference Sencha MVC app and with almost no changes, makes it work with the ASP.NET <a href="http://www.microsoft.com/visualstudio/en-us">Visual Studio 2010</a> project.  By default, the application works with <a href="http://json.org">JSON</a> static files.  We change that to work with an <a href="http://www.asp.net/mvc/mvc3">ASP.NET MVC3 project</a>.  The second article in the series embellishes the application to include a more real user experience by adding additional functionality and data.  The improved functionality includes both date and number columns as well as paging.  It also adds functionality for inserts and deletes which are left out of the base app from Sencha.</p>
</div>
<div></div>
<div></div>
<div id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:18f8ad45-378a-4ee5-ba60-cc46b12c93f8" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<p>Visual Studio Project <a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/11/SenchaDesignerExtension3.zip" target="_blank">SenchaMVCASPNetSolution</a></p>
</div>
<p>&nbsp;</p>
<h2>The Final Project when running:</h2>
<p>&nbsp;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/11/image1.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/11/image_thumb1.png" alt="image" width="461" height="323" border="0" /></a></p>
<p>&nbsp;</p>
<p><span id="more-1634"></span></p>
<p>&nbsp;</p>
<h2>What Is Sencha’s MVC Application</h2>
<p>I don’t want to spend a lot of time here explaining what Sencha does really well in there article but I feel a short explanation is helpful  (<a href="http://www.sencha.com/learn/the-mvc-application-architecture/">http://www.sencha.com/learn/the-mvc-application-architecture/</a>).</p>
<p>So, here we go.  Basically ExtJS is a client side JavaScript framework which allows you to build the full user experience in JavaScript.  That is, all the grids, forms, tabs, etc. are all generated by a client side JavaScript library.  All that goes up and down from the server is JSON (after the JavaScript framework and code and assets are downloaded).  This means that on the client side, all the code for displaying a grid for example, reaching out for data, pushing data changes, etc. all need to be done on the client (browser).  Sencha’s ExtJS MVC pattern helps organize all these functions into a set of directories and functions that make building apps scalable.</p>
<p>Below is what Sencha’s app in Visual Studio looks like:</p>
<p>&nbsp;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/11/image2.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/11/image_thumb2.png" alt="image" width="212" height="310" border="0" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h2>ASP.NET Implementation</h2>
<p>The major change to the stock MVC app from Sencha is to change there Store class.  Here is the new Store Class.</p>
<p>&nbsp;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/11/image3.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/11/image_thumb3.png" alt="image" width="223" height="161" border="0" /></a></p>
<p>And the JavaScript itself:</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">var</span> writer = <span style="color: #0000ff;">new</span> Ext.data.JsonWriter({</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060;"> 2:</span>     type: <span style="color: #006080;">'json'</span>,</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060;"> 3:</span>     encode: <span style="color: #0000ff;">false</span>,</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060;"> 4:</span>     listful: <span style="color: #0000ff;">true</span>,</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060;"> 5:</span>     writeAllFields: <span style="color: #0000ff;">true</span>,</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum6" style="color: #606060;"> 6:</span>     returnJson: <span style="color: #0000ff;">true</span></pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum7" style="color: #606060;"> 7:</span> });</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum8" style="color: #606060;"> 8:</span></pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #0000ff;">var</span> reader = <span style="color: #0000ff;">new</span> Ext.data.JsonReader({</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum10" style="color: #606060;"> 10:</span>     totalProperty: <span style="color: #006080;">'total'</span>,</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum11" style="color: #606060;"> 11:</span>     successProperty: <span style="color: #006080;">'success'</span>,</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum12" style="color: #606060;"> 12:</span>     idProperty: <span style="color: #006080;">'Id'</span>,</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum13" style="color: #606060;"> 13:</span>     root: <span style="color: #006080;">'Data'</span>,</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum14" style="color: #606060;"> 14:</span>     messageProperty: <span style="color: #006080;">'message'</span></pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum15" style="color: #606060;"> 15:</span> });</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum16" style="color: #606060;"> 16:</span></pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum17" style="color: #606060;"> 17:</span> <span style="color: #0000ff;">var</span> proxy = <span style="color: #0000ff;">new</span> Ext.data.HttpProxy({</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum18" style="color: #606060;"> 18:</span>     reader: reader,</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum19" style="color: #606060;"> 19:</span>     writer: writer,</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum20" style="color: #606060;"> 20:</span>     type: <span style="color: #006080;">'ajax'</span>,</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum21" style="color: #606060;"> 21:</span>     api: {</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum22" style="color: #606060;"> 22:</span>         read: <span style="color: #006080;">'/UserInfo/Get'</span>,</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum23" style="color: #606060;"> 23:</span>         create: <span style="color: #006080;">'/UserInfo/Create'</span>,</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum24" style="color: #606060;"> 24:</span>         update: <span style="color: #006080;">'/UserInfo/Update'</span>,</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum25" style="color: #606060;"> 25:</span>         destroy: <span style="color: #006080;">'/UserInfo/Delete'</span></pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum26" style="color: #606060;"> 26:</span>     },</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum27" style="color: #606060;"> 27:</span>     headers: {</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum28" style="color: #606060;"> 28:</span>         <span style="color: #006080;">'Content-Type'</span>: <span style="color: #006080;">'application/json; charset=UTF-8'</span></pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum29" style="color: #606060;"> 29:</span>     }</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum30" style="color: #606060;"> 30:</span> });</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum31" style="color: #606060;"> 31:</span></pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum32" style="color: #606060;"> 32:</span> Ext.define(<span style="color: #006080;">'AM.store.Users'</span>, {</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum33" style="color: #606060;"> 33:</span>     extend: <span style="color: #006080;">'Ext.data.Store'</span>,</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum34" style="color: #606060;"> 34:</span>     model: <span style="color: #006080;">'AM.model.User'</span>,</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum35" style="color: #606060;"> 35:</span>     autoLoad: <span style="color: #0000ff;">true</span>,</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum36" style="color: #606060;"> 36:</span>     paramsAsHash: <span style="color: #0000ff;">true</span>,</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum37" style="color: #606060;"> 37:</span>     proxy: proxy</pre>
<p>&nbsp;</p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum38" style="color: #606060;"> 38:</span> });</pre>
<p>&nbsp;</p>
</div>
</div>
<p>&nbsp;</p>
<p>The primary change is to the reader.  Notice that the API’s are defined now to point the ASP.NET controller UserInfo.  Also, the column names have been changed to start with uppercase to be consistent with public properties in ASP.NET.  That is, id,name and email are now Id,Name and Email.</p>
<p>&nbsp;</p>
<p>Now, we need to implement the controller on the ASP.NET.  Basically, we implement GET on the read and POST on the write.  The controller class in c# is as follows: (Visual Studio Solution Explorer first, then the controller code itself)</p>
<p>&nbsp;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/11/image4.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/11/image_thumb4.png" alt="image" width="244" height="156" border="0" /></a></p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> UserInfoController : Controller{    <span style="color: #0000ff;">public</span> JsonResult Get(<span style="color: #0000ff;">int</span>? start, <span style="color: #0000ff;">int</span>? limit)    {        <span style="color: #0000ff;">using</span> (var db = <span style="color: #0000ff;">new</span> Db())        {            start = start.HasValue ? start.Value : 0;            limit = limit.HasValue ? limit.Value : Int32.MaxValue;            <span style="color: #0000ff;">int</span> cnt = db.Users.Count();            var recs = db.Users.OrderBy(a =&gt; a.Id).                Skip(start.Value).Take(limit.Value).ToList();            <span style="color: #0000ff;">return</span> Json(<span style="color: #0000ff;">new</span>                            {                                Data = recs,                                total = cnt                            }, JsonRequestBehavior.AllowGet);        }    }

    [HttpPost]    <span style="color: #0000ff;">public</span> JsonResult Update(UserInfo data)    {        <span style="color: #0000ff;">bool</span> success = <span style="color: #0000ff;">false</span>;        <span style="color: #0000ff;">string</span> message = <span style="color: #006080;">"no record found"</span>;        <span style="color: #0000ff;">if</span> (data != <span style="color: #0000ff;">null</span> &amp;&amp; data.Id &gt; 0)        {            <span style="color: #0000ff;">using</span> (var db = <span style="color: #0000ff;">new</span> Db())            {                var rec = db.Users.Where(a =&gt; a.Id == data.Id).                    FirstOrDefault();                rec.Name = data.Name;                rec.Email = data.Email;                db.SaveChanges();                success = <span style="color: #0000ff;">true</span>;                message = <span style="color: #006080;">"Update method called successfully"</span>;            }        }

        <span style="color: #0000ff;">return</span> Json(<span style="color: #0000ff;">new</span>                        {                            data,                            success,                            message                        });    }}</pre>
</div>
<p>&nbsp;</p>
<p>Notice that the Get method returns a JsonResult.  This conveniently returns the data in JSON format.  Part of the secret sauce here is in the Db().  This app used Microsoft’s new EntityFamework CodeFirst. Following the standard CodeFirst model, we implement the simple c# code and it automagically creates the data tables (and data) in the database (my example uses SqlServer CE because it can be run without installing any database on your windows computer, the code is all in-memory).</p>
<p>If we look at the Model on the ASP.NET MVC3 side, you’ll notice the c# attributes and the DbContext that do the magic for you.  There are some excellent getting started guides on the web including one from <a href="http://thedatafarm.com/blog/">Julie Lerman</a> (walk through video: <a title="http://msdn.microsoft.com/en-us/data/gg715119" href="http://msdn.microsoft.com/en-us/data/gg715119">http://msdn.microsoft.com/en-us/data/gg715119</a> and <a title="http://msdn.microsoft.com/en-us/data/gg685467" href="http://msdn.microsoft.com/en-us/data/gg685467">http://msdn.microsoft.com/en-us/data/gg685467</a> ).</p>
<p>Here is the Visual Studio Solution Explorer for the model:</p>
<p>&nbsp;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/11/image5.png"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/11/image_thumb5.png" alt="image" width="224" height="244" border="0" /></a></p>
<p>&nbsp;</p>
<p>and here is the model code in c#:</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">namespace</span> SenchaDesignerExtension.Models{    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> UserInfo    {        [Key]        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">int</span> Id { get; set; }

        [MaxLengthAttribute(256)]        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">string</span> Email { get; set; }

        [MaxLengthAttribute(256)]        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">string</span> Name { get; set; }

    } }</pre>
</div>
<p>&nbsp;</p>
<p>and the actual repository which is in the file DbContext.cs (screen shot for brevity below, the code is attached in the example.</p>
<p>&nbsp;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/11/image6.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/11/image_thumb6.png" alt="image" width="462" height="279" border="0" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/11/04/building-an-senchas-extjs-4-0-mvc-application-with-microsofts-asp-net-mvc3-series-basics/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Need To Get Static JSON File with POST verb on IIS 7.5?</title>
		<link>http://peterkellner.net/2011/10/30/need-to-get-static-json-file-with-post-verb-on-iis-7-5/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=need-to-get-static-json-file-with-post-verb-on-iis-7-5</link>
		<comments>http://peterkellner.net/2011/10/30/need-to-get-static-json-file-with-post-verb-on-iis-7-5/#comments</comments>
		<pubDate>Mon, 31 Oct 2011 01:36:18 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[ASP.NET 4.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Handler]]></category>
		<category><![CDATA[Web.Config]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/10/30/need-to-get-static-json-file-with-post-verb-on-iis-7-5/</guid>
		<description><![CDATA[Normally, when we stick a JSON file up on an IIS web server, all we have to do to get to is is to set the Mime type.&#160; One easy way to do it is to add to your web.config the following:
&#160;

&#60;system.webServer&#62;    &#60;validation validateIntegratedModeConfiguration=&#34;false&#34; /&#62;    &#60;modules runAllManagedModulesForAllRequests=&#34;true&#34; /&#62;  [...]]]></description>
			<content:encoded><![CDATA[<p>Normally, when we stick a JSON file up on an IIS web server, all we have to do to get to is is to set the Mime type.&#160; One easy way to do it is to add to your web.config the following:</p>
<p>&#160;</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">&lt;</span><span style="color: #800000">system.webServer</span><span style="color: #0000ff">&gt;</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">validation</span> <span style="color: #ff0000">validateIntegratedModeConfiguration</span><span style="color: #0000ff">=&quot;false&quot;</span> <span style="color: #0000ff">/&gt;</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">modules</span> <span style="color: #ff0000">runAllManagedModulesForAllRequests</span><span style="color: #0000ff">=&quot;true&quot;</span> <span style="color: #0000ff">/&gt;</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">staticContent</span><span style="color: #0000ff">&gt;</span>      <span style="color: #0000ff">&lt;</span><span style="color: #800000">mimeMap</span> <span style="color: #ff0000">fileExtension</span><span style="color: #0000ff">=&quot;.json&quot;</span> <span style="color: #ff0000">mimeType</span><span style="color: #0000ff">=&quot;application/json&quot;</span>  <span style="color: #0000ff">/&gt;</span>    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">staticContent</span><span style="color: #0000ff">&gt;</span>    ...</pre>
<p></div>
<p>&#160;</p>
<p>This works great as long as the GET verb is used (or just enter the on the url like http://mysite.com/myfile.json).</p>
<p>So, what if you &quot;need” to use the POST keyword.&#160; Say for example, you can not change the JavaScript file to use GET instead of POST to get the file.&#160; I was hoping to find some simple web.config parameter to set but I had no luck.&#160; I even <a href="http://stackoverflow.com/questions/7943270/how-to-serve-json-files-from-iis7-when-request-is-post">posted to StackOverflow</a> and so far, the answers have been less than helpful.&#160; Who knows, maybe by the time you read this, there will be a better answer then my solution which is to write a simple asp.net handler and register it to type <a href="http://json.org">json</a>.</p>
<p>&#160;</p>
<p>So, here is the simpler handler that does the trick:</p>
<p>&#160;</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> JSONHandler : IHttpHandler    {

        <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> ProcessRequest(HttpContext context)        {            context.Response.ContentType = <span style="color: #006080">&quot;application/json&quot;</span>;            <span style="color: #0000ff">string</span> output = System.IO.File.ReadAllText(context.Request.PhysicalPath);            context.Response.Write(output);

        }

        <span style="color: #0000ff">public</span> <span style="color: #0000ff">bool</span> IsReusable        {            get            {                <span style="color: #0000ff">return</span> <span style="color: #0000ff">false</span>;            }        }    }</pre>
<p></div>
<p>&#160;</p>
<p>and the associated web.config entries</p>
<p>&#160;</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">&lt;httpHandlers&gt;     &lt;add verb=<span style="color: #006080">&quot;*&quot;</span> path=<span style="color: #006080">&quot;*.json&quot;</span> validate=<span style="color: #006080">&quot;false&quot;</span> type=<span style="color: #006080">&quot;JSONHandler&quot;</span> /&gt;   &lt;/httpHandlers&gt; &lt;/system.web&gt;

 &lt;system.webServer&gt;   &lt;validation validateIntegratedModeConfiguration=<span style="color: #006080">&quot;false&quot;</span> /&gt;   &lt;modules runAllManagedModulesForAllRequests=<span style="color: #006080">&quot;true&quot;</span> /&gt;   &lt;staticContent&gt;     &lt;mimeMap fileExtension=<span style="color: #006080">&quot;.json&quot;</span> mimeType=<span style="color: #006080">&quot;application/json&quot;</span>  /&gt;   &lt;/staticContent&gt;   &lt;handlers&gt;     &lt;add verb=<span style="color: #006080">&quot;*&quot;</span> path=<span style="color: #006080">&quot;*.json&quot;</span> name=<span style="color: #006080">&quot;JSONHandler&quot;</span> type=<span style="color: #006080">&quot;JSONHandler&quot;</span>/&gt;   &lt;/handlers&gt; &lt;/system.webServer&gt;</pre>
<p></div>
<p>I’m assuming there is a simple way, but for now, this works for me.&#160; Please post a better solution and reference it or just tell me in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/10/30/need-to-get-static-json-file-with-post-verb-on-iis-7-5/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Microsoft To Add Auto-Compiled LINQ Queries to Entity Framework V.Next!</title>
		<link>http://peterkellner.net/2011/10/22/microsoft-to-add-auto-compiled-linq-queries-to-entity-framework-v-next/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=microsoft-to-add-auto-compiled-linq-queries-to-entity-framework-v-next</link>
		<comments>http://peterkellner.net/2011/10/22/microsoft-to-add-auto-compiled-linq-queries-to-entity-framework-v-next/#comments</comments>
		<pubDate>Sun, 23 Oct 2011 01:57:03 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[.NET 4.5]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[LINQ to SQL]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/10/22/microsoft-to-add-auto-compiled-linq-queries-to-entity-framework-v-next/</guid>
		<description><![CDATA[&#160;
In May of 2009 I discovered some significant performance problems that I blogged about.&#160; In summary, I had tracked it down to the issue of LINQ2SQ having to create a full expression tree on every instantiation of a LINQ2SQL query.&#160; I’m not a compiler write kind of guy but do respect the complexity of that [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>In May of 2009 I discovered some significant performance problems that I <a href="http://peterkellner.net/2009/05/06/linq-to-sql-slow-performance-compilequery-critical/">blogged</a> about.&#160; In summary, I had tracked it down to the issue of LINQ2SQ having to create a full expression tree on every instantiation of a LINQ2SQL query.&#160; I’m not a compiler write kind of guy but do respect the complexity of that and doing things like building expression trees, but still this really sucked.&#160; Using the compile syntax in LINQ2SQL is very awkward, and IMHO takes all the fun out of using LINQ2SQL.&#160; If you don’t remember my post, here is the graph showing the evil happening.</p>
<p>&#160;</p>
<p><a href="http://peterkellner.net/2009/05/06/linq-to-sql-slow-performance-compilequery-critical/"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/10/image6.png" width="285" height="173" /></a></p>
<p>So, what is a Microsoft MVP to do?&#160; I complained to everyone at Microsoft I knew.&#160; I made this my mission for about a year.&#160; I was told time after time that the problem was hugely complicated and no one was working on making it any faster.&#160; I just could not believe it because I felt this was such a barrier to success to <a href="http://msdn.microsoft.com/en-us/library/bb425822.aspx">LINQ2SQL</a> type technology (now <a href="http://msdn.microsoft.com/en-us/library/bb399572.aspx">Entity Framework</a> really) that Microsoft just could not ignore my findings.&#160; I was actually surprised that I was the only one screaming about this.</p>
<p>Well, quietly, <a href="http://blogs.msdn.com/b/adonet/archive/2011/10/18/how-we-talk-about-ef-and-its-future-versions.aspx">Microsoft has announced that in .Net Framework 4.5, Entity Framework will include “Auto-Compiled LINQ Queries”</a>.&#160; This is awesome!&#160;&#160; When it comes out, I’ll be testing and it giving feedback.</p>
<p>For now, I’m a very happy camper.</p>
<p>&#160;</p>
<p><a href="http://blogs.msdn.com/b/adonet/archive/2011/10/18/how-we-talk-about-ef-and-its-future-versions.aspx"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/10/image7.png" width="882" height="474" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/10/22/microsoft-to-add-auto-compiled-linq-queries-to-entity-framework-v-next/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Silicon Valley Code Camp Login Failing with IE10 (Fixed Now)</title>
		<link>http://peterkellner.net/2011/09/20/silicon-valley-code-camp-login-failing-with-ie10-fixed-now/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=silicon-valley-code-camp-login-failing-with-ie10-fixed-now</link>
		<comments>http://peterkellner.net/2011/09/20/silicon-valley-code-camp-login-failing-with-ie10-fixed-now/#comments</comments>
		<pubDate>Tue, 20 Sep 2011 17:10:29 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[ASP.NET 4.0]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/09/20/silicon-valley-code-camp-login-failing-with-ie10-fixed-now/</guid>
		<description><![CDATA[&#160;
Scott Hanselman posted a while back about a browsers definition problem with some ASP.NET sites that causes problems.&#160; Microsoft has articles on this also.&#160; Having just received my BUILD tablet that includes IE10, I tested the Silicon Valley Code Camp web site and discovered that when you login, then switch to another page, the login [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p><a href="http://www.hanselman.com/blog/BugAndFixASPNETFailsToDetectIE10CausingDoPostBackIsUndefinedJavaScriptErrorOrMaintainFF5ScrollbarPosition.aspx">Scott Hanselman posted</a> a while back about a browsers definition problem with some ASP.NET sites that causes problems.&#160; Microsoft has <a href="http://support.microsoft.com/kb/2600088">articles</a> on this also.&#160; Having just received my <a href="http://www.buildwindows.com/">BUILD</a> tablet that includes IE10, I tested the <a href="http://www.siliconvalley-codecamp.com/">Silicon Valley Code Camp web site</a> and discovered that when you login, then switch to another page, the login did not stick.&#160; After uploading the two files Scott mentions (<a href="http://msdn.microsoft.com/en-us/library/ms228122.aspx">firefox.browser and ie.browser</a>), the problem goes away.</p>
<p>Thanks Scott for the heads up.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image3.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image_thumb2.png" width="657" height="350" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/09/20/silicon-valley-code-camp-login-failing-with-ie10-fixed-now/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using ASP.NET Web Forms, Passing Primary Key to RowCommand Event</title>
		<link>http://peterkellner.net/2011/09/05/using-asp-net-web-forms-passing-primary-key-to-rowcommand-event/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-asp-net-web-forms-passing-primary-key-to-rowcommand-event</link>
		<comments>http://peterkellner.net/2011/09/05/using-asp-net-web-forms-passing-primary-key-to-rowcommand-event/#comments</comments>
		<pubDate>Mon, 05 Sep 2011 15:01:54 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[DataBinding]]></category>
		<category><![CDATA[GridView]]></category>
		<category><![CDATA[WebForms]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/09/05/using-asp-net-web-forms-passing-primary-key-to-rowcommand-event/</guid>
		<description><![CDATA[&#160;
I know this is old hat, but after recently having a conversation with one of the ASP.NET Team guys about how easy Web Forms is to use, I thought I’d just post a simple example of that.&#160; Here is the scenario.&#160; You have a simple GridView with just three columns (Select,Id,TagName).&#160; You want to be [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>I know this is old hat, but after recently having a conversation with one of the <a href="http://www.asp.net/">ASP.NET</a> Team guys about how easy <a href="http://www.asp.net/web-forms">Web Forms</a> is to use, I thought I’d just post a simple example of that.&#160; Here is the scenario.&#160; You have a simple <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.aspx">GridView</a> with just three columns (Select,Id,TagName).&#160; You want to be able to capture what happens when the user pressed the Select command and capture the Id.&#160; It looks like this:</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image1.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image_thumb.png" width="196" height="244" /></a></p>
<p>&#160;</p>
<p>And has an aspx page like this:</p>
<p>&#160;</p>
<div id="codeSnippetWrapper">
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:GridView</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">=&quot;GridViewNotSelected&quot;</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span> <span style="color: #ff0000">AllowSorting</span><span style="color: #0000ff">=&quot;True&quot;</span>         <span style="color: #ff0000">AutoGenerateColumns</span><span style="color: #0000ff">=&quot;False&quot;</span>         <span style="color: #ff0000">DataSourceID</span><span style="color: #0000ff">=&quot;SqlDataSourceTagsNotSelected&quot;</span>         <span style="color: #ff0000">onrowcommand</span><span style="color: #0000ff">=&quot;GridViewNotSelected_RowCommand&quot;</span><span style="color: #0000ff">&gt;</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">Columns</span><span style="color: #0000ff">&gt;</span>        <span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:TemplateField</span> <span style="color: #ff0000">ShowHeader</span><span style="color: #0000ff">=&quot;False&quot;</span><span style="color: #0000ff">&gt;</span>            <span style="color: #0000ff">&lt;</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">&gt;</span>                <span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:LinkButton</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">=&quot;LinkButton1&quot;</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span>                     <span style="color: #ff0000">CausesValidation</span><span style="color: #0000ff">=&quot;False&quot;</span> <span style="color: #ff0000">CommandArgument</span><span style="color: #0000ff">='&lt;%# Eval(&quot;Id&quot;) %&gt;'</span>                    <span style="color: #ff0000">CommandName</span><span style="color: #0000ff">=&quot;Select&quot;</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">=&quot;Select&quot;</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">asp:LinkButton</span><span style="color: #0000ff">&gt;</span>            <span style="color: #0000ff">&lt;/</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">&gt;</span>        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">asp:TemplateField</span><span style="color: #0000ff">&gt;</span>        <span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:TemplateField</span>             <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">=&quot;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&quot;</span><span style="color: #0000ff">&gt;</span>        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">asp:TemplateField</span><span style="color: #0000ff">&gt;</span>        <span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:TemplateField</span><span style="color: #0000ff">&gt;</span>            <span style="color: #0000ff">&lt;</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">&gt;</span>                <span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:Label</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">=&quot;Label1&quot;</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">='&lt;%# Eval(&quot;TagName&quot;) %&gt;'</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">asp:Label</span><span style="color: #0000ff">&gt;</span>            <span style="color: #0000ff">&lt;/</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">&gt;</span>        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">asp:TemplateField</span><span style="color: #0000ff">&gt;</span>    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Columns</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">asp:GridView</span><span style="color: #0000ff">&gt;</span></pre>
<p></div>
<p></div>
<p>Notice that in the <a href="http://weblogs.asp.net/scottgu/archive/2006/06/04/Supporting-Templates-with-ASP.NET-User-Controls.aspx">TemplateField</a> there is LinkButton with a <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.commandargument.aspx">CommandArgument</a> that simply extracts the TagName with the current Id of the <a href="http://msdn.microsoft.com/en-us/library/dz12d98w.aspx">SqlDataSource</a>.&#160; Now, all you need is the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx">RowCommand</a> event and you are done.&#160; Here it is in <a href="http://msdn.microsoft.com/en-us/vcsharp/aa336706">C#.</a></p>
<p>&#160;</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> GridViewNotSelected_RowCommand(<span style="color: #0000ff">object</span> sender, GridViewCommandEventArgs e){    <span style="color: #0000ff">int</span> tagsId = Convert.ToInt32(e.CommandArgument);}</pre>
<p></div>
<p>And finally, the proof!</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image2.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image_thumb1.png" width="627" height="118" /></a></p>
<p>&#160;</p>
<p>Very very simple.&#160; HTH’s.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/09/05/using-asp-net-web-forms-passing-primary-key-to-rowcommand-event/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My First Experience With SqlServer CE 4.0</title>
		<link>http://peterkellner.net/2011/09/02/my-first-experience-with-sqlserver-ce-4-0/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=my-first-experience-with-sqlserver-ce-4-0</link>
		<comments>http://peterkellner.net/2011/09/02/my-first-experience-with-sqlserver-ce-4-0/#comments</comments>
		<pubDate>Fri, 02 Sep 2011 15:57:43 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Sql Server 2008]]></category>
		<category><![CDATA[Sql Server CE]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/09/02/my-first-experience-with-sqlserver-ce-4-0/</guid>
		<description><![CDATA[I have heard all the hype about how great Sql Server CE 4.0 and that it is now standard with Visual Studio 2010 SP1.
&#160;

&#160;
I’ve got a small project (1 table) that I’d like to include in an asp.net website project so I decided to give it a try.&#160; For the most part, things have gone [...]]]></description>
			<content:encoded><![CDATA[<p>I have heard all the hype about how great <a href="http://www.microsoft.com/sqlserver/en/us/default.aspx">Sql Server CE 4.0</a> and that it is now standard with <a href="http://support.microsoft.com/kb/983509">Visual Studio 2010 SP1</a>.</p>
<p>&#160;</p>
<p><a href="http://weblogs.asp.net/scottgu/archive/2011/01/11/vs-2010-sp1-and-sql-ce.aspx"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image.png" width="592" height="185" /></a></p>
<p>&#160;</p>
<p>I’ve got a small project (1 table) that I’d like to include in an asp.net website project so I decided to give it a try.&#160; For the most part, things have gone smoothly, however I did have a couple hiccups I’d like to mention.&#160; One cost me <a href="http://www.gogoair.com/gogo/splash.do">$9</a> because I was doing this implementation on an airplane and immediately, I had a failed connection with a confusing error that I needed Bing to lookup&#160; (more details below).</p>
<p>&#160;</p>
<p>  <span id="more-1559"></span><br />
<h2>Method Names Changed</h2>
<p>&#160;</p>
<p>I have to wonder why Microsoft decided to change the names of the methods in ADO.NET.&#160; Seems to me that all the names should be the same whether I’m using Sql Server, Sql Server Express or Sql Server CE.&#160; My expectation was that the statement:</p>
<div id="codeSnippetWrapper">&#160;</div>
<div>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">using</span> (<span style="color: #0000ff">var</span> connection = <span style="color: #0000ff">new</span> SqlConnection(testDataContext.ConnectionString)) {..</pre>
</div>
<div>&#160;</div>
<div>would work correctly, however, I get the very misleading (or at least unhelpful) error:</div>
<div>&#160;</div>
<h4><i>A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 &#8211; Error Locating Server/Instance Specified)</i></h4>
<div>&#160;</div>
<div>It turns out, you need to open the connection like this:</div>
<div>&#160;</div>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">using</span> (<span style="color: #0000ff">var</span> connection = <span style="color: #0000ff">new</span> SqlCeConnection(connectionString)) {...</pre>
<p></div>
<p>And things now work (my connection string is actually what I’ve pasted below).</p>
<p>&#160;</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">&lt;</span><span style="color: #800000">connectionStrings</span><span style="color: #0000ff">&gt;</span>  <span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;ConnectionStringMxMessage&quot;</span> <span style="color: #ff0000">connectionString</span><span style="color: #0000ff">=&quot;Data Source=|DataDirectory|\MxMessageDb.sdf&quot;</span>       <span style="color: #ff0000">providerName</span><span style="color: #0000ff">=&quot;System.Data.SqlServerCe.4.0&quot;</span> <span style="color: #0000ff">/&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">connectionStrings</span><span style="color: #0000ff">&gt;</span></pre>
<p></div>
<p>Bottomline, all ado.net commands need the Ce in them.</p>
<p>&#160;</p>
<p>&#160;</p>
<h2>Getting Identity Column After Insert Fails</h2>
<p>&#160;</p>
<p>My expectation is that what has worked for a very long time in Sql Server for me should work in Sql Server CE.&#160; The most simple pattern of inserting a row and getting back the value of the identity column does not work the same.&#160; My original code looks like this (which fails):</p>
<p>&#160;</p>
<div id="codeSnippetWrapper">
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">using (var connection = new SqlCeConnection(testDataContext.ConnectionString))    {        connection.Open();        using (var sqlCeCommand =            new SqlCeCommand(                &quot;INSERT INTO message (Name, Subject, Header, Body, Footer) Values                     (@Name);SELECT @@IDENTITY&quot;,                connection))        {            sqlCeCommand.Parameters.Add(&quot;@Name&quot;, SqlDbType.NVarChar).Value = Name;            // problem, need to do separate select to get this to work            sqlCeCommand.Parameters.Add                (new SqlCeParameter(&quot;@IDENTITY&quot;, SqlDbType.Int)                                            {                                                Direction =                                                    ParameterDirection.Output                                            });

            using (var reader = sqlCeCommand.ExecuteReader())            {                while (reader.Read())                {                    message.Id = reader.IsDBNull(0) ? 0 :                       Convert.ToInt32(reader.GetDecimal(0));                }            }        }    }}</pre>
<p></div>
<p></div>
<p>To fix it, it seems that you can not send two sql commands on the same execution (separated by semicolon).&#160; That is, after the first command (without the SELECT @@IDENTITY) you need to do another SqlCeCommand as follows:</p>
<p>&#160;</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">using (var sqlCeCommand2 =    new SqlCeCommand(        &quot;SELECT @@IDENTITY&quot;,        connection)){    message.Id = Convert.ToInt32(sqlCeCommand2.ExecuteScalar());}</pre>
</div>
<h2>
<p>&#160;</p>
<p>Conclusions</p>
</h2>
<p>Well, things are working, but I have not done much and I’ve had a couple of stumbles.&#160; Hopefully I’m done with stumbling for now.</p>
<div>
  </div>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/09/02/my-first-experience-with-sqlserver-ce-4-0/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Getting ExtJS 4 Date Format To Behave Properly in Grid Panel with ASP.NET MVC3</title>
		<link>http://peterkellner.net/2011/08/24/getting-extjs-4-date-format-to-behave-properly-in-grid-panel-with-asp-net-mvc3/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=getting-extjs-4-date-format-to-behave-properly-in-grid-panel-with-asp-net-mvc3</link>
		<comments>http://peterkellner.net/2011/08/24/getting-extjs-4-date-format-to-behave-properly-in-grid-panel-with-asp-net-mvc3/#comments</comments>
		<pubDate>Wed, 24 Aug 2011 18:52:44 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[DateFormat]]></category>
		<category><![CDATA[MVC3]]></category>
		<category><![CDATA[Sencha]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/08/24/getting-extjs-4-date-format-to-behave-properly-in-grid-panel-with-asp-net-mvc3/</guid>
		<description><![CDATA[&#160;
Introduction and Problem
Converting Data Formats back and forth between browser and back end servers can be a little confusing.&#160; In my case, I have a simple Sencha&#160;ExtJS 4.0 form that the user types a date into.&#160; That date gets passed through an ajax request to the Microsoft asp.net controller, then that dates updates the SqlServer [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<h3>Introduction and Problem</h3>
<p>Converting Data Formats back and forth between browser and back end servers can be a little confusing.&#160; In my case, I have a simple <a href="http://www.sencha.com/">Sencha</a>&#160;<a href="http://www.sencha.com/products/extjs/">ExtJS 4.0</a> form that the user types a date into.&#160; That date gets passed through an <a href="http://www.w3schools.com/ajax/default.asp">ajax request</a> to the <a href="http://www.microsoft.com/en-us/default.aspx">Microsoft</a> <a href="http://www.asp.net/">asp.net</a> <a href="http://www.asp.net/mvc/mvc3">controller</a>, then that dates updates the <a href="http://en.wikipedia.org/wiki/Microsoft_SQL_Server">SqlServer</a> Database.&#160; When the Date is displayed on a Grid Panel, again, an ajax request is made that grabs the date from the controller, then formats it using the MS <a href="http://dev.sencha.com/deploy/ext-4.0.2a/docs/#/api/Ext.data.Field-cfg-dateFormat">dateFormat</a> from ExtJS and hopefully, the same date the user typed in gets re-displayed.</p>
<div>
<div class="peterkellnerpromo"><a href="http://peterkellner.net/open-source-javascript-extjs-and-jquery/" target="_blank">If you have a problem like this involving ASP.NET or Sencha Tools (ExtJS, SenchaTouch), more information about our consulting services are <span>here.</span></a></div>
</div>
<p>So, let’s look at the details.</p>
<h3>Posting the Date To the Server (View From JavaScript)</h3>
<p>First, we need to define an ExtJS Model that has the date in it.&#160; That codes looks like this in my case.</p>
<p><span id="more-1556"></span></p>
<p>&#160;</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">Ext.define(<span style="color: #006080">'EvMgr.model.SponsorListJobListing'</span>, {    extend: <span style="color: #006080">'Ext.data.Model'</span>,    fields: [        <span style="color: #006080">'Id'</span>,        <span style="color: #006080">'SponsorListId'</span>,        <span style="color: #006080">'JobName'</span>,        <span style="color: #006080">'JobLocation'</span>,        <span style="color: #006080">'JobURL'</span>,        <span style="color: #006080">'JobBrief'</span>,        <span style="color: #006080">'JobTagline'</span>,        <span style="color: #006080">'JobButtonToolTip'</span>,        { name: <span style="color: #006080">'EnteredDate'</span>, type: <span style="color: #006080">'date'</span>, dateFormat: <span style="color: #006080">'MS'</span> },        <span style="color: #006080">'JobCompanyName'</span>,        { name: <span style="color: #006080">'StartRunDate'</span>, type: <span style="color: #006080">'date'</span>, dateFormat: <span style="color: #006080">'MS'</span> },        { name: <span style="color: #006080">'EndRunDate'</span>, type: <span style="color: #006080">'date'</span>, dateFormat: <span style="color: #006080">'MS'</span> },        { name: <span style="color: #006080">'HideListing'</span>, type: <span style="color: #006080">'boolean'</span> },        <span style="color: #006080">'Notes'</span>    ],    idProperty: <span style="color: #006080">'Id'</span>,

    proxy: {        type: <span style="color: #006080">'ajax'</span>,        api: {            read: <span style="color: #006080">'SponsorListJobListing/Get'</span>,            update: <span style="color: #006080">'SponsorListJobListing/Update'</span>,            create: <span style="color: #006080">'SponsorListJobListing/Create'</span>,            destroy: <span style="color: #006080">'SponsorListJobListing/Delete'</span>        },        reader: {            type: <span style="color: #006080">'json'</span>,            root: <span style="color: #006080">'Data'</span>,            successProperty: <span style="color: #006080">'success'</span>        }    },

    belongsTo: <span style="color: #006080">'EvMgr.model.SponsorList'</span>});</pre>
<p></div>
<p>Notice the StartRunDate field has dateFormat of ‘MS”.</p>
<p>Now, we have an ExtJS Window that we use to collect the data from the user.&#160; The code is as follows:</p>
<div>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">Ext.define(<span style="color: #006080">'EvMgr.view.sponsorlist.ListJobListingsEdit'</span>, {    extend: <span style="color: #006080">'Ext.window.Window'</span>,    alias: <span style="color: #006080">'widget.sponsorlistjoblistingsedit'</span>,    title: <span style="color: #006080">'Edit Job Listing'</span>,    layout: <span style="color: #006080">'fit'</span>,    width: 1000,    autoShow: <span style="color: #0000ff">true</span>,

    initComponent: <span style="color: #0000ff">function</span>() {

        <span style="color: #0000ff">this</span>.items = [            {                xtype: <span style="color: #006080">'form'</span>,

                items: [                    {                        xtype: <span style="color: #006080">'textfield'</span>,                        name: <span style="color: #006080">'JobName'</span>,                        fieldLabel: <span style="color: #006080">'JobName'</span>,                        width: 850                    },                    {                        xtype: <span style="color: #006080">'textfield'</span>,                        name: <span style="color: #006080">'JobLocation'</span>,                        fieldLabel: <span style="color: #006080">'JobLocation'</span>,                        width: 850                    },                     {                         xtype: <span style="color: #006080">'textfield'</span>,                         name: <span style="color: #006080">'JobURL'</span>,                         fieldLabel: <span style="color: #006080">'JobURL'</span>,                         width: 850                     },                     {                         xtype: <span style="color: #006080">'textfield'</span>,                         name: <span style="color: #006080">'JobBrief'</span>,                         fieldLabel: <span style="color: #006080">'JobBrief'</span>,                         width: 850                     }, {                         xtype: <span style="color: #006080">'textfield'</span>,                         name: <span style="color: #006080">'JobTagline'</span>,                         fieldLabel: <span style="color: #006080">'JobTagline'</span>,                         width: 850                     },                     {                         xtype: <span style="color: #006080">'textfield'</span>,                         name: <span style="color: #006080">'JobButtonToolTip'</span>,                         fieldLabel: <span style="color: #006080">'JobButtonToolTip'</span>,                         width: 850                     },                     {                         xtype: <span style="color: #006080">'textfield'</span>,                         name: <span style="color: #006080">'JobCompanyName'</span>,                         fieldLabel: <span style="color: #006080">'JobCompanyName'</span>,                         width: 850                     },                     {                         xtype: <span style="color: #006080">'textfield'</span>,  <span style="color: #008000">// checkbox makesthe value not come back for some reason</span>                         name: <span style="color: #006080">'HideListing'</span>,                         fieldLabel: <span style="color: #006080">'HideListing'</span>,                         width: 850                     },                     {                         xtype: <span style="color: #006080">'datefield'</span>,                         name: <span style="color: #006080">'StartRunDate'</span>,                         fieldLabel: <span style="color: #006080">'StartRunDate'</span>,                         width: 850                     },                     {                         xtype: <span style="color: #006080">'datefield'</span>,                         name: <span style="color: #006080">'EndRunDate'</span>,                         fieldLabel: <span style="color: #006080">'EndRunDate'</span>,                         width: 850                     },                    {                        xtype: <span style="color: #006080">'textfield'</span>,                        name: <span style="color: #006080">'SponsorListId'</span>,                        fieldLabel: <span style="color: #006080">'SponsorListId'</span>,                        width: 850                    }                ]            }        ];

        <span style="color: #0000ff">this</span>.buttons = [            {                text: <span style="color: #006080">'Save'</span>,                action: <span style="color: #006080">'save'</span>            }, {                text: <span style="color: #006080">'Cancel'</span>,                scope: <span style="color: #0000ff">this</span>,                handler: <span style="color: #0000ff">this</span>.close            }        ];

        <span style="color: #0000ff">this</span>.callParent(arguments);    }});</pre>
</div>
<div>Notice we don’t have to mention the StartRunDate’s format because the model has that already.</div>
<div>&#160;</div>
<div>When we run the app and press the “save” button, the actual post that goes back to the asp.net MVC3 controller looks like the following (notice the screen shot of the app first, then what happens when the Save button is pressed)</div>
<div>&#160;</div>
<div><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/08/image4.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/08/image_thumb3.png" width="608" height="320" /></a></div>
<div>&#160;</div>
<div><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/08/image5.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/08/image_thumb4.png" width="466" height="395" /></a></div>
<div>&#160;</div>
<div>You can see that the date is passed back as Date(1313996400000).&#160; This is actually UTC time so we will need to make sure we check for that on the server.&#160; It’s always a good idea to store all dates on the server in UTC time anyhow.</div>
<div>&#160;</div>
<h3>Posting the Date To the Server (View From ASP.NET)</h3>
<div>&#160;</div>
<div>So let’s take a look at what is coming to the server.&#160; Remember that in the model, we defined what REST api is hit by a post from this model.&#160; In this case, it’s “update: &#8216;SponsorListJobListing/Update&#8217;,”.&#160; So, let’s debug into the C# (asp.net) side and see what is actually coming in.&#160; Here is what we see:</div>
<div>&#160;</div>
<div><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/08/image6.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/08/image_thumb5.png" width="624" height="324" /></a></div>
<div>&#160;</div>
<div>Notice that the date comes in very simply as midnight on 8/22/2011 (the date we put in).&#160; The tricky part is we need to store this date as UTC so that when we end it back, it can get converted back to local.&#160; To do this, in our repository class, we have code to convert to UTC as follows:</div>
<div>&#160;</div>
<div><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/08/image7.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/08/image_thumb6.png" width="594" height="444" /></a></div>
<div>&#160;</div>
<div>&#160;</div>
<div>Your repository will look different, but this is a good example.&#160; Now, notice the StartRunDate will be 8/22/2011 at 7AM.</div>
<div>&#160;</div>
<div><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/08/image8.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/08/image_thumb7.png" width="620" height="76" /></a></div>
<p>&#160;</p>
<p>I’m over simplifying a little because it’s calculating UTC based on the Servers time zone, not the browsers.&#160; It would be better to send the timezone of the browser also and then calculate UTC correctly in <a href="http://en.wikipedia.org/wiki/JavaScript">JavaScript</a>, but I just want to give you the idea here.&#160; In my case, I’m always running this app from California and my server is always inCalifornia so at least things stay consistent.&#160; I do realize I’m simplifying and you need to make sure you think this through.</p>
<p>&#160;</p>
<p>Now, when I query the server for the returned data using the same ExtJS data model, the data comes down as follows.&#160; In ASP.NET it looks like this:</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/08/image9.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/08/image_thumb8.png" width="244" height="191" /></a></p>
<p>Which is actually different than what was pushed up.&#160; It seems though that when ExtJS displays this, it converts it to local time.</p>
<p>Our browser Grid shows it like this (as we would expect)</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/08/image10.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/08/image_thumb9.png" width="156" height="112" /></a></p>
<p>Hope this helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/08/24/getting-extjs-4-date-format-to-behave-properly-in-grid-panel-with-asp-net-mvc3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Connecting To SqlServer From Web.Config Without a Password (Trusted Connection)</title>
		<link>http://peterkellner.net/2011/08/11/connecting-to-sqlserver-from-web-config-without-a-password-trusted-connection/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=connecting-to-sqlserver-from-web-config-without-a-password-trusted-connection</link>
		<comments>http://peterkellner.net/2011/08/11/connecting-to-sqlserver-from-web-config-without-a-password-trusted-connection/#comments</comments>
		<pubDate>Thu, 11 Aug 2011 16:19:56 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Sql Server 2008]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/08/11/connecting-to-sqlserver-from-web-config-without-a-password-trusted-connection/</guid>
		<description><![CDATA[I often forget that the simplest way (IMHO) to connect to a Microsoft SqlServer 2008 database is to use the web.config connection for making a Trusted connection.&#160; Basically, it keeps you from having to put a username and password in the web.config and also from having to keep track of different username and passwords on [...]]]></description>
			<content:encoded><![CDATA[<p>I often forget that the simplest way (IMHO) to connect to a <a href="http://www.microsoft.com/en-us/default.aspx">Microsoft</a> <a href="http://www.microsoft.com/sqlserver/en/us/default.aspx">SqlServer 2008</a> database is to use the <a href="http://msdn.microsoft.com/en-us/library/aa306178.aspx">web.config</a> connection for making a Trusted connection.&#160; Basically, it keeps you from having to put a username and password in the web.config and also from having to keep track of different username and passwords on different systems (like where you deploy to for example).&#160; The simplest connection string I can think of looks like this:</p>
<div id="codeSnippetWrapper">&#160;</div>
<div>&#160;</div>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">&lt;add name=<span style="color: #006080">&quot;MyConnName&quot;</span> connectionString=<span style="color: #006080">&quot;Server=.;Database=mydbcatalogname;Trusted_Connection=True;&quot;</span>     providerName=<span style="color: #006080">&quot;System.Data.SqlClient&quot;</span> /&gt;</pre>
<p></div>
<p>Notice that I’m using the “.” as the server name.&#160; This allows me to reference the local system where my sqlserver lives. Not necessarily a best practice, but often is the case.</p>
<h3>Upside</h3>
<p>One big benefit is if you fall victim to a <a href="http://www.imperva.com/products/wsc_web-application_attacks.html">disk scraping attack</a>, or someone gets a hold of your source (maybe from version control?), you don’t give up your passwords.</p>
<h3>Downside</h3>
<p>If you SqlSever is not on the system system as your web project or application, then this become more tricky because of the cross system authentication issues.&#160; If you have active directory installed on both systems, then this works also.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/08/11/connecting-to-sqlserver-from-web-config-without-a-password-trusted-connection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DevConnections Orlando, Build Advanced Web UIs with a Rich JavaScript UI Language</title>
		<link>http://peterkellner.net/2011/03/30/devconnections-orlando-build-advanced-web-uis-with-a-rich-javascript-ui-language/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=devconnections-orlando-build-advanced-web-uis-with-a-rich-javascript-ui-language</link>
		<comments>http://peterkellner.net/2011/03/30/devconnections-orlando-build-advanced-web-uis-with-a-rich-javascript-ui-language/#comments</comments>
		<pubDate>Wed, 30 Mar 2011 14:26:30 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[MVC3]]></category>
		<category><![CDATA[Presentations]]></category>
		<category><![CDATA[Sencha]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/03/30/devconnections-orlando-build-advanced-web-uis-with-a-rich-javascript-ui-language/</guid>
		<description><![CDATA[To build fully-featured web applications that support complex interaction in a reasonable amount of time requires a high-end JavaScript library. Someday, maybe JQueryUI will be good for this, but for now, the choices are few and include ExtJS, Dojo, YUI and a handful of others. This session will use ExtJS as the example. We will [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>To build fully-featured web applications that support complex interaction in a reasonable amount of time requires a high-end JavaScript library. Someday, maybe JQueryUI will be good for this, but for now, the choices are few and include ExtJS, Dojo, YUI and a handful of others. This session will use ExtJS as the example. We will use Microsoft’s ASP.NET MVC as the data / CRUD layer and from that, we will build a typical LOB (line of business) application using complex UI elements. Those elements include layout managers, data grids, extensive validation, spinner controls and other advanced UI features. To get an idea of what I’m talking about, spend five minutes looking at the examples on the ExtJS web site demonstrating these advanced web UI features <a href="http://www.sencha.com/products/js/">http://www.sencha.com/products/js/</a>. You will be convinced that spending hundreds of hours trying to build something not nearly as well done as this is a waste of time when there are such excellent libraries already built for you.</p>
</blockquote>
<p>The source attached below for my demos.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8eb9d37f-1541-4f29-b6f4-1eea890d4876:e83cd384-32b1-473e-a4b3-7328eea142cb" class="wlWriterEditableSmartContent">
<div><a href="http://peterkellner.net/FilesForWebDownload/P_8B12/DemoApp.zip" target="_self">Project Used For Demo (Including Notes as txt files)</a></div>
</p>
</div>
<p><a href="http://peterkellner.net/FilesForWebDownload/P_8B12/image.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/P_8B12/image_thumb.png" width="244" height="208" /></a></p>
<p>  <span id="more-1455"></span>
<p>Final <a href="http://sencha.com">ExtJS4</a> JavaScript (that didn’t quite work, but working now)</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #008000">// Load dependencies</span>Ext.require([    <span style="color: #006080">'Ext.data.*'</span>,    <span style="color: #006080">'Ext.button.*'</span>,    <span style="color: #006080">'Ext.form.*'</span>]);

Ext.onReady(<span style="color: #0000ff">function</span> () {

    <span style="color: #008000">// Date renderer</span>    <span style="color: #0000ff">var</span> dateConvert = <span style="color: #0000ff">function</span> (val, record) {        <span style="color: #0000ff">if</span> (val.split(<span style="color: #006080">'('</span>).length == 2) {            <span style="color: #0000ff">var</span> dateObj = <span style="color: #0000ff">new</span> Date(parseInt(val.substr(6)));            <span style="color: #0000ff">return</span> Ext.util.Date.format(dateObj, <span style="color: #006080">'m/d/Y'</span>);        } <span style="color: #0000ff">else</span> {            <span style="color: #0000ff">return</span> val;        }

    }

    Ext.regModel(<span style="color: #006080">'Users'</span>, {

        fields: [            { name: <span style="color: #006080">'Id'</span>, type: <span style="color: #006080">'int'</span> },            { name: <span style="color: #006080">'Username'</span> },            { name: <span style="color: #006080">'CreationDate'</span> },            { name: <span style="color: #006080">'FirstName'</span> },            { name: <span style="color: #006080">'LastName'</span> },            { name: <span style="color: #006080">'PlanExpirationDate'</span> }        ],        <span style="color: #008000">// Proxy</span>        proxy: {            type: <span style="color: #006080">'ajax'</span>,            url: <span style="color: #006080">'/Users/JsonData'</span>,            api: {                read :    <span style="color: #006080">'/Users/JsonData'</span>,                create :  <span style="color: #006080">'/Users/Create'</span>,                update :    <span style="color: #006080">'/Users/Edit'</span>,                destroy : <span style="color: #006080">'/Users/Delete'</span>            },            <span style="color: #008000">// Json Reader</span>            reader: {                type: <span style="color: #006080">'json'</span>,                idProperty: <span style="color: #006080">'Id'</span>,                totalProperty: <span style="color: #006080">'total'</span>,                root: <span style="color: #006080">'data'</span>            },            writer: {                type: <span style="color: #006080">'json'</span>,                encode: <span style="color: #0000ff">false</span>,                listful: <span style="color: #0000ff">true</span>,                writeAllFields: <span style="color: #0000ff">true</span>            },            headers: { <span style="color: #006080">'Content-Type'</span>: <span style="color: #006080">'application/json; charset=UTF-8'</span> }                            }

    });

    <span style="color: #0000ff">var</span> usersStore = <span style="color: #0000ff">new</span> Ext.data.Store({        model: <span style="color: #006080">'Users'</span>,        autoLoad: <span style="color: #0000ff">true</span>,        pageSize: 10    });

    <span style="color: #0000ff">var</span> gridForm = Ext.create(<span style="color: #006080">'Ext.form.FormPanel'</span>, {        id: <span style="color: #006080">'userFormPanel'</span>,        frame: <span style="color: #0000ff">true</span>,        title: <span style="color: #006080">'Users Data'</span>,        store: usersStore,        bodyPadding: 5,        width: 910,        layout: <span style="color: #006080">'column'</span>,    <span style="color: #008000">// Specifies that the items will now be arranged in columns</span>

        fieldDefaults: {            labelAlign: <span style="color: #006080">'left'</span>,            msgTarget: <span style="color: #006080">'side'</span>        },

        items: [{            columnWidth: 0.65,            xtype: <span style="color: #006080">'gridpanel'</span>,            id: <span style="color: #006080">'usersGrid'</span>,            store: usersStore,            height: 410,            title: <span style="color: #006080">'Users'</span>,

            headers: [        {            text: <span style="color: #006080">'User Name'</span>,            flex: 1,            sortable: <span style="color: #0000ff">true</span>,            dataIndex: <span style="color: #006080">'Username'</span>        },        {            text: <span style="color: #006080">'CreationDate'</span>,            width: 100,            sortable: <span style="color: #0000ff">true</span>,            renderer: dateConvert,            dataIndex: <span style="color: #006080">'CreationDate'</span>        },        {            text: <span style="color: #006080">'First Name'</span>,            width: 100,            sortable: <span style="color: #0000ff">true</span>,            dataIndex: <span style="color: #006080">'FirstName'</span>        },        {            text: <span style="color: #006080">'Last Name'</span>,            width: 100,            sortable: <span style="color: #0000ff">true</span>,            dataIndex: <span style="color: #006080">'LastName'</span>        },        {            text: <span style="color: #006080">'Plan Expiration Date'</span>,            width: 120,            sortable: <span style="color: #0000ff">true</span>,            renderer: dateConvert,            dataIndex: <span style="color: #006080">'PlanExpirationDate'</span>        }    ],

    listeners: {        selectionchange: <span style="color: #0000ff">function</span> (model, records) {            <span style="color: #0000ff">if</span> (records[0]) {                <span style="color: #0000ff">var</span> recordToLoad = {                    Username: records[0].data.Username,                    CreationDate: dateConvert(records[0].data.CreationDate),                    FirstName: records[0].data.FirstName,                    LastName: records[0].data.LastName,                    PlanExpirationDate: dateConvert(records[0].data.PlanExpirationDate)                }                <span style="color: #0000ff">this</span>.up(<span style="color: #006080">'form'</span>).getForm().setValues(recordToLoad);            }        }    },    bbar: <span style="color: #0000ff">new</span> Ext.PagingToolbar({        store: usersStore    })        }, {            columnWidth: 0.35,            margin: <span style="color: #006080">'0 0 0 10'</span>,            bodyStyle: {                margin: <span style="color: #006080">'4px'</span>            },            xtype: <span style="color: #006080">'form'</span>,            id: <span style="color: #006080">'userForm'</span>,            title: <span style="color: #006080">'Add / Edit User Details'</span>,            defaults: {                width: 260,                labelWidth: 120,                margin: <span style="color: #006080">'7px'</span>            },            defaultType: <span style="color: #006080">'textfield'</span>,            items: [{                fieldLabel: <span style="color: #006080">'User Name'</span>,                name: <span style="color: #006080">'Username'</span>            }, {                xtype: <span style="color: #006080">'datefield'</span>,                fieldLabel: <span style="color: #006080">'Creation Date'</span>,                name: <span style="color: #006080">'CreationDate'</span>            }, {                fieldLabel: <span style="color: #006080">'First Name'</span>,                name: <span style="color: #006080">'FirstName'</span>            }, {                fieldLabel: <span style="color: #006080">'Last Name'</span>,                name: <span style="color: #006080">'LastName'</span>            }, {                xtype: <span style="color: #006080">'datefield'</span>,                fieldLabel: <span style="color: #006080">'Plan Expiration Date'</span>,                name: <span style="color: #006080">'PlanExpirationDate'</span>            }],            buttons: [{                text: <span style="color: #006080">'Update Record'</span>,                scale: <span style="color: #006080">'medium'</span>,                handler: <span style="color: #0000ff">function</span> (btn, e) {                    <span style="color: #0000ff">var</span> userSelectionModel = Ext.getCmp(<span style="color: #006080">'usersGrid'</span>).getSelectionModel();                    <span style="color: #0000ff">if</span> (userSelectionModel.hasSelection()) {                        <span style="color: #008000">// get the form</span>                        <span style="color: #0000ff">var</span> formCmp = Ext.getCmp(<span style="color: #006080">'userForm'</span>);                        <span style="color: #008000">// get the form field values</span>                        <span style="color: #0000ff">var</span> formValues = formCmp.getForm().getValues();                        <span style="color: #008000">// get the selected record</span>                        <span style="color: #0000ff">var</span> recordSelection = userSelectionModel.getLastSelected();                        <span style="color: #008000">// update the record with the form fields</span>                        recordSelection.set(formValues)                        <span style="color: #008000">// sync store</span>                        usersStore.sync();                    }                }            }, {                text: <span style="color: #006080">'Add As New Record'</span>,                scale: <span style="color: #006080">'medium'</span>,                handler: <span style="color: #0000ff">function</span> (btn, e) {                    <span style="color: #008000">// get the form</span>                    <span style="color: #0000ff">var</span> formCmp = Ext.getCmp(<span style="color: #006080">'userForm'</span>);                    <span style="color: #008000">// get the form field values</span>                    <span style="color: #0000ff">var</span> formValues = formCmp.getForm().getValues();                    <span style="color: #008000">// add to the the store</span>                    usersStore.add(formValues);                    <span style="color: #008000">// sync with the store</span>                    usersStore.sync();                }            }, {                text: <span style="color: #006080">'Delete Record'</span>,                scale: <span style="color: #006080">'medium'</span>,                handler: <span style="color: #0000ff">function</span> (btn, e) {                    <span style="color: #008000">// get the user grid selection model</span>                    <span style="color: #0000ff">var</span> userSelectionModel = Ext.getCmp(<span style="color: #006080">'usersGrid'</span>).getSelectionModel();                    <span style="color: #008000">// check if there's a selection</span>                    <span style="color: #0000ff">if</span> (userSelectionModel.hasSelection()) {                        <span style="color: #008000">// remove the selected record</span>                        usersStore.remove(userSelectionModel.getLastSelected());                        usersStore.sync();                    }                }            }]        }],        renderTo: <span style="color: #006080">'extjs-grid'</span>    });

});</pre>
<p></div>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/03/30/devconnections-orlando-build-advanced-web-uis-with-a-rich-javascript-ui-language/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>What is the Difference Between Path.GetTempFileName and Path.GetTempPath</title>
		<link>http://peterkellner.net/2011/02/17/what-is-the-difference-between-path-gettempfilename-and-path-gettemppath/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=what-is-the-difference-between-path-gettempfilename-and-path-gettemppath</link>
		<comments>http://peterkellner.net/2011/02/17/what-is-the-difference-between-path-gettempfilename-and-path-gettemppath/#comments</comments>
		<pubDate>Fri, 18 Feb 2011 00:40:31 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/02/17/what-is-the-difference-between-path-gettempfilename-and-path-gettemppath/</guid>
		<description><![CDATA[Getting filenames to use as scratch files is usually very straight forward.&#160; Well, today, I found out “not so much”.&#160; I decided today was a good day to tackle the problem of why is my file synchronization product we are about to release still littering my tmp directory with files when it finishes.&#160; Turns out, [...]]]></description>
			<content:encoded><![CDATA[<p>Getting filenames to use as scratch files is usually very straight forward.&#160; Well, today, I found out “not so much”.&#160; I decided today was a good day to tackle the problem of why is my file synchronization product we are about to release still littering my tmp directory with files when it finishes.&#160; Turns out, it’s the subtle difference between the above two Path member functions GetTempFileName and GetTempPath.</p>
<p>The big difference is that GetTempFileName actually creates a file where as GetTempPath simply tells you where the file is going to be.</p>
<p>Here are some words out of MSDN for <a href="http://msdn.microsoft.com/en-us/library/system.io.path.gettempfilename(v=VS.100).aspx">Path.GetTempFileName</a></p>
<blockquote><p>This method creates a temporary file with a .TMP file extension.</p>
</blockquote>
<p>And For <a href="http://msdn.microsoft.com/en-us/library/system.io.path.gettemppath.aspx">Path.GetTempPath</a></p>
<blockquote><p>The path to the temporary folder, ending with a backslash.</p>
</blockquote>
<p>Subtle, but clear when you read the doc.&#160; If you read the community content, there is a humorous discussion with someone saying “you might as well use the other one, it does the same thing”.&#160; All I can say to that is read the docs!&#160; I got stung today, but never again.</p>
<p>I’m now creating my filename with a string as follows which kind of does the same thing, but not really.&#160; </p>
<p>&#160;</p>
<p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> GetTempFileWithGuid(<span style="color: #0000ff">string</span> filePrefix){    <span style="color: #0000ff">string</span> retFileName = <span style="color: #0000ff">string</span>.Format(<span style="color: #006080">&quot;{0}{1}{2}.crsync&quot;</span>,         Path.GetTempPath(), filePrefix, Guid.NewGuid());    <span style="color: #0000ff">return</span> retFileName;}</pre>
</p></div>
</p>
<p>HTH’s.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/02/17/what-is-the-difference-between-path-gettempfilename-and-path-gettemppath/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#8220;Programming Windows Azure&#8221; By Sriram Krishnan / O&#8217;Reilly Book Review</title>
		<link>http://peterkellner.net/2010/12/21/programming-windows-azure-by-sriram-krishnan-book-review/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=programming-windows-azure-by-sriram-krishnan-book-review</link>
		<comments>http://peterkellner.net/2010/12/21/programming-windows-azure-by-sriram-krishnan-book-review/#comments</comments>
		<pubDate>Tue, 21 Dec 2010 17:43:20 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[Azure Blob Storage]]></category>
		<category><![CDATA[Azure Table Storage]]></category>
		<category><![CDATA[Book Reviews]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2010/12/21/programming-windows-azure-by-sriram-krishnan-book-review/</guid>
		<description><![CDATA[I’ve been slowly building up my Azure experience over the past few months and actually plan to release a product using Azure during the next month or two.&#160; Programming Windows Azure has been a huge value to me in learning both the basics of the Azure platform as well as the details.&#160; It has a [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been slowly building up my <a href="http://www.microsoft.com/windowsazure/">Azure</a> experience over the past few months and actually plan to release a product using Azure during the next month or two.&#160; Programming Windows Azure has been a huge value to me in learning both the basics of the <a href="http://www.microsoft.com/windowsazure/">Azure</a> platform as well as the details.&#160; It has a great balance of theory verses practice.&#160; I strongly recommend this book if you are new to Azure or even if you have experience with Azure.&#160; I often find myself going back and re-reading sections to better understand things.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:7dc1bd33-94bd-46fd-a20b-0131235bcd47:ec3f43d6-d26f-4aaa-8d47-6c2f98ce99fc" class="wlWriterEditableSmartContent">
<table cellspacing="0" cellpadding="2" width="400" border="0" unselectable="on">
<tbody>
<tr>
<td valign="top" width="400">
<p><a title="Programming Windows Azure eBook: Sriram Krishnan: Kindle Store" href="http://www.amazon.com/exec/obidos/ASIN/B0043M58U8/petkelsblo-20"><img src="http://images.amazon.com/images/P/B0043M58U8.01.MZZZZZZZ.jpg" border="0" align="left" style="float:left">Programming Windows Azure eBook: Sriram Krishnan: Kindle Store</a></p>
</td>
</tr>
</tbody>
</table>
</div>
<p>&#160;</p>
<p>Two of the sections I feel are particularly well written or the ones that talk about <a href="http://msdn.microsoft.com/en-us/library/dd179355.aspx">Storage and Tables</a> (chapters 7 and 8).&#160; The application I’ve been working on heavily uses blob storage and I spend lots of times re-reading those sections.&#160; Azure tables is a hard topic to get a <a href="http://www.microsoft.com/sqlserver/en/us/default.aspx">sql server</a> programmer like me to get my head wrapped around.&#160; Sriram does a great job of talking directly to someone like me to help me understand how and when to use tables.</p>
<p>Again, I whole heartedly recommend this book.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2010/12/21/programming-windows-azure-by-sriram-krishnan-book-review/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A Simple MultiThreading Pattern For C# With No Statics.  Shows Compressing A File With GZip</title>
		<link>http://peterkellner.net/2010/12/04/simple-multithreading-pattern-for-c-sharp-with-no-statics-and-gzip-compression/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=simple-multithreading-pattern-for-c-sharp-with-no-statics-and-gzip-compression</link>
		<comments>http://peterkellner.net/2010/12/04/simple-multithreading-pattern-for-c-sharp-with-no-statics-and-gzip-compression/#comments</comments>
		<pubDate>Sat, 04 Dec 2010 15:09:03 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[gzip]]></category>
		<category><![CDATA[threading]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[VS2010]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2010/12/04/simple-multithreading-pattern-for-c-sharp-with-no-statics-and-gzip-compression/</guid>
		<description><![CDATA[Background
This post shows a very simple technique for processing a gzip compression on a background thread using c# with Visual Studio 2010.&#160; What is unique here is we are using no statics to do it.&#160; I’m not totally against using statics, but in general, it is best to avoid them.&#160; I’ve heard the notorious Ward [...]]]></description>
			<content:encoded><![CDATA[<h2>Background</h2>
<p>This post shows a very simple technique for processing a <a href="http://msdn.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx">gzip</a> compression on a background <a href="http://msdn.microsoft.com/en-us/library/aa645740(VS.71).aspx">thread</a> using <a href="http://msdn.microsoft.com/en-us/vcsharp/default.aspx">c#</a> with <a href="http://msdn.microsoft.com/en-us/vstudio/default.aspx">Visual Studio 2010</a>.&#160; What is unique here is we are using no statics to do it.&#160; I’m not totally against using statics, but in general, it is best to avoid them.&#160; I’ve heard the notorious <a href="http://www.neverindoubtnet.blogspot.com/">Ward Bell</a> say <a href="http://msdn.microsoft.com/en-us/library/98f28cdx.aspx">statics</a> are evil and have had many cases where they have bitten me.&#160; Since I heard Ward say this, I’ve been trying to avoid them where I can.</p>
<p>&#160;</p>
<h2>The Simple Problem</h2>
<p>The problem is to simply compress a file to bytes and return to us the compressed, uncompressed and byte array of the result.&#160; We can pass parameters into a thread, however we can not return them (when I say thread, I mean the anonymous method that processes our data).</p>
<p>  <span id="more-1418"></span><br />
<h2>Some Code</h2>
<p>So, to that end, Let’s create a main method as below.&#160; Notice that it creates a very simple anonymous method which executes the code cryptoCopress.CompressFile(…), then simply starts that thread.&#160; Once the thread starts, it simply waits for the thread to end by looping every 50 milliseconds on the thread.IsAlive method.&#160; Finally, when it returns, it simply looks at the cryptCompress object for the results.&#160; No Statics!</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8eb9d37f-1541-4f29-b6f4-1eea890d4876:dd5555c2-7bcc-4715-9cc2-b94a7ef4604b" class="wlWriterEditableSmartContent">
<div>Code:<a href="http://peterkellner.net/FilesForWebDownload/A-Simple-MultiThreading-Pattern-For-C_6021/MultiThreadingInCSharpSimple.zip" target="_self">MultiThreadingInCSharpSimple.zip</a></div>
</p>
</div>
<p>&#160;</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[] args){    var cryptCompress =        <span style="color: #0000ff">new</span> CryptCompress();    var thread =        <span style="color: #0000ff">new</span> Thread(            () =&gt;            cryptCompress.CompressFile                (<span style="color: #006080">@&quot;G:\NoBackup\ext-3.2.1\ext-all-debug-w-comments.js&quot;</span>));    thread.Start();

    <span style="color: #0000ff">int</span> cnt = 0;    <span style="color: #0000ff">while</span> (thread.IsAlive)    {        cnt++;        Console.WriteLine(<span style="color: #006080">&quot;Waiting... &quot;</span> + cnt);        Thread.Sleep(50);    }    Console.WriteLine(<span style="color: #006080">&quot;Before Compression KBytes: {0}&quot;</span>,                        cryptCompress.BeforeCompressionBytes/1000);    Console.WriteLine(<span style="color: #006080">&quot;After Compression KBytes: {0}&quot;</span>,                        cryptCompress.AfterCompressionBytes/1000);}</pre>
<p></div>
<p>Now, Lets look at the CryptCompress class.&#160; Notice that it’s basically got one public method (CompressFile) and 3 public properties that will be used to hold the return values.&#160; This way, the main method that started the thread can get the results.&#160; Again, notice that there is no word static any place in this project.</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> CryptCompress{<span style="color: #0000ff">public</span> <span style="color: #0000ff">byte</span>[] CompressedBytes { get; set; }<span style="color: #0000ff">public</span> <span style="color: #0000ff">long</span> BeforeCompressionBytes { get; set; }<span style="color: #0000ff">public</span> <span style="color: #0000ff">long</span> AfterCompressionBytes { get; set; }

<span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CompressFile(<span style="color: #0000ff">string</span> fileName){    <span style="color: #0000ff">using</span> (var fileStream =         <span style="color: #0000ff">new</span> FileStream(fileName, FileMode.Open, FileAccess.Read))    {        var uncompressedBytes = <span style="color: #0000ff">new</span> <span style="color: #0000ff">byte</span>[fileStream.Length];        fileStream.Read(uncompressedBytes, 0,             (<span style="color: #0000ff">int</span>) fileStream.Length);        CompressedBytes = CompressGzip(uncompressedBytes);        BeforeCompressionBytes = fileStream.Length;        AfterCompressionBytes = CompressedBytes.Length;        fileStream.Close();    }}

<span style="color: #008000">/// &lt;summary&gt;</span><span style="color: #008000">/// Take a simple stream of uncompressed bytes and compress them</span><span style="color: #008000">/// &lt;/summary&gt;</span><span style="color: #008000">/// &lt;param name=&quot;uncompressedBytes&quot;&gt;&lt;/param&gt;</span><span style="color: #008000">/// &lt;returns&gt;&lt;/returns&gt;</span><span style="color: #0000ff">public</span> <span style="color: #0000ff">byte</span>[] CompressGzip(<span style="color: #0000ff">byte</span>[] uncompressedBytes){    <span style="color: #0000ff">using</span> (var memory = <span style="color: #0000ff">new</span> MemoryStream())    {        <span style="color: #0000ff">using</span>             (var gZipStream =                 <span style="color: #0000ff">new</span> GZipStream(memory, CompressionMode.Compress, <span style="color: #0000ff">true</span>))        {            gZipStream.Write                (uncompressedBytes, 0, uncompressedBytes.Length);        }        <span style="color: #0000ff">return</span> memory.ToArray();    }}}</pre>
</div>
<p>&#160;</p>
<h2>The Results</h2>
<p>When we run this, notice that it takes 3 iterations (or 150 milliseconds) to complete. I’m only compressing a small file so no surprise.&#160; The file is actually 2.7 Megabytes and compress to .7 Megabytes.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/A-Simple-MultiThreading-Pattern-For-C_6021/image.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/A-Simple-MultiThreading-Pattern-For-C_6021/image_thumb.png" width="244" height="116" /></a></p>
<p>&#160;</p>
<p>That’s it for now! Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2010/12/04/simple-multithreading-pattern-for-c-sharp-with-no-statics-and-gzip-compression/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Using SHA256Managed to Generate SHA256 Hash with Microsoft .Net Cryptography Namespace / Memory Usage Implications</title>
		<link>http://peterkellner.net/2010/12/03/using-sha256managed-to-generate-sha256-hash/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-sha256managed-to-generate-sha256-hash</link>
		<comments>http://peterkellner.net/2010/12/03/using-sha256managed-to-generate-sha256-hash/#comments</comments>
		<pubDate>Fri, 03 Dec 2010 19:33:10 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[SHA256]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=1415</guid>
		<description><![CDATA[&#160;
Background And Conclusion
In my very last post I talked about how using SHA256 seemed to not be affected by whether you use Buffered or Not Buffered streams.&#160; An astute reader (Samuel Jack) referenced an article by one of my favorite ex MIcrosoft employees (Brad Abrams) saying that almost all the .Net streams have buffering built [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<h2>Background And Conclusion</h2>
<p>In my <a href="http://peterkellner.net/2010/11/24/efficiently-generating-sha256-checksum-for-files-using-csharp/">very last post</a> I talked about how using <a href="http://msdn.microsoft.com/en-us/library/d0hxa5e7.aspx">SHA256</a> seemed to not be affected by whether you use Buffered or Not Buffered streams.&#160; An astute reader (<a href="http://blog.functionalfun.net/">Samuel Jack</a>) referenced <a href="http://blogs.msdn.com/b/brada/archive/2004/04/15/114329.aspx">an article</a> by one of my favorite ex MIcrosoft employees (<a href="http://bradabrams.com/">Brad Abrams</a>) saying that almost all the .Net streams have buffering built in.</p>
<p>Well, I think SHA256Managed does not.&#160; One of the challenges I’ve been facing lately with my current project is to provide feedback while doing all kinds of byte piping (stream stuff).&#160; While figuring out how to do this, I inadvertently figured out that buffering makes a huge difference.&#160; Briefly, let me show my results first, then talk about the code that went into it.</p>
<p>Notice that when I use a 64MB Buffer, the memory used for the process is 77MB and when I use an 8MB buffer, the memory used is 17MB.&#160; Clearly the buffer allocated matters.&#160; Just for information, I’ve also included the code that does not break the SHA256 hash into blocks, and it has the same results based on the size of the Memory Buffer declared.&#160; That is, small buffer, small use, big buffer, big use.</p>
<p>  <span id="more-1415"></span>
<p><a href="http://peterkellner.net/FilesForWebDownload/Using_9C01/image.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/Using_9C01/image_thumb.png" width="402" height="220" /></a></p>
<p><a href="http://peterkellner.net/FilesForWebDownload/Using_9C01/image_3.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/Using_9C01/image_thumb_3.png" width="405" height="276" /></a></p>
<h2>The Code</h2>
<p>The code that I wrote to do this basically does a nice job of splitting up the processing so that you can log progress as it runs. I’m attaching the <a href="http://msdn.microsoft.com/en-us/vstudio/default.aspx">Visual Studio 2010</a> project here as well as pasting the relevant source code.&#160; It’s a good base to experiment with.&#160; Feel free to comment on interesting things you find experimenting with it.</p>
<p>Visual Studio 2010 Project:&#160;&#160;&#160;&#160;&#160;&#160;
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8eb9d37f-1541-4f29-b6f4-1eea890d4876:3633437a-182a-48b1-90bc-e4ae3be04a84" class="wlWriterEditableSmartContent">
<div><a href="http://peterkellner.net/FilesForWebDownload/Using_9C01/SHA512BufferedConsoleProject.zip" target="_self">SHA512BufferedConsoleProject.zip</a></div>
</p>
</div>
<p>&#160;</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #008000">/// &lt;summary&gt;</span><span style="color: #008000">/// Used so we can get MD5Hash and get progress on calculation</span><span style="color: #008000">/// &lt;/summary&gt;</span><span style="color: #008000">/// &lt;param name=&quot;streamIn&quot;&gt;&lt;/param&gt;</span><span style="color: #008000">/// &lt;returns&gt;&lt;/returns&gt;</span><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> GetSha512Buffered(Stream streamIn){    Process process = Process.GetCurrentProcess();    <span style="color: #0000ff">const</span> <span style="color: #0000ff">int</span> bufferSizeForMd5Hash = 1024*1024*8; <span style="color: #008000">// 8MB</span>    Console.WriteLine(<span style="color: #006080">&quot;-----------------------------------&quot;</span>);    Console.WriteLine(<span style="color: #006080">&quot;Memory Buffer Size {0} MB&quot;</span>, bufferSizeForMd5Hash/1000);    Console.WriteLine(<span style="color: #006080">&quot;-----------------------------------&quot;</span>);    <span style="color: #0000ff">string</span> hashString;    <span style="color: #0000ff">using</span> (var md5Prov = <span style="color: #0000ff">new</span> SHA256Managed())    {        <span style="color: #0000ff">int</span> readCount;        <span style="color: #0000ff">long</span> bytesTransfered = 0;        var buffer = <span style="color: #0000ff">new</span> <span style="color: #0000ff">byte</span>[bufferSizeForMd5Hash];        <span style="color: #0000ff">while</span> ((readCount = streamIn.Read(buffer, 0, buffer.Length)) != 0)        {            <span style="color: #008000">// Need to figure out if this is final block</span>            <span style="color: #0000ff">if</span> (bytesTransfered + readCount == streamIn.Length)            {                md5Prov.TransformFinalBlock(buffer, 0, readCount);            }            <span style="color: #0000ff">else</span>            {                md5Prov.TransformBlock(buffer, 0, bufferSizeForMd5Hash, buffer, 0);            }            bytesTransfered += readCount;            Console.WriteLine(<span style="color: #006080">&quot;GetSha512Buffered:{0}MB/{1}MB.   Memory Used: {2}MB&quot;</span>,                                bytesTransfered/1000000,                                streamIn.Length/1000000,                                process.PrivateMemorySize64/1000000);        }        hashString = BitConverter.ToString(md5Prov.Hash).Replace(<span style="color: #006080">&quot;-&quot;</span>, String.Empty);        md5Prov.Clear();    }    <span style="color: #0000ff">return</span> hashString;}</pre>
<p></div>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2010/12/03/using-sha256managed-to-generate-sha256-hash/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Efficiently Generating SHA256 Checksum For Files Using C#</title>
		<link>http://peterkellner.net/2010/11/24/efficiently-generating-sha256-checksum-for-files-using-csharp/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=efficiently-generating-sha256-checksum-for-files-using-csharp</link>
		<comments>http://peterkellner.net/2010/11/24/efficiently-generating-sha256-checksum-for-files-using-csharp/#comments</comments>
		<pubDate>Wed, 24 Nov 2010 18:01:00 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[SHA256]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2010/11/24/efficiently-generating-sha256-checksum-for-files-using-csharp/</guid>
		<description><![CDATA[* I just added another post on similar topic and added more details on performance and a case where buffered memory usage really did matter:&#160; http://peterkellner.net/2010/12/03/using-sha256managed-to-generate-sha256-hash/
I’m building a file synchronization with the cloud application and I want to store a checksum with the file so that I can verify later that the file is what [...]]]></description>
			<content:encoded><![CDATA[<p><font style="background-color: #ffff00">* I just added another post on similar topic and added more details on performance and a case where buffered memory usage really did matter:&#160; </font><a title="http://peterkellner.net/2010/12/03/using-sha256managed-to-generate-sha256-hash/" href="http://peterkellner.net/2010/12/03/using-sha256managed-to-generate-sha256-hash/"><font style="background-color: #ffff00">http://peterkellner.net/2010/12/03/using-sha256managed-to-generate-sha256-hash/</font></a></p>
<p>I’m building a <a href="http://connectionroad.com/">file synchronization</a> with the cloud application and I want to store a checksum with the file so that I can verify later that the file is what I think it is. I’m not a crypto guy so I searched around the internet for a solution.&#160;&#160; I found lots of examples and settled on this one that uses <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha256.aspx">SHA256</a> for the job.&#160; I also found some comments saying that it would be more efficient to wrap it in a <a href="http://msdn.microsoft.com/en-us/library/system.io.bufferedstream.aspx">BufferedStream</a> rather than processing the entire file at once.</p>
<p>Example Links: <a title="http://efreedom.com/Question/1-1345851/MD5-File-Processing" href="http://efreedom.com/Question/1-1345851/MD5-File-Processing">http://efreedom.com/Question/1-1345851/MD5-File-Processing</a> ; <a title="http://stackoverflow.com/questions/1177607/what-is-the-fastest-way-to-create-a-checksum-for-large-files-in-c/1177744#1177744" href="http://stackoverflow.com/questions/1177607/what-is-the-fastest-way-to-create-a-checksum-for-large-files-in-c/1177744#1177744">http://stackoverflow.com/questions/1177607/what-is-the-fastest-way-to-create-a-checksum-for-large-files-in-c/1177744#1177744</a></p>
<p>My intention for this post was to show how much more efficient it would be to use BufferedStream, however my results don’t show that.&#160; I’m guessing that somehow, the efficiency is happening under the covers in a place I don’t see.</p>
<p>If anyone knows this space well, please feel free to comment and suggest a better method.&#160; I’m publishing my source below for the test and my surprisingly similar results whether I used buffering or not.</p>
<p>Looking forward to the responses.</p>
<p>  <span id="more-1414"></span>
<p>&#160;</p>
<table border="1" cellspacing="0" cellpadding="2" width="599">
<tbody>
<tr>
<td valign="top" width="158">File Size In Megabytes</td>
<td valign="top" width="152">Non-Buffered</td>
<td valign="top" width="168">Buffered</td>
<td valign="top" width="119">Max Memory</td>
</tr>
<tr>
<td valign="top" width="158">.8 MB</td>
<td valign="top" width="152">.088 Seconds</td>
<td valign="top" width="168">.082 Seconds</td>
<td valign="top" width="119">&#160;</td>
</tr>
<tr>
<td valign="top" width="158">851 MB (buffer not set)</td>
<td valign="top" width="152">30.3 Seconds</td>
<td valign="top" width="168">30.4 Seconds</td>
<td valign="top" width="119">1700MB</td>
</tr>
<tr>
<td valign="top" width="158">851 MB (buffer 1MB)</td>
<td valign="top" width="160">29.2 Seconds</td>
<td valign="top" width="189">29.6 Seconds</td>
<td valign="top" width="152">1450MB</td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">using</span> System;<span style="color: #0000ff">using</span> System.Diagnostics;<span style="color: #0000ff">using</span> System.IO;<span style="color: #0000ff">using</span> System.Security.Cryptography;

<span style="color: #0000ff">namespace</span> ConsoleApplicationMD5test{    <span style="color: #0000ff">internal</span> <span style="color: #0000ff">class</span> Program    {        <span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[] args)        {            <span style="color: #008000">//const string fileName = @&quot;g:\tempjunk\BlobSyncClient.zip&quot;;</span>            <span style="color: #0000ff">const</span> <span style="color: #0000ff">string</span> fileName =             <span style="color: #006080">@&quot;g:\msdn\en_visual_studio_2008_service_pack_1_x86_dvd_x15-12962.iso&quot;</span>;

            var stopwatch1 = <span style="color: #0000ff">new</span> Stopwatch();            stopwatch1.Start();            <span style="color: #0000ff">string</span> str1 = <span style="color: #006080">&quot;&quot;</span>; <span style="color: #008000">// GetChecksum(fileName);</span>            stopwatch1.Stop();

            var stopwatch2 = <span style="color: #0000ff">new</span> Stopwatch();            stopwatch2.Start();            var fileStream = <span style="color: #0000ff">new</span> FileStream(fileName, FileMode.OpenOrCreate,                FileAccess.Read);            <span style="color: #0000ff">string</span> str2 = GetChecksumBuffered(fileStream);            stopwatch2.Stop();

            Console.WriteLine(str1 + <span style="color: #006080">&quot; &quot;</span> + stopwatch1.ElapsedMilliseconds);            Console.WriteLine(str2 + <span style="color: #006080">&quot; &quot;</span> + stopwatch2.ElapsedMilliseconds);

            Console.ReadLine();        }

        <span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> GetChecksum(<span style="color: #0000ff">string</span> file)        {            <span style="color: #0000ff">using</span> (FileStream stream = File.OpenRead(file))            {                var sha = <span style="color: #0000ff">new</span> SHA256Managed();                <span style="color: #0000ff">byte</span>[] checksum = sha.ComputeHash(stream);                <span style="color: #0000ff">return</span> BitConverter.ToString(checksum).Replace(<span style="color: #006080">&quot;-&quot;</span>, String.Empty);            }        }

        <span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> GetChecksumBuffered(Stream stream)        {            <span style="color: #0000ff">using</span> (var bufferedStream = <span style="color: #0000ff">new</span> BufferedStream(stream, 1024 * 32))            {                var sha = <span style="color: #0000ff">new</span> SHA256Managed();                <span style="color: #0000ff">byte</span>[] checksum = sha.ComputeHash(bufferedStream);                <span style="color: #0000ff">return</span> BitConverter.ToString(checksum).Replace(<span style="color: #006080">&quot;-&quot;</span>, String.Empty);            }        }    }}</pre>
<p></div>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2010/11/24/efficiently-generating-sha256-checksum-for-files-using-csharp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Building a Simple Azure Blob Tree Viewer With Azure StorageClient API</title>
		<link>http://peterkellner.net/2010/11/12/azure-storage-treeviewer-directory-browser/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=azure-storage-treeviewer-directory-browser</link>
		<comments>http://peterkellner.net/2010/11/12/azure-storage-treeviewer-directory-browser/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 01:36:30 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[Azure Blob Storage]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[StorageClient]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2010/11/12/azure-storage-treeviewer-directory-browser/</guid>
		<description><![CDATA[Understanding how Azure Blob Storage can be used to simulate directory structures is a little tricky to say the least.&#160; I’ve got a long forum thread on the Windows Azure Community site&#160; now discussing the details.&#160; As always, Steve Marx has been a big help here with a bunch of code. Steve’s got a great [...]]]></description>
			<content:encoded><![CDATA[<p>Understanding how <a href="http://msdn.microsoft.com/en-us/windowsazure/cc974146.aspx">Azure</a> <a href="http://www.microsoft.com/windowsazure/storage/default.aspx">Blob Storage</a> can be used to simulate directory structures is a little tricky to say the least.&#160; I’ve got a long <a href="http://social.msdn.microsoft.com/Forums/en-US/windowsazuredata/thread/256cfc0f-bccc-4bf7-b7eb-cb7c7aca0c8a">forum thread</a> on the Windows Azure Community site&#160; now discussing the details.&#160; As always, <a href="http://blog.smarx.com/">Steve Marx</a> has been a big help here with a bunch of code. Steve’s got a great blog where he provides lots of examples and insights.&#160; Neil Mackenzie has also contributed here to getting to the answer.</p>
<p>Just so we now have an example, I’ve put together a simple windows form app that let’s you set a few variables in your app.config to point at your azure storage and container, let you view your app as a tree as well as see the code how it can be done.&#160; I have not commented the code much, just thought it would be good to get it out there.&#160; The running application shows you the data as follows.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/Building-a-Simple-Azure-Blob-Tree-Viewer_F37A/image.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/Building-a-Simple-Azure-Blob-Tree-Viewer_F37A/image_thumb.png" width="341" height="254" /></a></p>
<p>  <span id="more-1410"></span>
<p>So, for the details, I’m pasting below the meet of the code.&#160; Basically, it does what you would expect in terms of iterating through the directories recursively to build the list.&#160; Again, just set your parameters in your app.config as follows:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/Building-a-Simple-Azure-Blob-Tree-Viewer_F37A/image_3.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/Building-a-Simple-Azure-Blob-Tree-Viewer_F37A/image_thumb_3.png" width="281" height="115" /></a></p>
<p>and you can run it for yourself and see how it goes.</p>
<p>I’m pasting some code below, as well as including the project source code.&#160; The main reason I’m pasting the code is so that the search engines can find it better.&#160; It’s really just easier to download the project and load it into <a href="http://www.microsoft.com/visualstudio/en-us/visual-studio-2010-launch?WT.mc_id=SEARCH&amp;WT.srch=1">Visual Studio 2010</a> and run it yourself.</p>
<p>&#160;</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8eb9d37f-1541-4f29-b6f4-1eea890d4876:40251c5f-e5d4-447d-80ca-5c6ba51b4cef" class="wlWriterEditableSmartContent">
<div>Visual Studio 2010   <a href="http://peterkellner.net/FilesForWebDownload/Building-a-Simple-Azure-Blob-Tree-Viewer_F37A/AzureBlobTreeViewer_3.zip" target="_self">AzureBlobTreeViewer.zip</a></div>
</p>
</div>
<p>&#160;</p>
<p>Good Luck, and hope this helps!</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8eb9d37f-1541-4f29-b6f4-1eea890d4876:6a0a0214-7d94-482e-9b3f-436063c63866" class="wlWriterEditableSmartContent">
<div>Visual Studio 2010   <a href="http://peterkellner.net/FilesForWebDownload/Building-a-Simple-Azure-Blob-Tree-Viewer_F37A/AzureBlobTreeViewer.zip" target="_self">AzureBlobTreeViewer.zip</a></div>
</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2010/11/12/azure-storage-treeviewer-directory-browser/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>If You Use BackgroundWorker in .Net, Make Sure You Wrap Your Worker Method In Try (or risk missing the exception thrown)</title>
		<link>http://peterkellner.net/2010/11/09/using-backgroundworker-exception-not-thrown/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-backgroundworker-exception-not-thrown</link>
		<comments>http://peterkellner.net/2010/11/09/using-backgroundworker-exception-not-thrown/#comments</comments>
		<pubDate>Tue, 09 Nov 2010 21:57:42 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Exceptions]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2010/11/09/if-you-use-backgroundworker-in-net-make-sure-you-wrap-your-worker-method-in-try-or-risk-missing-the-exception-thrown/</guid>
		<description><![CDATA[So, just a short post in case someone runs into the same problem I had today that cost me about 2 hours using Visual Studio 2010.&#160; Basically, if you are using the BackgroundWorker in a windows app (with visual studio) and find that the method is not finishing and seemingly not throwing exceptions, maybe it [...]]]></description>
			<content:encoded><![CDATA[<p>So, just a short post in case someone runs into the same problem I had today that cost me about 2 hours using <a href="http://www.microsoft.com/visualstudio/en-us/visual-studio-2010-launch?WT.mc_id=SEARCH&amp;WT.srch=1">Visual Studio 2010</a>.&#160; Basically, if you are using the <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx">BackgroundWorker</a> in a windows app (with visual studio) and find that the method is not finishing and seemingly not throwing exceptions, maybe it actually is and you are missing it.</p>
<p>That is, if you have code like this:</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> backgroundWorker1_DoWork(<span style="color: #0000ff">object</span> sender, DoWorkEventArgs e){    backgroundWorker1.ReportProgress(0,<span style="color: #006080">&quot;starting...&quot;</span>);    <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; 10;i++ )    {        <span style="color: #0000ff">if</span> (i &gt; 5)        {            <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ApplicationException(<span style="color: #006080">&quot;any error here&quot;</span>);        }        backgroundWorker1.ReportProgress(i, <span style="color: #006080">&quot;working...&quot;</span>);    }}</pre>
<p></div>
<p>and you run it in the debugger, it will not stop by default when the exception is thrown (like it would in single threaded code).</p>
<p>So, I recommend doing the following and setting a break point to see the error.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/If-You-Use-BackgroundThrea_BFD6/image.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/If-You-Use-BackgroundThrea_BFD6/image_thumb.png" width="497" height="251" /></a></p>
<p>&#160;</p>
<p>Another thing you can do is bump up where debug’s stops uisng the dialog:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/If-You-Use-BackgroundThrea_BFD6/image_3.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/If-You-Use-BackgroundThrea_BFD6/image_thumb_3.png" width="512" height="336" /></a></p>
<p>goes to:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/If-You-Use-BackgroundThrea_BFD6/image_4.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/If-You-Use-BackgroundThrea_BFD6/image_thumb_4.png" width="462" height="244" /></a></p>
<p>&#160;</p>
<p>Then, you will get an error you expect.</p>
<p>&#160;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/If-You-Use-BackgroundThrea_BFD6/image_5.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/If-You-Use-BackgroundThrea_BFD6/image_thumb_5.png" width="416" height="229" /></a></p>
<p>HTH’s!</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2010/11/09/using-backgroundworker-exception-not-thrown/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Building Job Ads Management Module With LightSwitch Beta 1 For Silicon Valley Code Camp</title>
		<link>http://peterkellner.net/2010/09/30/building-job-ads-management-module-with-lightswitch-beta-1-for-silicon-valley-code-camp/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=building-job-ads-management-module-with-lightswitch-beta-1-for-silicon-valley-code-camp</link>
		<comments>http://peterkellner.net/2010/09/30/building-job-ads-management-module-with-lightswitch-beta-1-for-silicon-valley-code-camp/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 15:34:29 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[LightSwitch]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=1370</guid>
		<description><![CDATA[&#160;
The End Result
&#160; 
&#160;
Motivation
As you can imagine, The Silicon Valley Code Camp web site has lots of “back end” functions that need to be done. That is, things like doing mailings, assigning roles to users, making schedules, allocating rooms and times and literally&#160; hundreds of other tasks like that.&#160; Over the 5 years of code [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<h2>The End Result</h2>
<p>&#160;<a href="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_17.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_thumb_17.png" width="398" height="318" /></a> </p>
<p>&#160;</p>
<h2>Motivation</h2>
<p>As you can imagine, The <a href="http://www.siliconvalley-codecamp.com/" target="_blank">Silicon Valley Code Camp</a> web site has lots of “back end” functions that need to be done. That is, things like doing mailings, assigning roles to users, making schedules, allocating rooms and times and literally&#160; hundreds of other tasks like that.&#160; Over the 5 years of code camp, I’ve always built simple protected asp.net web pages to do this.&#160; I’ve always used the simplest asp.net control I could find, such as GridView, DetailsView, DropDownList, and SqlDataSource.&#160; The interfaces usually basically work but are very clumsy and lacking in both functionality and aesthetics.</p>
<p>&#160;</p>
<h2>Why Now</h2>
<p>I’ve seen lots of short demos on <a href="http://msdn.microsoft.com/en-us/lightswitch/default.aspx" target="_blank">LightSwitch for Visual Studio</a> and recently read on someone else&#8217;s blog that they are now building all their simple applications using LIghtSwitch.&#160; Also, my friend <a href="http://blogs.msdn.com/b/bethmassi/" target="_blank">Beth Massi</a> has been running around the world espousing the greatness of this product and I knew if I ran into any dumb issues that she’d bail me out (I’m the king of running into dumb issues.&#160; I’ve found that given two choices that seem right, I always pick the wrong one which is what actually happened here along the way, and Beth did bail me out).</p>
<p> <span id="more-1370"></span>
<p>&#160;</p>
<h2>First Blood</h2>
<p>First thing to do (after installing LightSwitch) is to say “File/New/Project”.&#160; My plan is to add this project right off my SV Codecamp solution.&#160; So, here goes.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_thumb.png" width="309" height="180" /></a> </p>
<p>So far so good.&#160; Next step is to choose attach to an external database</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_thumb_3.png" width="329" height="113" /></a> </p>
<p>Continuing, but don’t get tripped up here like I did.&#160; You will use WCF RIA Services under the covers but you don’t want to select that choice.&#160; You want to say that you want to connect to a database and let LightSwitch do the work for you.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_4.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_thumb_4.png" width="341" height="230" /></a> </p>
<p>PIck your database and connection strings.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_5.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_thumb_5.png" width="217" height="310" /></a> </p>
<p>Now, pick the tables you plan on working with.&#160; If this were Linq2sql, I’d be choosing them all, but now that I’m in RIA Services land, I’m hoping I can&#160; have separate “Domains” and not have to reference all the tables all the time.&#160; Jury is still out on that one but for now, I’m following the advice of the team and just picking the tables I want to manage now.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_6.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_thumb_6.png" width="327" height="114" /></a> </p>
<p>And, I’m going to name the Data Source “svcodecampDataJobs”.&#160; I’ll have to see how this goes and report later.&#160; I’m doing this live so I really don’t know where I’ll end up.</p>
<p>click finish, then rebuild all and it&#160; all works.&#160; It comes up with this screen showing me my relationship between the tables. It is showing me a Company table with a link to a JobListing table which is what I have. Here is what LightSwitch shows me.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_7.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_thumb_7.png" width="384" height="384" /></a> </p>
<p>The reality of my database is that I also have a JobListingDates table that is now shown here.&#160; Taking a step backwards to explain my database, I have a simple company table, the company has a detail table associated with it called JobListings, and the JobListings table has a details file associated with it called JobListingsDates.&#160; That is, a company may run an ad for 30 days, take it down for 30,and bring it back up again.</p>
<p>Here is what that schema actually looks like in SqlManager from EMS.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_8.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_thumb_8.png" width="370" height="336" /></a> </p>
<p>&#160;</p>
<p>One thing I like about great software is that it has things that are discoverable.&#160; So, just now, I double clicked on the little table called JobListings and the view changed to having JobListing as primary and if you look on the bottom right, it shows JobListingDate.&#160; Very cool.&#160; I have no idea where this is all going but I’m starting to get excited.&#160; Here is what I’m looking at now.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_9.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_thumb_9.png" width="377" height="377" /></a> </p>
<p>&#160;</p>
<h2>Building a Screen</h2>
<p>&#160;</p>
<p>So now, let’s push the “Screen” button and see what happens (while looking at the Company View).</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_10.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_thumb_10.png" width="323" height="102" /></a> </p>
<p>This is nice, I get a list of sample screens.&#160; How about if we build an Editable Grid Screen with the hope of editing and adding new Companies.&#160; Notice that I’m naming it EditableGridCompany and chosing the Company for the data in the dropdown.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_11.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_thumb_11.png" width="362" height="266" /></a></p>
<p>You now get a screen that is a little scary looking so rather than actually try and understand it, I thought “maybe I’m done, maybe this will just run”.&#160; So, here goes, Debug/Start Without Debug.&#160; Here is the scary screen, followed by what happens after the run.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_12.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_thumb_12.png" width="399" height="344" /></a> </p>
<p>And the Run:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_thumb_13.png" width="427" height="303" /></a> </p>
<p>Wow!&#160; Paging, Fancy editing including date pickers, exporting to Excel, Inserts, Updates and Deletes on the company table.&#160; This is amazing.&#160; Let me add another Grid so that I can add JobListings to the company.&#160; To do that, go back to the solution explorer and choose add screen.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_14.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_thumb_14.png" width="218" height="244" /></a> </p>
<p>Then again, I have choices.</p>
<p>I choose Details Screen and check Company in the dropdown, Company Details and Company JobListings for the additional data.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_15.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_thumb_15.png" width="399" height="292" /></a> </p>
<p>Another intimidating screen, but simply do Debug/Debug Start.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_16.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/BuildingJobAdsManagementWithLightSwitchB_13C17/image_thumb_16.png" width="415" height="229" /></a></p>
<p>&#160;</p>
<p>Well, that’s it for now.&#160; Code Camp is 4 days away and I don’t really have time to take this to the next level.&#160; You can see from the screen at the top of the post that this is pretty amazing for the effort!&#160; I’m sure I’ll be back to this.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2010/09/30/building-job-ads-management-module-with-lightswitch-beta-1-for-silicon-valley-code-camp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Adding a List of Recent Posts To The Silicon Valley Code Camp Home Page (From RSS Feed)</title>
		<link>http://peterkellner.net/2010/09/12/simplerssreader-in-silicon-valley-code-camp-objectdatasource-repeater-aspnet/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=simplerssreader-in-silicon-valley-code-camp-objectdatasource-repeater-aspnet</link>
		<comments>http://peterkellner.net/2010/09/12/simplerssreader-in-silicon-valley-code-camp-objectdatasource-repeater-aspnet/#comments</comments>
		<pubDate>Sun, 12 Sep 2010 21:44:26 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[ObjectDataSource]]></category>
		<category><![CDATA[Repeater]]></category>
		<category><![CDATA[RSS]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2010/09/12/simplerssreader-in-silicon-valley-code-camp-objectdatasource-repeater-aspnet/</guid>
		<description><![CDATA[There are 10,000 ways to do this.&#160; Back way back when (ASP.NET 1.1) days, we would have created either a custom control to do this, then added a Repeater control on the page to display it.&#160; Well, the Silicon Valley Code Camp Website was started back in those days and since what I want is [...]]]></description>
			<content:encoded><![CDATA[<p>There are 10,000 ways to do this.&#160; Back way back when (<a href="http://www.asp.net/">ASP.NET</a> 1.1) days, we would have created either a custom control to do this, then added a Repeater control on the page to display it.&#160; Well, the <a href="http://siliconvalley-codecamp.com/">Silicon Valley Code Camp</a> Website was started back in those days and since what I want is so simple, I decided to do just that (minus the custom control).&#160; I really only wanted to spend about 10 minutes doing this, and as it turned out, it took about 30.&#160; Oh well, 3x plan verses execution.&#160; Could do better next time.</p>
<p>So, here is basically what I want on the left side bar of the home page of Silicon Valley Code Camp:</p>
<p> <span id="more-1366"></span>
<p><a href="http://blog.siliconvalley-codecamp.com/"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="RSS Feed Look" border="0" alt="RSS Feed Look" src="http://peterkellner.net/FilesForWebDownload/AddingaListofRecentPostsToTheSiliconVall_CF44/image.png" width="177" height="346" /></a> </p>
<p>&#160;</p>
<p>First, I’ll attach my simple project I build to do this standalone so you can run it yourself, then, I’ll do a quick step through of the key code.&#160; </p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8eb9d37f-1541-4f29-b6f4-1eea890d4876:a42e11ac-159d-4bc9-8e14-637ad835e07b" class="wlWriterEditableSmartContent">
<div><a href="http://peterkellner.net/FilesForWebDownload/AddingaListofRecentPostsToTheSiliconVall_CF44/SimpleRSSReaderJustTitleAndLink.zip" target="_self">SimpleRSSReaderJustTitleAndLink.zip</a></div>
</p>
</div>
<p>All that is really in this project is a simple c# class file that contains a business object and one get method to retrieve the list.&#160; That file is called RSSFeed.cs.&#160; I’ve pasted all the code of that class below:</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">using</span> System.Collections.Generic;<span style="color: #0000ff">using</span> System.ComponentModel;<span style="color: #0000ff">using</span> System.Linq;<span style="color: #0000ff">using</span> System.Xml.Linq;

<span style="color: #0000ff">namespace</span> App_Code{    [DataObject(<span style="color: #0000ff">true</span>)]    <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> RSSFeedObject    {

        [DataObjectMethod(DataObjectMethodType.Select, <span style="color: #0000ff">true</span>)]        <span style="color: #0000ff">public</span> List&lt;RSSItem&gt; Get(<span style="color: #0000ff">int</span> numberToGet)        {            XDocument feedXML = XDocument.Load              (<span style="color: #006080">&quot;http://blog.siliconvalley-codecamp.com/feed/&quot;</span>);

            var feeds = feedXML.Descendants(<span style="color: #006080">&quot;item&quot;</span>).                Select(feed =&gt; <span style="color: #0000ff">new</span>                   {                       PostTitle = feed.Element(<span style="color: #006080">&quot;title&quot;</span>).Value,                       PostURL = feed.Element(<span style="color: #006080">&quot;link&quot;</span>).Value                   });            var rssItems = <span style="color: #0000ff">new</span> List&lt;RSSItem&gt;();            <span style="color: #0000ff">int</span> id = 0;            <span style="color: #0000ff">foreach</span> (var rec <span style="color: #0000ff">in</span> feeds)            {                rssItems.Add(<span style="color: #0000ff">new</span> RSSItem                                (id,rec.PostTitle,rec.PostURL));                id++;                <span style="color: #0000ff">if</span> (id &gt;= numberToGet)                {                    <span style="color: #0000ff">break</span>;                }            }            <span style="color: #0000ff">return</span> rssItems;                            }

    }

    <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> RSSItem    {        [DataObjectField(<span style="color: #0000ff">true</span>)]        <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> Id { get; set; }

        [DataObjectField(<span style="color: #0000ff">false</span>)]        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> PostTitle { get; set; }

        [DataObjectField(<span style="color: #0000ff">false</span>)]        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> PostURL { get; set; }

        <span style="color: #0000ff">public</span> RSSItem(<span style="color: #0000ff">int</span> id, <span style="color: #0000ff">string</span> postTitle,                        <span style="color: #0000ff">string</span> postURL)        {            Id = id;            PostTitle = postTitle;            PostURL = postURL;        }    }}</pre>
<p></div>
<p>Then, in the Default.aspx page, you can simply reference this object with a <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.aspx">Repeater</a> and an <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.aspx">ObjectDataSource</a> and you are done!&#160; That is it, very simple.&#160; Below is the page code.</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:ObjectDataSource</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">=&quot;ObjectDataSourceRSS&quot;</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span>   <span style="color: #ff0000">SelectMethod</span><span style="color: #0000ff">=&quot;Get&quot;</span> <span style="color: #ff0000">TypeName</span><span style="color: #0000ff">=&quot;App_Code.RSSFeedObject&quot;</span><span style="color: #0000ff">&gt;</span>   <span style="color: #0000ff">&lt;</span><span style="color: #800000">SelectParameters</span><span style="color: #0000ff">&gt;</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:Parameter</span> <span style="color: #ff0000">DefaultValue</span><span style="color: #0000ff">=&quot;5&quot;</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">=&quot;numberToGet&quot;</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">=&quot;Int32&quot;</span> <span style="color: #0000ff">/&gt;</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">SelectParameters</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">asp:ObjectDataSource</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:Repeater</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">=&quot;RepeaterRSS&quot;</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span> <span style="color: #ff0000">DataSourceID</span><span style="color: #0000ff">=&quot;ObjectDataSourceRSS&quot;</span><span style="color: #0000ff">&gt;</span>   <span style="color: #0000ff">&lt;</span><span style="color: #800000">HeaderTemplate</span><span style="color: #0000ff">&gt;</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">ul</span><span style="color: #0000ff">&gt;</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">HeaderTemplate</span><span style="color: #0000ff">&gt;</span>   <span style="color: #0000ff">&lt;</span><span style="color: #800000">FooterTemplate</span><span style="color: #0000ff">&gt;</span>       <span style="color: #0000ff">&lt;/</span><span style="color: #800000">ul</span><span style="color: #0000ff">&gt;</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">FooterTemplate</span><span style="color: #0000ff">&gt;</span>   <span style="color: #0000ff">&lt;</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">&gt;</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;</span>           <span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:HyperLink</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">=&quot;HyperLinkURL&quot;</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span>                <span style="color: #ff0000">NavigateUrl</span><span style="color: #0000ff">='&lt;%# Eval(&quot;PostURL&quot;) %&gt;'</span>               <span style="color: #ff0000">Text</span><span style="color: #0000ff">='&lt;%# Eval(&quot;PostTitle&quot;) %&gt;'</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">asp:HyperLink</span><span style="color: #0000ff">&gt;</span>       <span style="color: #0000ff">&lt;/</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">asp:Repeater</span><span style="color: #0000ff">&gt;</span></pre>
<p></div>
<p>I’m sure someone is going to point out how this could have been done in three lines of code.&#160; Until then, I’ll keep this in the Silicon Valley Code Camp site.</p>
<p>BTW, if the site looks different, it’s because a wizard html/css guy has come by and cleaned it up to look good. What you see in the top screen shot is what it looks like without any formatting.&#160; Just unordered list and listitems with no formatting.</p>
<p>HTH’s!</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2010/09/12/simplerssreader-in-silicon-valley-code-camp-objectdatasource-repeater-aspnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Override ToString() in a Simple C# Class</title>
		<link>http://peterkellner.net/2010/07/26/override-tostring-csharp-simple/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=override-tostring-csharp-simple</link>
		<comments>http://peterkellner.net/2010/07/26/override-tostring-csharp-simple/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 18:25:50 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2010/07/26/override-tostring-csharp-simple/</guid>
		<description><![CDATA[So, you have a simple class that has a bunch public properties and you want to be able to use ToString() on it to show some data?&#160; It’s easy.&#160; All you have to do is override the ToString() class inside your C# code.
So, here is an example class that does that.

public class DbProgressReport{   [...]]]></description>
			<content:encoded><![CDATA[<p>So, you have a simple class that has a bunch public properties and you want to be able to use <a href="http://msdn.microsoft.com/en-us/library/system.object.tostring.aspx">ToString()</a> on it to show some data?&#160; It’s easy.&#160; All you have to do is override the ToString() class inside your <a href="http://msdn.microsoft.com/en-us/vcsharp/default.aspx">C#</a> code.</p>
<p>So, here is an example class that does that.</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> DbProgressReport{    <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> ScopeNameProgress { get; set; }    <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> SourceOrDestination { get; set; }    <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> TableName { get; set; }    <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> TotalRecords { get; set; }    <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> ChangesApplied { get; set; }    <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> ChangesFailed { get; set; }    <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> ChangesPending { get; set; }    <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> Deletes { get; set; }    <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> Inserts { get; set; }    <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> TotalChanges { get; set; }    <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> Updates { get; set; }    <span style="color: #0000ff">public</span> DateTime LastChangeDate { get; set; }

    <span style="color: #0000ff">public</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">string</span> ToString()    {        <span style="color: #0000ff">string</span> readableDbProgressReport =            <span style="color: #0000ff">string</span>.Format(                <span style="color: #006080">&quot;{0} ScopeName {1},Table {2},TotalRecords {3}&quot;</span>                SourceOrDestination, ScopeNameProgress, TableName);

        <span style="color: #0000ff">return</span> readableDbProgressReport;    }    ...</pre>
<p></div>
<p>Now, all you have to do when accessing this class is use the ToString property.</p>
<p>That is:</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">DbProgressReport dbProgressReport =   <span style="color: #0000ff">new</span> DbProgressReport(<span style="color: #006080">&quot;source&quot;</span>,<span style="color: #006080">&quot;scopename&quot;</span>,<span style="color: #006080">&quot;tablename&quot;</span>);<span style="color: #0000ff">string</span> str = dbProgressReport.ToString();</pre>
<p></div>
<p>and the output will be:</p>
<p>source ScopeName scopename,&#160; Table tablename</p>
<p>Simple as that!</p>
<p>Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2010/07/26/override-tostring-csharp-simple/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Clear the Data From an Umbraco to Start From Scratch</title>
		<link>http://peterkellner.net/2010/07/12/reset-umbraco-install-webpi-windows7/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=reset-umbraco-install-webpi-windows7</link>
		<comments>http://peterkellner.net/2010/07/12/reset-umbraco-install-webpi-windows7/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 18:08:24 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[Umbraco]]></category>
		<category><![CDATA[WebPI]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2010/07/12/reset-umbraco-install-webpi-windows7/</guid>
		<description><![CDATA[In my previous post (http://peterkellner.net/2010/07/10/installing-umbraco-to-win7-step-by-step/), I detailed the steps to use WebPI to install a fresh version of Umbraco on a Windows 7 Ultimate 64 bit system.&#160; Now that I’ve done that, and played with it for a few hours, I’d like to start again with a fresh (no RunWay) set of data to play [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous post (<a title="http://peterkellner.net/2010/07/10/installing-umbraco-to-win7-step-by-step/" href="http://peterkellner.net/2010/07/10/installing-umbraco-to-win7-step-by-step/">http://peterkellner.net/2010/07/10/installing-umbraco-to-win7-step-by-step/</a>), I detailed the steps to use <a href="http://www.microsoft.com/web/downloads/platform.aspx">WebPI</a> to install a fresh version of <a href="http://umbraco.org/">Umbraco</a> on a <a href="http://www.microsoft.com/windows/windows-7/compare/ultimate.aspx">Windows 7 Ultimate 64 bit system</a>.&#160; Now that I’ve done that, and played with it for a few hours, I’d like to start again with a fresh (no RunWay) set of data to play with.</p>
<p>I posted on the Umbraco forums and got some tips, but I thought I’d document the process here because I’m sure I’m going to be doing this again and thought it best to have some notes I can go back to (and that might help others newbie&#8217;s to Umbraco while I’m at it).</p>
<p> <span id="more-1343"></span>
<p>So, let’s assume you have an Umbraco installation up and running.&#160; First thing you want to do is drop the sqlserver database you assigned to umbraceo (in my case umbracodb), re-add it and make sure you set the umbracoUser to have rights to that database.&#160; I’ll skip those steps because they don’t have much to do with umbraco.</p>
<p>Now, let’s assume you have done the above and now launch WebPI and chose Umbraco CMS again.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/HowToCleartheDataFromanUmbracotoStartFro_9A70/image.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/HowToCleartheDataFromanUmbracotoStartFro_9A70/image_thumb.png" width="415" height="322" /></a> </p>
<p>Continue to the first step after accepting the install options and make sure you select the name of your existing web site (mine is umbraco) and name the application name (which can be different than it was before).</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/HowToCleartheDataFromanUmbracotoStartFro_9A70/image_3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/HowToCleartheDataFromanUmbracotoStartFro_9A70/image_thumb_3.png" width="416" height="311" /></a> </p>
<p>Ignore this warning by saying “Yes”</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/HowToCleartheDataFromanUmbracotoStartFro_9A70/image_4.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/HowToCleartheDataFromanUmbracotoStartFro_9A70/image_thumb_4.png" width="244" height="94" /></a> </p>
<p>Now, fill in the next page with your db details (same as before)</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/HowToCleartheDataFromanUmbracotoStartFro_9A70/image_5.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/HowToCleartheDataFromanUmbracotoStartFro_9A70/image_thumb_5.png" width="344" height="242" /></a> </p>
<p>&#160;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/HowToCleartheDataFromanUmbracotoStartFro_9A70/image_6.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/HowToCleartheDataFromanUmbracotoStartFro_9A70/image_thumb_6.png" width="368" height="259" /></a> </p>
<p>I changed the default to “Use Existing Database” and updated my databasename correctly (as well as put the name of the server, W500, that has my sqlserver installed).</p>
<p>Saying continue, causes it to run for a few minutes (without much feedback or warning so be patient).</p>
<p>Then, Success!</p>
<p>&#160;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/HowToCleartheDataFromanUmbracotoStartFro_9A70/image_7.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/HowToCleartheDataFromanUmbracotoStartFro_9A70/image_thumb_7.png" width="349" height="246" /></a> </p>
<p>&#160;</p>
<p>For some reason, I need to go back to inetmgr (IIS Manager) and make the umbraco web site started and stop all the others running on port 80 (see my last post for this).&#160; Once you do that, I found that I need to go into the web.config and comment out the version number so that the umbracoConfigurationStatus line looks like this:</p>
<p>&#160;</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">key</span><span style="color: #0000ff">=&quot;umbracoConfigurationStatus&quot;</span> <span style="color: #ff0000">value</span><span style="color: #0000ff">=&quot;&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<p></div>
<p>After doing that, I could browse to the URL:&#160; <a title="http://localhost/install/default.aspx" href="http://localhost/install/default.aspx">http://localhost/install/default.aspx</a></p>
<p>Get a screen:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/HowToCleartheDataFromanUmbracotoStartFro_9A70/image_8.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/HowToCleartheDataFromanUmbracotoStartFro_9A70/image_thumb_8.png" width="273" height="323" /></a> </p>
<p>Chose Next and then go through the same screens as before.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/HowToCleartheDataFromanUmbracotoStartFro_9A70/image_9.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/HowToCleartheDataFromanUmbracotoStartFro_9A70/image_thumb_9.png" width="244" height="144" /></a> </p>
<p>etc., then finally get to a screen that correctly tells me I have work do do because I have not added any pages.</p>
<p>That’s it!&#160; Again, I’m still new to this and I’m sure making lots of mistakes.&#160; Please correct me if I’m wrong by making comments and make suggestions of the correct way to do it.</p>
<p>HTH’s!</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2010/07/12/reset-umbraco-install-webpi-windows7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)
Database Caching 31/36 queries in 0.007 seconds using disk: basic
Content Delivery Network via Amazon Web Services: S3: PetersBlogCDN.s3.amazonaws.com

Served from: peterkellner.net @ 2012-05-22 10:41:51 -->
