<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Joe Stevens&#039; Blog</title>
	<atom:link href="http://joestevens.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://joestevens.wordpress.com</link>
	<description>Everything .NET and C#</description>
	<lastBuildDate>Fri, 10 Jul 2009 03:39:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='joestevens.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Joe Stevens&#039; Blog</title>
		<link>http://joestevens.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://joestevens.wordpress.com/osd.xml" title="Joe Stevens&#039; Blog" />
	<atom:link rel='hub' href='http://joestevens.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Open Flash Chart</title>
		<link>http://joestevens.wordpress.com/2009/07/10/open-flash-chart/</link>
		<comments>http://joestevens.wordpress.com/2009/07/10/open-flash-chart/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 03:35:44 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://joestevens.wordpress.com/?p=138</guid>
		<description><![CDATA[Open flash chart is on open source project written by my brother-in-law.  It is actually used by WordPress to show the Stats charts. http://teethgrinder.co.uk/open-flash-chart/<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=joestevens.wordpress.com&amp;blog=7980660&amp;post=138&amp;subd=joestevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Open flash chart is on open source project written by my brother-in-law.  It is actually used by WordPress to show the Stats charts.</p>
<p><a href="http://teethgrinder.co.uk/open-flash-chart/" target="_blank">http://teethgrinder.co.uk/open-flash-chart/</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/joestevens.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/joestevens.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/joestevens.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/joestevens.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/joestevens.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/joestevens.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/joestevens.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/joestevens.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/joestevens.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/joestevens.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/joestevens.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/joestevens.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/joestevens.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/joestevens.wordpress.com/138/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=joestevens.wordpress.com&amp;blog=7980660&amp;post=138&amp;subd=joestevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://joestevens.wordpress.com/2009/07/10/open-flash-chart/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5f2e9694486862628e397e5e098ac47a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Joe</media:title>
		</media:content>
	</item>
		<item>
		<title>Linq to SQL with WCF Services</title>
		<link>http://joestevens.wordpress.com/2009/07/10/linq-to-sql-with-wcf-services/</link>
		<comments>http://joestevens.wordpress.com/2009/07/10/linq-to-sql-with-wcf-services/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 03:32:37 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Linq]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Linq To SQL]]></category>

		<guid isPermaLink="false">http://joestevens.wordpress.com/?p=121</guid>
		<description><![CDATA[I was interested to see how I could use Linq to SQL with WCF Services to load and save data using a Silverlight project.  In this post I will expand upon the database I created in my Linq to SQL Tutorial and the console application I wrote for my Set inheritance modifiers with SQLMetal post. The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=joestevens.wordpress.com&amp;blog=7980660&amp;post=121&amp;subd=joestevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was interested to see how I could use Linq to SQL with WCF Services to load and save data using a Silverlight project.  In this post I will expand upon the database I created in my <a href="http://joestevens.wordpress.com/2009/07/01/linq-to-sql-tutorial/" target="_blank">Linq to SQL Tutorial</a> and the console application I wrote for my <a href="http://joestevens.wordpress.com/2009/07/01/linq-to-sql-set-inheritance-modifiers-with-sqlmetal/" target="_blank">Set inheritance modifiers with SQLMetal</a> post.</p>
<p>The first step is to enable serialisation on my Linq entities so that they can be sent over the wire. To do this in the O/R Designer you can select the white space of the designer and view the DataContext properties.  Set the property called Serialization Mode to Unidirectional:</p>
<p><img class="alignnone size-full wp-image-122" title="Linq Serialization Mode Property" src="http://joestevens.files.wordpress.com/2009/07/linqwcf_datacontext_properties.jpg?w=500" alt="Linq Serialization Mode Property"   /></p>
<p>If using SQLMetal you can use the serialization command line argument:</p>
<p><pre class="brush: bash;">
SQLMetal.exe&quot;/server:localhost /database:University /dbml:University.dbml &lt;strong&gt;/serialization:unidirectional&lt;/strong&gt; /namespace:Entities /context:UniversityDataContext /pluralize
</pre></p>
<p>Enabling unidirectional serialization in either of these two ways adds the necessary <a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.aspx" target="_blank">DataContract</a> and <a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute.aspx" target="_blank">DataMember</a> attributes to the generated entities and properties:</p>
<p><pre class="brush: csharp;">
[Table(Name=&quot;dbo.Student&quot;)]
[DataContract()]
public partial class Student : EntityBase, INotifyPropertyChanging, INotifyPropertyChanged
{
    ....

    [Column(Storage=&quot;_Forename&quot;, DbType=&quot;NVarChar(50) NOT NULL&quot;, CanBeNull=false, UpdateCheck=UpdateCheck.Never)]
    [DataMember(Order=3)]
    public string Forename
    {
        ....
    }
}
</pre></p>
<p>The entities are now in a state where they can be serialised and sent down the wire.  In my WCF service I have a method that returns a list of my Linq to SQL Student entity:</p>
<p><pre class="brush: csharp;">
public List&lt;Student&gt; GetStudents()
{
    using (_context)
    {
        return _context.Students.ToList();
    }
}
</pre></p>
<p>These entities can then be easily used by the client, in this case the Silverlight application:</p>
<p><pre class="brush: csharp;">

UniversityContractClient _proxy = new UniversityContractClient();

private void PopulateStudents()
{
    _proxy.GetStudentsCompleted += new EventHandler&lt;GetStudentsCompletedEventArgs&gt;(proxy_GetStudentsCompleted);
    _proxy.GetStudentsAsync();
}

void proxy_GetStudentsCompleted(object sender, GetStudentsCompletedEventArgs e)
{
    dgStudents.ItemsSource = e.Result;
}

</pre></p>
<p>Here I am using the list to populate a DataGrid:</p>
<p><img class="alignnone size-full wp-image-123" title="Linq WCF Datagrid" src="http://joestevens.files.wordpress.com/2009/07/linqwcf_datagrid.jpg?w=500&#038;h=64" alt="Linq WCF Datagrid" width="500" height="64" /></p>
<p>This is all very straight forward, but the next step to update the data it a little more complex.  Here is my service method to save a Student entity created or updated by the client:</p>
<p><pre class="brush: csharp;">
public void SaveStudent(Student student)
{
    using (_context)
    {
        if (student.IsNew)
        {
            _context.Students.InsertOnSubmit(student);
        }
        else
        {
            _context.Students.Attach(student, true);
        }
               
        _context.SubmitChanges();
    }
}
</pre></p>
<p>Here I am using the IsNew property I created in my <a href="http://joestevens.wordpress.com/2009/07/01/linq-to-sql-set-inheritance-modifiers-with-sqlmetal/" target="_blank">Set inheritance modifiers with SQLMetal</a> post to check if the entity is to be inserted or updated.  The insert code is simple enough, but for the update we have to attach the entity to the DataContext as it has been modified outside of the DataContext&#8217;s scope.  I&#8217;m at doing this using the Attach method of the Student table, passing true for the asModified parameter to state that the entity has been updated.</p>
<p>In my Silverlight application I have a DataForm which calls this method passing the updated Student entity:</p>
<p><img class="alignnone size-full wp-image-124" title="Linq WCF DataForm" src="http://joestevens.files.wordpress.com/2009/07/linqwcf_dataform.jpg?w=500&#038;h=208" alt="Linq WCF DataForm" width="500" height="208" /></p>
<p>At this point inserting data will work, but when I try to update an entity the service method will throw the following error when trying to attach the entity:</p>
<p><em>An entity can only be attached as modified without original state if it declares a version member or does not have an update check policy.</em></p>
<p>This occurs because the entity was modified outside of the scope of the DataContext, so Linq to SQL doesn&#8217;t know what has changed about the entity and what to update.  To overcome this we can use a Timestamp column.  The Timestamp is a byte array which is used for versioning.  Linq to SQL knows to check this column to see if an object has been updated.  In my database I have changed the Student table so that it has a field called Timestamp, of type timestamp which doesn&#8217;t allow NULLs:</p>
<p><img class="alignnone size-full wp-image-125" title="Linq WCF Timestamp Field" src="http://joestevens.files.wordpress.com/2009/07/linqwcf_timestamp_field.jpg?w=500" alt="Linq WCF Timestamp Field"   /></p>
<p>When adding the new column, the O/R Designer automatically knows this is a timetamp column and sets the Time Stamp and Auto Generated Value properties to true:</p>
<p><img class="alignnone size-full wp-image-133" title="Linq WCF Timestamp Properties" src="http://joestevens.files.wordpress.com/2009/07/linqwcf_timestamp_properties1.jpg?w=500" alt="Linq WCF Timestamp Properties"   /></p>
<p> </p>
<p>SQLMetal will also detect a column with the timestamp type and set the necessary attributes.</p>
<p>With this timestamp column set up it will now be possible to successfully update an entity that was changed by the client.</p>
<p>In my example if I try to update the entity twice it will throw the following exception when trying to submit the changes:</p>
<p><em>Row not found or changed.</em></p>
<p>This is because the client doesn&#8217;t have the entity with the updated timestamp.  Also when adding a new entity the entity at the client won&#8217;t have the updated ID identity column so trying to update this will create another entity.  To resolve this I can change my SaveStudent service method to return the updated Student entity:</p>
<p><pre class="brush: csharp;">

public Student SaveStudent(Student student)
{
    using (_context)
    {
        if (student.IsNew)
        {
            _context.Students.InsertOnSubmit(student);
        }
        else
        {
            _context.Students.Attach(student, true);
        }
               
        _context.SubmitChanges();
    }

    return student;
}

</pre></p>
<p>In my Silverlight application I then pass the hash code for the object as the userState when calling the asyncronus service method:</p>
<p><pre class="brush: csharp;">
_proxy.SaveStudentAsync(student, student.GetHashCode());
</pre></p>
<p>This user state can then be obtained in the callback EventArgs class using e.UserState.  Using this I get the correct object from my collection, update it and reassign the source for my DataGrid and DataForm:</p>
<p><pre class="brush: csharp;">
void _proxy_SaveStudentCompleted(object sender, SaveStudentCompletedEventArgs e)
{
    ObservableCollection&lt;Student&gt; students = (ObservableCollection&lt;Student&gt;)dgStudents.ItemsSource;
    Student student = students.Where(s =&gt; s.GetHashCode() == Convert.ToInt32(e.UserState)).First();
    if (student.ID == 0)
    {
        student.ID = e.Result.ID;
    }
    student.Timestamp = e.Result.Timestamp;
    dgStudents.ItemsSource = students;
    dfStudent.ItemsSource = students;
}
</pre></p>
<p>This is all well and good and works as expected but what I really wanted to do was have an UpdateDate column which holds the date of the last update which could be used as a timestamp.  I replaced my current Timestamp column with an UpdateDate column:</p>
<p><img class="alignnone size-full wp-image-130" title="Linq WCF UpdateDate Field" src="http://joestevens.files.wordpress.com/2009/07/linqwcf_updatedate_field1.jpg?w=500" alt="Linq WCF UpdateDate Field"   /></p>
<p>The default for the new column is set to getdate() to automatically populate with the current date when creating a new record:</p>
<p><img class="alignnone size-full wp-image-131" title="Linq WCF UpdateDate Default" src="http://joestevens.files.wordpress.com/2009/07/linqwcf_updatedate_default1.jpg?w=500&#038;h=90" alt="Linq WCF UpdateDate Default" width="500" height="90" /></p>
<p>Using the O/R Designer this field can be set to a timestamp by setting the Time Stamp property to True, which will automatically set Auto Generated Value to True.</p>
<p>As I am using SQLMetal I can update the console application I wrote in my <a href="http://joestevens.wordpress.com/2009/07/01/linq-to-sql-set-inheritance-modifiers-with-sqlmetal/" target="_blank">Set inheritance modifiers with SQLMetal post</a> to add an IsVersion attribute to the DBML XML as well as the Modifier attribute:</p>
<p><pre class="brush: csharp;">

.... code omitted ....

//Find the column node
if (child.Name.Equals(&quot;Column&quot;))
{
    if (child.Attributes[&quot;Name&quot;].Value.Equals(&quot;ID&quot;))
    {
        //Create the Modifier attribute to add to ID column
        XmlAttribute modifierAttribute = xmlDoc.CreateAttribute(&quot;Modifier&quot;);
        modifierAttribute.Value = &quot;Override&quot;;
        child.Attributes.Append(modifierAttribute);
    }
    else if (child.Attributes[&quot;Name&quot;].Value.Equals(&quot;UpdateDate&quot;))
    {
        //Create the IsVersion attribute to add to UpdateDate column
        XmlAttribute versionAttribute = xmlDoc.CreateAttribute(&quot;IsVersion&quot;);
        versionAttribute.Value = &quot;True&quot;;
        child.Attributes.Append(versionAttribute);
    }
}

.... code omitted ....

</pre></p>
<p>Doing this adds the following values to the Column attribute on the UpdateDate property in the Student entity.  You can see IsVersion=true which tells Linq to SQL this property is the timestamp.</p>
<p><pre class="brush: csharp;">
[Column(Storage=&quot;_UpdateDate&quot;, AutoSync=AutoSync.Always, DbType=&quot;DateTime NOT NULL&quot;, IsDbGenerated=true, IsVersion=true, UpdateCheck=UpdateCheck.Never)]
</pre></p>
<p>At this point everything works okay, but the UpdateDate is not refreshed on update.  To fix this add a trigger that sets the date on update:</p>
<p><pre class="brush: sql;">
ALTER TRIGGER trg_UpdateDate
ON dbo.Student
FOR UPDATE
AS
    UPDATE      Student
    SET         UpdateDate = getdate()
    WHERE       (ID IN (SELECT ID FROM Inserted))
</pre></p>
<p>The UpdateDate is now set for each update and is used by Linq to SQL as the timestamp.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/joestevens.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/joestevens.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/joestevens.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/joestevens.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/joestevens.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/joestevens.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/joestevens.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/joestevens.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/joestevens.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/joestevens.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/joestevens.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/joestevens.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/joestevens.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/joestevens.wordpress.com/121/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=joestevens.wordpress.com&amp;blog=7980660&amp;post=121&amp;subd=joestevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://joestevens.wordpress.com/2009/07/10/linq-to-sql-with-wcf-services/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5f2e9694486862628e397e5e098ac47a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Joe</media:title>
		</media:content>

		<media:content url="http://joestevens.files.wordpress.com/2009/07/linqwcf_datacontext_properties.jpg" medium="image">
			<media:title type="html">Linq Serialization Mode Property</media:title>
		</media:content>

		<media:content url="http://joestevens.files.wordpress.com/2009/07/linqwcf_datagrid.jpg" medium="image">
			<media:title type="html">Linq WCF Datagrid</media:title>
		</media:content>

		<media:content url="http://joestevens.files.wordpress.com/2009/07/linqwcf_dataform.jpg" medium="image">
			<media:title type="html">Linq WCF DataForm</media:title>
		</media:content>

		<media:content url="http://joestevens.files.wordpress.com/2009/07/linqwcf_timestamp_field.jpg" medium="image">
			<media:title type="html">Linq WCF Timestamp Field</media:title>
		</media:content>

		<media:content url="http://joestevens.files.wordpress.com/2009/07/linqwcf_timestamp_properties1.jpg" medium="image">
			<media:title type="html">Linq WCF Timestamp Properties</media:title>
		</media:content>

		<media:content url="http://joestevens.files.wordpress.com/2009/07/linqwcf_updatedate_field1.jpg" medium="image">
			<media:title type="html">Linq WCF UpdateDate Field</media:title>
		</media:content>

		<media:content url="http://joestevens.files.wordpress.com/2009/07/linqwcf_updatedate_default1.jpg" medium="image">
			<media:title type="html">Linq WCF UpdateDate Default</media:title>
		</media:content>
	</item>
		<item>
		<title>Linq To SQL &#8211; Set inheritance modifiers with SQLMetal</title>
		<link>http://joestevens.wordpress.com/2009/07/01/linq-to-sql-set-inheritance-modifiers-with-sqlmetal/</link>
		<comments>http://joestevens.wordpress.com/2009/07/01/linq-to-sql-set-inheritance-modifiers-with-sqlmetal/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 05:34:26 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Linq]]></category>
		<category><![CDATA[base class]]></category>
		<category><![CDATA[entitybase]]></category>
		<category><![CDATA[Linq To SQL]]></category>
		<category><![CDATA[sqlmetal]]></category>

		<guid isPermaLink="false">http://joestevens.wordpress.com/?p=116</guid>
		<description><![CDATA[I have created an base class which my entities inherit from that gives a property called IsNew which returns true if the the value of ID is 0; all of my tables use ID for the identifier. For this to work each of my entities need to use the override modifier for the ID property.  Using [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=joestevens.wordpress.com&amp;blog=7980660&amp;post=116&amp;subd=joestevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have created an base class which my entities inherit from that gives a property called IsNew which returns true if the the value of ID is 0; all of my tables use ID for the identifier.</p>
<p><pre class="brush: csharp;">
 

public abstract class EntityBase
{
    public virtual int ID { get; set; }

    public bool IsNew
    {
        get
        {
            return ID == 0;
        }
    }
}

</pre><br />
For this to work each of my entities need to use the override modifier for the ID property.  Using the O/R Designer it is possible to set the inheritance modifier for each property, but this is not possible using SQLMetal and I need to use SQLMetal to set the base class.</p>
<p>To overcome this I have a batch file that first creates my .dbml file using SQLMetal:</p>
<p><pre class="brush: bash;">
SQLMetal.exe /server:localhost /database:University /dbml:University.dbml /namespace:Entities /context:UniversityDataContext /pluralize
</pre></p>
<p>I then run a console application to find column nodes with the name of ID, and add the Modifier attribute:</p>
<p><pre class="brush: bash;">
EntityProcessor.exe University.dbml
</pre></p>
<p>The code for EntityProcessor looks like this:</p>
<p><pre class="brush: csharp;">
 

static void Main(string[] args)
{
    try
    {
        //Ensure there is an argument for the DBML file
        if (args.Count() == 0)
        {
            throw new ApplicationException(&quot;DBML path expected.&quot;);
        }

        string dbml = args[0];

        //Load the DBML file
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(dbml);

        //Loop through the tables
        foreach (XmlNode node in xmlDoc.GetElementsByTagName(&quot;Table&quot;))
        {
            //Loop through the nodes for the type
            foreach (XmlNode child in node.FirstChild.ChildNodes)
            {
                //Find the ID column node
                if (child.Name.Equals(&quot;Column&quot;) &amp;&amp; child.Attributes[&quot;Name&quot;].Value.Equals(&quot;ID&quot;))
                {
                    //Create the modifier attribute to add to ID column
                    XmlAttribute modifierAttribute = xmlDoc.CreateAttribute(&quot;Modifier&quot;);
                    modifierAttribute.Value = &quot;Override&quot;;
                    child.Attributes.Append(modifierAttribute);
                }
            }
        }

        //Save the updated DBML file
        xmlDoc.Save(dbml);

        Console.WriteLine(&quot;Processing complete&quot;);
    }
    catch (Exception ex)
    {
        Console.WriteLine(&quot;An error occured: {0}&quot;, ex.Message);
    }
}

</pre><br />
Finally I use SQLMetal again to create my entities from the updated .dbml file:</p>
<p><pre class="brush: bash;">
SQLMetal.exe /code:University.cs /entitybase:EntityBase /namespace:Entities University.dbml
</pre></p>
<p>My new entities now have an ID property with an overrides modifier that looks like this:</p>
<p><pre class="brush: csharp;">
[Column(Storage=&quot;_ID&quot;, AutoSync=AutoSync.OnInsert, DbType=&quot;Int NOT NULL IDENTITY&quot;, IsPrimaryKey=true, IsDbGenerated=true)]
public override int ID
{
    get
    {
        return this._ID;
    }
    set
    {
        if ((this._ID != value))
        {
            this.OnIDChanging(value);
            this.SendPropertyChanging();
            this._ID = value;
            this.SendPropertyChanged(&quot;ID&quot;);
            this.OnIDChanged();
        }
    }
}
</pre></p>
<p>I can now call IsNew on any of my entities to check if they have been inserted into the database.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/joestevens.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/joestevens.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/joestevens.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/joestevens.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/joestevens.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/joestevens.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/joestevens.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/joestevens.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/joestevens.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/joestevens.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/joestevens.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/joestevens.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/joestevens.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/joestevens.wordpress.com/116/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=joestevens.wordpress.com&amp;blog=7980660&amp;post=116&amp;subd=joestevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://joestevens.wordpress.com/2009/07/01/linq-to-sql-set-inheritance-modifiers-with-sqlmetal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5f2e9694486862628e397e5e098ac47a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Joe</media:title>
		</media:content>
	</item>
		<item>
		<title>Linq To SQL &#8211; EntityBase &#8211; Base class for entities</title>
		<link>http://joestevens.wordpress.com/2009/07/01/linq-to-sql-entitybase-base-class-for-entities/</link>
		<comments>http://joestevens.wordpress.com/2009/07/01/linq-to-sql-entitybase-base-class-for-entities/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 04:52:53 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Linq]]></category>
		<category><![CDATA[base class]]></category>
		<category><![CDATA[entitybase]]></category>
		<category><![CDATA[Linq To SQL]]></category>
		<category><![CDATA[sqlmetal]]></category>

		<guid isPermaLink="false">http://joestevens.wordpress.com/?p=113</guid>
		<description><![CDATA[When using Linq To SQL you may often find yourself in a position where you want each of your entities to inherit from a base class.  As generated classes are partial classes you could create a second partial class for each entity which inherits a base class, but this is inpractical.  The O/R designer does [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=joestevens.wordpress.com&amp;blog=7980660&amp;post=113&amp;subd=joestevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When using Linq To SQL you may often find yourself in a position where you want each of your entities to inherit from a base class.  As generated classes are partial classes you could create a second partial class for each entity which inherits a base class, but this is inpractical.  The O/R designer does not give you the option for a base entity class but it can be achieved using the <a href="http://msdn.microsoft.com/en-us/library/bb386987.aspx" target="_blank">SQLMetal</a> command line tool.</p>
<p>SQLMetal allows you to create a .dbml file or a code file containing your entities.  <a href="http://sourceforge.net/projects/sqlmetalbuilder" target="_blank">SQLMetal Builder</a> is a provides a simple user interface for the command line tool and also generates batch files.</p>
<p>I have created an abstract class called EntityBase which I want all of my generated entities to inherit. I can use the following arguments with SQLMetal in order to create my entities that inherit this class.</p>
<p><pre class="brush: bash;">
SQLMetal.exe /server:localhost /database:University /code:University.cs /namespace:Entities /context:UniversityDataContext /entitybase:EntityBase /pluralize
</pre></p>
<p>SQLMetal will look at server localhost and the database University.  It will create the entities in an file called University.cs with the namespace Entities.  The DataContext will be called UniversityDataContext and all entities will inherit EntityBase.  I am also using the pluralize argument which plurlises the table names, for example Student become Students;  I find this is more intuative when writing queries.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/joestevens.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/joestevens.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/joestevens.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/joestevens.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/joestevens.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/joestevens.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/joestevens.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/joestevens.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/joestevens.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/joestevens.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/joestevens.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/joestevens.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/joestevens.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/joestevens.wordpress.com/113/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=joestevens.wordpress.com&amp;blog=7980660&amp;post=113&amp;subd=joestevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://joestevens.wordpress.com/2009/07/01/linq-to-sql-entitybase-base-class-for-entities/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5f2e9694486862628e397e5e098ac47a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Joe</media:title>
		</media:content>
	</item>
		<item>
		<title>Linq To SQL Tutorial</title>
		<link>http://joestevens.wordpress.com/2009/07/01/linq-to-sql-tutorial/</link>
		<comments>http://joestevens.wordpress.com/2009/07/01/linq-to-sql-tutorial/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 23:04:06 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Linq]]></category>
		<category><![CDATA[Linq To SQL]]></category>

		<guid isPermaLink="false">http://joestevens.wordpress.com/?p=94</guid>
		<description><![CDATA[This is a basic tutorial for using Linq To SQL introducing some of the concepts behind it. For this tutorial I have created a simple database for a University.  I will probably use this database and expand on it for any future posts where a database is required.  Below you can see the structure of the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=joestevens.wordpress.com&amp;blog=7980660&amp;post=94&amp;subd=joestevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is a basic tutorial for using Linq To SQL introducing some of the concepts behind it.</p>
<p>For this tutorial I have created a simple database for a University.  I will probably use this database and expand on it for any future posts where a database is required.  Below you can see the structure of the database.</p>
<p><img class="alignnone size-full wp-image-95" title="ERD" src="http://joestevens.files.wordpress.com/2009/06/linqtosql_erd.jpg?w=500&#038;h=588" alt="ERD" width="500" height="588" /></p>
<p>Create a new website called Universities and add a second project called DAL to the solution.  This is the Data Access Layer where we will create the Linq To SQL classes.</p>
<p><img class="alignnone size-full wp-image-97" title="Universities Solution" src="http://joestevens.files.wordpress.com/2009/06/linqtosql_solution1.jpg?w=500" alt="Universities Solution"   /></p>
<p>Right-click on the DAL project and select Add &gt; New Item.  From the dialog choose &#8216;LINQ to SQL Classes&#8217; and call the file University.dbml.</p>
<p><img class="alignnone size-full wp-image-98" title="New Linq to SQL file" src="http://joestevens.files.wordpress.com/2009/06/linqtosql_newlinqtosql.jpg?w=500" alt="New Linq to SQL file"   /></p>
<p>The .dbml extension stands for Database Markup Language.  The file itself is essentially an XML file that describes the database which is used to generate our classes.  When you add your new dbml file the <a href="http://msdn.microsoft.com/en-us/library/bb384429.aspx" target="_blank">Object Relational Designer</a> (O/R Designer) should launch which is a visual tool for creating your model.  There is also a command-line tool called <a href="http://msdn.microsoft.com/en-us/library/bb386987.aspx" target="_blank">SqlMetal</a> which gives you further control over how your model is created.  In this instance we will use the O/R Designer.</p>
<p>Locate your database in the Server Explorer window <em>(View &gt; Server Explorer)</em>, and drag and drop the tables to use onto the surface of the O/R Designer.  The result should look like this:</p>
<p><img class="alignnone size-full wp-image-99" title="Object Relational Designer" src="http://joestevens.files.wordpress.com/2009/06/linqtosql_ord.jpg?w=500&#038;h=341" alt="Object Relational Designer" width="500" height="341" /></p>
<p>Save and close the the O/R desinger.  In solution explorer you should see the University.dbml file, expanding this shows two other files, University.dbml.layout and University.designer.cs.</p>
<p><img class="alignnone size-full wp-image-100" title="Solution Explorer" src="http://joestevens.files.wordpress.com/2009/06/linqtosql_solution2.jpg?w=500" alt="Solution Explorer"   /></p>
<p>Examine University.designer.cs and you will find your DataContext which inherits <a href="http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.aspx" target="_blank">System.Data.Linq.DataContext</a>, and your model classes which were generated from the dbml file.  These classes are all partial classes which allows you to easily build them out to add extra functionality which won&#8217;t be affected if you need to regenerate from the dbml.</p>
<p>At this point we are now ready to use the generated classes.  In the website create a reference to the DAL project, and to System.Data.Linq.</p>
<p><img class="alignnone size-full wp-image-101" title="linqtosql_referencelinq" src="http://joestevens.files.wordpress.com/2009/06/linqtosql_referencelinq.jpg?w=500" alt="linqtosql_referencelinq"   /></p>
<p>Create a simple form to add a new Student with a GridView to display the current students. It should look something like this:</p>
<p><img class="alignnone size-full wp-image-103" title="Student Form" src="http://joestevens.files.wordpress.com/2009/06/linqtosql_form.jpg?w=500&#038;h=495" alt="Student Form" width="500" height="495" /></p>
<p>Firstly we want to bind the data from the Title table in the database to the Title DropDownList on the form.  Manually add some data to this table such as Mr, Mrs and Miss.  In the Page_Load event handler put a (!Page.IsPostBack) condition and call the following method:</p>
<p><pre class="brush: csharp;">
private void PopulateTitles()
{
    using (UniversityDataContext context = new UniversityDataContext())
    {
        ddlTitle.DataSource = context.Titles;
        ddlTitle.DataTextField = &quot;Name&quot;;
        ddlTitle.DataValueField = &quot;ID&quot;;
        ddlTitle.DataBind();
    }
}
</pre></p>
<p>This method first creates an instance of our DataContext to use.  We then set the DataSource of the DropDownList to context.Title which is of type <a href="http://msdn.microsoft.com/en-us/library/bb358844.aspx" target="_blank">System.Data.Linq.Table</a>.  We can query this object further, but in this instace I want all rows from the table.  The DataTextField and DataValueField properties are set to the relevant properties of the Title object.  Run the application and the Title dropdown will be populated with the values from the database.</p>
<p>The next step is to create a new student and save it to the database.  Call the following method from the Save button event handler.</p>
<p><pre class="brush: csharp;">

private void SaveStudent()
{
    using (UniversityDataContext context = new UniversityDataContext())
    {
        Student newStudent = new Student()
        {
            TitleID = Convert.ToInt32(ddlTitle.SelectedValue),
            Forename = txtForename.Text,
            Surname = txtSurname.Text,
            DOB = Convert.ToDateTime(txtDOB.Text),
            EmailAddress = string.IsNullOrEmpty(txtEmail.Text) ? null : txtEmail.Text,
            Phone = string.IsNullOrEmpty(txtPhone.Text) ? null : txtPhone.Text
        };

        context.Students.InsertOnSubmit(newStudent);
        context.SubmitChanges();
    }
}

</pre></p>
<p>We are creating a new Student object and setting the properties of that object based on the form values.  We are using an <a href="http://msdn.microsoft.com/en-us/library/bb384062.aspx" target="_blank">Object Initializer</a> which allows setting the properties of the object without having to explicity envoke a constructor.  The penultimate line adds our newly created object to the table in a pending state, then calling the <a href="http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.submitchanges.aspx" target="_blank">SubmitChanges</a> method on the DataContext submits any pending changes in the context.</p>
<p>Now that there is data in our Student table it would be good to be able to see it.  Add the following method to our code and call it from the Page_Load event handler.</p>
<p><pre class="brush: csharp;">

private void PopulateStudents()
{
    using (UniversityDataContext context = new UniversityDataContext())
    {
        var students = from s in context.Students
                       select new
                       {
                           Title = s.Title.Name,
                           Forename = s.Forename,
                           Surname = s.Surname,
                           DOB = s.DOB.ToShortDateString(),
                           EmailAddress = s.EmailAddress,
                           Phone = s.Phone
                       };

        gvStudents.DataSource = students;
        gvStudents.DataBind();
    }
}

</pre></p>
<p>This method uses a Linq query to assign an <a href="http://msdn.microsoft.com/en-us/library/bb397696.aspx" target="_blank">Anonymous Type</a> using the var keyword.  We could bind context.Students to the GridView as we did with the Titles, but in this instance I want the Name of the Title for the student using context.Student.Title.Name and I also want to show the DOB without the time.  The Linq query is selecting all rows in the Students table, and creating a collection of the Anonymous Type setting each of its properties.  We then set the datasource of the GridView to this collection and call DataBind.</p>
<p>I hope this tutorial gives a good overview of Linq To SQL for anybody new to it.  In the real world you would probably not access your object model directly from the page, but write a repository model that handles all the data access and DataContext.  I will write more about how to do this at a later date.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/joestevens.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/joestevens.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/joestevens.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/joestevens.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/joestevens.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/joestevens.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/joestevens.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/joestevens.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/joestevens.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/joestevens.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/joestevens.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/joestevens.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/joestevens.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/joestevens.wordpress.com/94/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=joestevens.wordpress.com&amp;blog=7980660&amp;post=94&amp;subd=joestevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://joestevens.wordpress.com/2009/07/01/linq-to-sql-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5f2e9694486862628e397e5e098ac47a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Joe</media:title>
		</media:content>

		<media:content url="http://joestevens.files.wordpress.com/2009/06/linqtosql_erd.jpg" medium="image">
			<media:title type="html">ERD</media:title>
		</media:content>

		<media:content url="http://joestevens.files.wordpress.com/2009/06/linqtosql_solution1.jpg" medium="image">
			<media:title type="html">Universities Solution</media:title>
		</media:content>

		<media:content url="http://joestevens.files.wordpress.com/2009/06/linqtosql_newlinqtosql.jpg" medium="image">
			<media:title type="html">New Linq to SQL file</media:title>
		</media:content>

		<media:content url="http://joestevens.files.wordpress.com/2009/06/linqtosql_ord.jpg" medium="image">
			<media:title type="html">Object Relational Designer</media:title>
		</media:content>

		<media:content url="http://joestevens.files.wordpress.com/2009/06/linqtosql_solution2.jpg" medium="image">
			<media:title type="html">Solution Explorer</media:title>
		</media:content>

		<media:content url="http://joestevens.files.wordpress.com/2009/06/linqtosql_referencelinq.jpg" medium="image">
			<media:title type="html">linqtosql_referencelinq</media:title>
		</media:content>

		<media:content url="http://joestevens.files.wordpress.com/2009/06/linqtosql_form.jpg" medium="image">
			<media:title type="html">Student Form</media:title>
		</media:content>
	</item>
		<item>
		<title>Resize image with Silverlight and FJCore before uploading to server</title>
		<link>http://joestevens.wordpress.com/2009/06/22/resize-image-with-silverlight-and-fjcore-before-uploading-to-server/</link>
		<comments>http://joestevens.wordpress.com/2009/06/22/resize-image-with-silverlight-and-fjcore-before-uploading-to-server/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 00:56:06 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[fjcore]]></category>
		<category><![CDATA[image resize]]></category>
		<category><![CDATA[resize image]]></category>

		<guid isPermaLink="false">http://joestevens.wordpress.com/?p=88</guid>
		<description><![CDATA[I have a Silverlight application which allows the user to select images from their local PC which are then uploaded to a server via a WCF Service. It is easy enough to resize the image once it gets to the server, but this would still mean that the full image is being sent over the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=joestevens.wordpress.com&amp;blog=7980660&amp;post=88&amp;subd=joestevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have a Silverlight application which allows the user to select images from their local PC which are then uploaded to a server via a WCF Service.</p>
<p>It is easy enough to resize the image once it gets to the server, but this would still mean that the full image is being sent over the wire.</p>
<p>In Silverlight 2 there are no built in features that allow us to do the resizing at the client, but it can be achieved using an open source imaging library called <a href="http://code.google.com/p/fjcore/" target="_blank">FJCore</a>.</p>
<p>To get the FJCore source from Subversion I use an open source plug-in for Visual Studio called <a href="http://ankhsvn.open.collab.net/" target="_blank">AnkhSVN</a>.  It is then possible to build the solution and add a reference to the FJCore library to my own solution.</p>
<p>In my application I allow the user to select multiple files using the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.openfiledialog(VS.95).aspx" target="_blank">OpenFileDialog</a> which are then processed as byte arrays and sent to the server via the WCF Service.  Before doing the upload I am using FJCore to check if the image needs to be resized, and if so resize the image.</p>
<p>The resizing requires the following using statements.</p>
<p><pre class="brush: csharp;">
using FluxJpeg.Core;
using FluxJpeg.Core.Decoder;
using FluxJpeg.Core.Filtering;
using FluxJpeg.Core.Encoder;
</pre></p>
<p>The following code shows how to use FJCore to take the files selected with the OpenFileDialog and do the resizing before calling the service method to upload to the server.  Here the maximum edge length is 640px, so if width or height is greater than 640px, the resize code is used to resize the maximum edge length to 640px while keeping perspective.</p>
<p><pre class="brush: csharp;">

OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = &quot;JPEG Files (*.jpg;*.jpeg)|*.jpg;*.jpeg&quot;;
ofd.Multiselect = true;

if (ofd.ShowDialog().GetValueOrDefault(false))
{
    //The path to upload the files on the server
    string serverPath = &quot;d:\uploads&quot;;

    foreach (FileInfo image in ofd.Files)
    {
        FileStream stream = image.OpenRead();
        using (stream)
        {
            byte[] data;
                       
            //Decode image
            DecodedJpeg origJpeg = new JpegDecoder(stream).Decode();

            //Check if the image needs resizing
            if (ImageResizer.ResizeNeeded(origJpeg.Image, 640))
            {
                //Resize image
                DecodedJpeg resizedJpeg =
                    new DecodedJpeg(new ImageResizer(origJpeg.Image).Resize(640, ResamplingFilters.NearestNeighbor), origJpeg.MetaHeaders);

                //Encode resized image
                MemoryStream resizedStream = new MemoryStream();
                new JpegEncoder(resizedJpeg, 100, resizedStream).Encode();

                //Read resized stream to byte array
                resizedStream.Seek(0, SeekOrigin.Begin);
                data = new byte[resizedStream.Length];
                resizedStream.Read(data, 0, Convert.ToInt32(resizedStream.Length));
            }
            else
            {
                //Read original stream to byte array
                stream.Seek(0, SeekOrigin.Begin);
                data = new byte[stream.Length];
                stream.Read(data, 0, Convert.ToInt32(stream.Length));
            }

            //Upload image via service
            GalleryContractClient proxy = new GalleryContractClient();
            proxy.UploadImageCompleted += new EventHandler&lt;UploadImageCompletedEventArgs&gt;(proxy_UploadImageCompleted);
            proxy.UploadImageAsync(serverPath, image.Name, data);
        }
    }
}

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/joestevens.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/joestevens.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/joestevens.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/joestevens.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/joestevens.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/joestevens.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/joestevens.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/joestevens.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/joestevens.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/joestevens.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/joestevens.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/joestevens.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/joestevens.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/joestevens.wordpress.com/88/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=joestevens.wordpress.com&amp;blog=7980660&amp;post=88&amp;subd=joestevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://joestevens.wordpress.com/2009/06/22/resize-image-with-silverlight-and-fjcore-before-uploading-to-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5f2e9694486862628e397e5e098ac47a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Joe</media:title>
		</media:content>
	</item>
		<item>
		<title>Enum description using reflection and extension methods</title>
		<link>http://joestevens.wordpress.com/2009/06/18/enum-description-using-reflection-and-extension-methods/</link>
		<comments>http://joestevens.wordpress.com/2009/06/18/enum-description-using-reflection-and-extension-methods/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 05:31:17 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[enum]]></category>
		<category><![CDATA[enumeration]]></category>
		<category><![CDATA[extension methods]]></category>
		<category><![CDATA[reflection]]></category>

		<guid isPermaLink="false">http://joestevens.wordpress.com/?p=67</guid>
		<description><![CDATA[I don&#8217;t take credit for this as it was written by another developer on the the project, but I thought it was good and worth writing about. On the current project I&#8217;m working on we use a lot of enumerations for statuses which are shown in drop-down lists and grids. It can get a bit [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=joestevens.wordpress.com&amp;blog=7980660&amp;post=67&amp;subd=joestevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>I don&#8217;t take credit for this as it was written by another developer on the the project, but I thought it was good and worth writing about.</strong></p>
<p>On the current project I&#8217;m working on we use a lot of enumerations for statuses which are shown in drop-down lists and grids. It can get a bit ugly from a UI perspective when simply using the ToString method as enumeration values cannot have spaces and are usually shortened for ease of use when coding.</p>
<p>One way to overcome this is to add a description attribute to each enumeration value and write an extension method that uses reflection to obtain the value in the description attribute.</p>
<p>The description attribute is part of the <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.aspx" target="_blank">System.ComponentModel</a> namespace so we need to import this.  The attribute value can then be set on each enumeration value:</p>
<p><pre class="brush: csharp;">
public enum Status : int
{
    [Description(&quot;Application pending&quot;)]
    Pending = 0,
    [Description(&quot;Application received&quot;)]
    Received = 1,
    [Description(&quot;Application processing in progress&quot;)]
    Processing = 2,
    [Description(&quot;Application processed&quot;)]
    Processed = 3
}
</pre></p>
<p>The next step is to create the <a href="http://msdn.microsoft.com/en-us/library/bb383977.aspx" target="_blank">extension method</a>.  Extension methods were introduced in  C# 3 and allow you to easily add new methods to existing types.  Scott Guthrie has a good blog post on them <a href="http://weblogs.asp.net/scottgu/archive/2007/03/13/new-orcas-language-feature-extension-methods.aspx" target="_blank">here</a>.  Extensions methods need to be static, and contained in a static class.  In the method signature the &#8216;this&#8217; keyword is used to indicate which type the extension method is for.  Below is the extension method that will get the description attribute for an enumeration using reflection.</p>
<p><pre class="brush: csharp;">
public static string Description(this Enum enumeration)
{
    string value = enumeration.ToString();
    Type type = enumeration.GetType();
    //Use reflection to try and get the description attribute for the enumeration
    DescriptionAttribute[] descAttribute = (DescriptionAttribute[])type.GetField(value).GetCustomAttributes(typeof(DescriptionAttribute), false);
    return descAttribute.Length &gt; 0 ? descAttribute[0].Description : value;
}
</pre></p>
<p>Any enumeration will now have a method called Description that will try to return the value of the description attribute, and if the attribute is not present return the result of calling ToString.  For example:</p>
<p><pre class="brush: csharp;">
Console.WriteLine(Status.Processing.Description());
</pre></p>
<p> <br />
Will display:</p>
<p><img class="alignnone size-full wp-image-69" title="exmethod1" src="http://joestevens.files.wordpress.com/2009/06/exmethod1.jpg?w=500&#038;h=251" alt="exmethod1" width="500" height="251" /></p>
<p>As the extension method is for Enum, and not just the Status enumeration I created, we could do this:</p>
<p><pre class="brush: csharp;">
Array values = Enum.GetValues(typeof(Status));
foreach (Enum e in values)
    Console.WriteLine(&quot;{0} - {1}&quot;, e, e.Description());
</pre></p>
<p>The result here would be:</p>
<p><img title="exmethod2" src="http://joestevens.files.wordpress.com/2009/06/exmethod2.jpg?w=500&#038;h=251" alt="exmethod2" width="500" height="251" /></p>
<p>There are lots of uses for extension methods which are used extensively with Linq, but I particularly like this idea to provide a more readable value for an enumeration.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/joestevens.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/joestevens.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/joestevens.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/joestevens.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/joestevens.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/joestevens.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/joestevens.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/joestevens.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/joestevens.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/joestevens.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/joestevens.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/joestevens.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/joestevens.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/joestevens.wordpress.com/67/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=joestevens.wordpress.com&amp;blog=7980660&amp;post=67&amp;subd=joestevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://joestevens.wordpress.com/2009/06/18/enum-description-using-reflection-and-extension-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5f2e9694486862628e397e5e098ac47a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Joe</media:title>
		</media:content>

		<media:content url="http://joestevens.files.wordpress.com/2009/06/exmethod1.jpg" medium="image">
			<media:title type="html">exmethod1</media:title>
		</media:content>

		<media:content url="http://joestevens.files.wordpress.com/2009/06/exmethod2.jpg" medium="image">
			<media:title type="html">exmethod2</media:title>
		</media:content>
	</item>
		<item>
		<title>Simple double click in Silverlight</title>
		<link>http://joestevens.wordpress.com/2009/06/05/simple-double-click-in-silverlight/</link>
		<comments>http://joestevens.wordpress.com/2009/06/05/simple-double-click-in-silverlight/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 04:56:20 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://joestevens.wordpress.com/?p=61</guid>
		<description><![CDATA[I needed to pick up on a double click on an image in Silverlight but there is no event to handle this. It can be done quite easily using a DispatchTimer.  I am doing this for an image but you should be able to do it for any UIElement. First I have imported the System.Windows.Theading namespace [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=joestevens.wordpress.com&amp;blog=7980660&amp;post=61&amp;subd=joestevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I needed to pick up on a double click on an image in Silverlight but there is no event to handle this. It can be done quite easily using a DispatchTimer.  I am doing this for an image but you should be able to do it for any UIElement.</p>
<p>First I have imported the System.Windows.Theading namespace where the DispatchTimer lives.  In the constructor of the User Control containing the image I have instantiated the Timer and set its interval to 200 milliseconds, this is the amount of time allowed between clicks for it to be considered a double click.  I have also added a listener to the Tick event of the Timer which fires with each iteration.</p>
<p><pre class="brush: csharp;">
 
using System.Windows.Threading;

public partial class Image : UserControl
{
    DispatcherTimer _timer;

    public Image()
    {
        InitializeComponent();

        _timer = new DispatcherTimer();
        _timer.Interval = new TimeSpan(0, 0, 0, 0, 200);
        _timer.Tick += new EventHandler(_timer_Tick);
    }
}

</pre></p>
<p>My event handler for the Image&#8217;s MouseLeftButtonDown will check if the Timer has already been started, and if so we know this is a double click, if not we start the timer.  The first time the event is raised the timer won&#8217;t be started, but the second time, on the second click it will be so this is our double click.</p>
<p><pre class="brush: csharp;">
private void imgImage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    if (_timer.IsEnabled)
    {
        MessageBox.Show(&quot;Double Click&quot;);
    }
        else
    {
        _timer.Start();
    }
}
</pre></p>
<p>Finally I handle the Tick event of the Timer, and simply stop the timer so that after 200 milliseconds the timer is no longer active, and any subsequent clicks are not counted as the second click of a double click.</p>
<p><pre class="brush: csharp;">
void _timer_Tick(object sender, EventArgs e)
{
    _timer.Stop();
}
</pre></p>
<p>This is a fairly basic and not very reusable but does the job for what I need.  You could also use the GetPosition property of MouseButtonEventArgs to make sure that the mouse hasn&#8217;t moved between clicks.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/joestevens.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/joestevens.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/joestevens.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/joestevens.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/joestevens.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/joestevens.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/joestevens.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/joestevens.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/joestevens.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/joestevens.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/joestevens.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/joestevens.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/joestevens.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/joestevens.wordpress.com/61/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=joestevens.wordpress.com&amp;blog=7980660&amp;post=61&amp;subd=joestevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://joestevens.wordpress.com/2009/06/05/simple-double-click-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5f2e9694486862628e397e5e098ac47a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Joe</media:title>
		</media:content>
	</item>
		<item>
		<title>Setting the SelectedItem in a Silverlight TreeView</title>
		<link>http://joestevens.wordpress.com/2009/06/04/setting-the-selecteditem-in-a-silverlight-treeview/</link>
		<comments>http://joestevens.wordpress.com/2009/06/04/setting-the-selecteditem-in-a-silverlight-treeview/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 06:56:49 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://joestevens.wordpress.com/?p=56</guid>
		<description><![CDATA[I wanted to select a specific item in my Silverlight TreeView programatically.  Looking at the TreeView.SelectedItem property the setter is not public so it cannot be done this way. If you are simply adding TreeViewItems to the TreeView you can cast the item you want to select in the Items collection to a TreeViewItem and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=joestevens.wordpress.com&amp;blog=7980660&amp;post=56&amp;subd=joestevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I wanted to select a specific item in my Silverlight TreeView programatically.  Looking at the TreeView.SelectedItem property the setter is not public so it cannot be done this way.</p>
<p>If you are simply adding TreeViewItems to the TreeView you can cast the item you want to select in the Items collection to a TreeViewItem and set the IsSelected property to true. The following example will grab the first item and set it to selected.</p>
<p><pre class="brush: csharp;">
TreeViewItem item = tvDirectories.Items[0] as TreeViewItem;
item.IsSelected = true;
</pre></p>
<p>If you are binding a list of business objects to the TreeView this will not work as the Items collection will be a list of your object.  In this scenario you can use the ItemContainerGenerator property of the TreeView to get the underlying TreeViewItem.  In this example I have a collection of Gallery objects bound to my TreeView and am using the ContainerFromIndex method to get the TreeViewItem at position 0.</p>
<p><pre class="brush: csharp;">
TreeViewItem item = tvDirectories.ItemContainerGenerator.ContainerFromIndex(0) as TreeViewItem;
item.IsSelected = true;
</pre></p>
<p>The ItemContainerGenerator class also has a ContainerFromItem method that will get the TreeViewItem by passing it an instance of the business object you want to select.</p>
<p><pre class="brush: csharp;">
Gallery gallery = GetGallery(); //Some method that gets the object you want to select in the TreeView
TreeViewItem item = tvDirectories.ItemContainerGenerator.ContainerFromItem(gallery) as TreeViewItem;
item.IsSelected = true;
</pre></p>
<p>In my application I want to select the TreeViewItem based on the ServerPath of the Gallery object so I&#8217;m using some of the nifty Linq extension methods (<a href="http://msdn.microsoft.com/en-us/library/bb341406.aspx" target="_blank">Cast</a> and <a href="http://msdn.microsoft.com/en-us/library/bb535118.aspx" target="_blank">Single</a>) to get my business object.</p>
<p><pre class="brush: csharp;">
public void SelectGallery(string serverPath)
{
    Gallery gallery = tvDirectories.Items.Cast&lt;Gallery&gt;().Single(x =&gt; x.ServerPath.Equals(serverPath));
           
    if (gallery != null)
    {
        TreeViewItem item = tvDirectories.ItemContainerGenerator.ContainerFromItem(gallery) as TreeViewItem;
        item.IsSelected = true;
    }
}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/joestevens.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/joestevens.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/joestevens.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/joestevens.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/joestevens.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/joestevens.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/joestevens.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/joestevens.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/joestevens.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/joestevens.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/joestevens.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/joestevens.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/joestevens.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/joestevens.wordpress.com/56/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=joestevens.wordpress.com&amp;blog=7980660&amp;post=56&amp;subd=joestevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://joestevens.wordpress.com/2009/06/04/setting-the-selecteditem-in-a-silverlight-treeview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5f2e9694486862628e397e5e098ac47a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Joe</media:title>
		</media:content>
	</item>
		<item>
		<title>Disable enter submitting form with JavaScript</title>
		<link>http://joestevens.wordpress.com/2009/06/04/disable-enter-submitting-form-with-javascript/</link>
		<comments>http://joestevens.wordpress.com/2009/06/04/disable-enter-submitting-form-with-javascript/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 04:07:18 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://joestevens.wordpress.com/?p=49</guid>
		<description><![CDATA[On a project I was working on I was asked to disable the enter key submitting the form.  Usually it would be better just to ensure that hitting enter performed the correct action but if you do want to disable this you can do so with JavaScript. I created a JavaScript function called disableEnterSubmit which [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=joestevens.wordpress.com&amp;blog=7980660&amp;post=49&amp;subd=joestevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>On a project I was working on I was asked to disable the enter key submitting the form.  Usually it would be better just to ensure that hitting enter performed the correct action but if you do want to disable this you can do so with JavaScript.</p>
<p>I created a JavaScript function called disableEnterSubmit which takes in the event as a parameter as shown below.</p>
<p><pre class="brush: jscript;">
function disableEnterSubmit(e)
{
    if (e.keyCode)
       return (e.keyCode != 13); //IE
    else
        return (e.which != 13); //FireFox
}
</pre></p>
<p>The event has different properties for the code of the pressed key for Internet Explorer and FireFox. In Internet Explorer we use e.keyCode and for FireFox it&#8217;s e.which.  The function simply returns false if the key is enter (<a href="http://www.cambiaresearch.com/c4/702b8cd1-e5b0-42e6-83ac-25f0306e3e25/Javascript-Char-Codes-Key-Codes.aspx" target="_blank">key code 13</a>).</p>
<p>I then just need to set the onkeydown event in the body tag of my HTML to call the method.</p>
<p><pre class="brush: xml;">
&lt;body onkeydown=&quot;return disableEnterSubmit(event)&quot;&gt;
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/joestevens.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/joestevens.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/joestevens.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/joestevens.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/joestevens.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/joestevens.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/joestevens.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/joestevens.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/joestevens.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/joestevens.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/joestevens.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/joestevens.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/joestevens.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/joestevens.wordpress.com/49/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=joestevens.wordpress.com&amp;blog=7980660&amp;post=49&amp;subd=joestevens&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://joestevens.wordpress.com/2009/06/04/disable-enter-submitting-form-with-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5f2e9694486862628e397e5e098ac47a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Joe</media:title>
		</media:content>
	</item>
	</channel>
</rss>
