<?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>Sam Beauvois &#187; .NET</title>
	<atom:link href="http://www.sambeauvois.be/blog/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sambeauvois.be/blog</link>
	<description>general dev, .net and other stuff</description>
	<lastBuildDate>Tue, 31 Jan 2012 13:38:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Bring a bit of the Subsonic power to Entity Framework by adding automatic audit and logical delete fields</title>
		<link>http://www.sambeauvois.be/blog/2011/11/bring-a-bit-of-the-subsonic-power-to-entity-framework-by-adding-automatic-audit-and-logical-delete-fields/</link>
		<comments>http://www.sambeauvois.be/blog/2011/11/bring-a-bit-of-the-subsonic-power-to-entity-framework-by-adding-automatic-audit-and-logical-delete-fields/#comments</comments>
		<pubDate>Fri, 04 Nov 2011 16:04:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[SubSonic]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=915</guid>
		<description><![CDATA[Here is the code to do the same thing than in my previous article &#8220;Bring a bit of the Subsonic power to Linq to sql by adding automatic audit and logical delete fields&#8221; namespace YouNamespace.DAL { using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Data; using System.Data.Common; using System.Data.Objects; using System.Linq; public partial class [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the code to do the same thing than in my previous article <a href="http://www.sambeauvois.be/blog/2010/09/bring-a-bit-of-the-subsonic-power-to-linq-to-sql-by-adding-automatic-audit-and-logical-delete-fields/" target="_blank">&#8220;Bring a bit of the Subsonic power to Linq to sql by adding automatic audit and logical delete fields&#8221;</a></p>
<pre class="brush: csharp; title: ;">

namespace YouNamespace.DAL
{
 using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Data;
 using System.Data.Common;
 using System.Data.Objects;
 using System.Linq;

 public partial class YOURCONTEXTEntities
 {
 /// &lt;summary&gt;
 /// System fields for automatic audit and logical delete
 /// &lt;/summary&gt;
 private struct SystemFields
 {
 public const string CreatedOn = &quot;CREATEDON&quot;;
 public const string ModifiedOn = &quot;MODIFIEDON&quot;;
 public const string CreatedBy = &quot;CREATEDBY&quot;;
 public const string ModifiedBy = &quot;MODIFIEDBY&quot;;
 public const string IsDeleted = &quot;ISDELETED&quot;;
 }

 /// &lt;summary&gt;
 /// Overriding the SaveChanges method to automaticaly set system fields if any.
 /// &lt;/summary&gt;
 /// &lt;param name=&quot;options&quot;&gt;&lt;/param&gt;
 /// &lt;returns&gt;&lt;/returns&gt;
 public override int SaveChanges(System.Data.Objects.SaveOptions options)
 {
 IEnumerable&lt;ObjectStateEntry&gt; newEntries = this.ObjectStateManager.GetObjectStateEntries(EntityState.Added);

 foreach (ObjectStateEntry entry in newEntries)
 {
 ReadOnlyCollection&lt;FieldMetadata&gt; fieldsMetaData = entry.CurrentValues
 .DataRecordInfo.FieldMetadata;

 FieldMetadata createdOnField = fieldsMetaData
 .Where(f =&gt; string.Equals(f.FieldType.Name, SystemFields.CreatedOn, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

 if (createdOnField.FieldType != null)
 {
 entry.CurrentValues.SetValue(createdOnField.Ordinal, DateTime.Now);
 }

 FieldMetadata createdByField = fieldsMetaData
 .Where(f =&gt; string.Equals(f.FieldType.Name, SystemFields.CreatedBy, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

 if (createdByField.FieldType != null)
 {
 entry.CurrentValues.SetValue(createdByField.Ordinal, &quot;Sam&quot;);
 }

 FieldMetadata deletedField = fieldsMetaData
 .Where(f =&gt; string.Equals(f.FieldType.Name, SystemFields.IsDeleted, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

 if (deletedField.FieldType != null)
 {
 entry.CurrentValues.SetValue(deletedField.Ordinal, false);
 }
 }

 IEnumerable&lt;ObjectStateEntry&gt; modifiedEntries = this.ObjectStateManager.GetObjectStateEntries(EntityState.Modified);
 foreach (ObjectStateEntry entry in modifiedEntries)
 {
 ReadOnlyCollection&lt;FieldMetadata&gt; fieldsMetaData = entry.CurrentValues
 .DataRecordInfo.FieldMetadata;

 FieldMetadata createdOnField = fieldsMetaData
 .Where(f =&gt; string.Equals(f.FieldType.Name, SystemFields.ModifiedOn, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

 if (createdOnField.FieldType != null)
 {
 entry.CurrentValues.SetValue(createdOnField.Ordinal, DateTime.Now);
 }

 FieldMetadata createdByField = fieldsMetaData
 .Where(f =&gt; string.Equals(f.FieldType.Name, SystemFields.ModifiedBy, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

 if (createdByField.FieldType != null)
 {
 entry.CurrentValues.SetValue(createdByField.Ordinal, &quot;Sam&quot;);
 }
 }

 IEnumerable&lt;ObjectStateEntry&gt; deletedEntries = this.ObjectStateManager.GetObjectStateEntries(EntityState.Deleted);
 foreach (ObjectStateEntry entry in deletedEntries)
 {
 // change from deleted to modified (!important)
 this.ObjectStateManager.ChangeObjectState(entry.Entity, EntityState.Modified);

 ReadOnlyCollection&lt;FieldMetadata&gt; fieldsMetaData = entry.CurrentValues
 .DataRecordInfo.FieldMetadata;

 FieldMetadata deletedField = fieldsMetaData
 .Where(f =&gt; string.Equals(f.FieldType.Name, SystemFields.IsDeleted, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

 if (deletedField.FieldType != null)
 {
 entry.CurrentValues.SetValue(deletedField.Ordinal, true);
 }
else
 {
 // change back from modified to deleted (!important)
 this.ObjectStateManager.ChangeObjectState(entry.Entity, EntityState.Deleted);
 }
 }

 return base.SaveChanges(options);
 }
 }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2011/11/bring-a-bit-of-the-subsonic-power-to-entity-framework-by-adding-automatic-audit-and-logical-delete-fields/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Enum HasFlag method extension for &lt; 4.0 Framework</title>
		<link>http://www.sambeauvois.be/blog/2011/08/enum-hasflag-method-extension-for-4-0-framework/</link>
		<comments>http://www.sambeauvois.be/blog/2011/08/enum-hasflag-method-extension-for-4-0-framework/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 19:52:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=909</guid>
		<description><![CDATA[In the same idea than the previous article, here is an extension method to mimic the 4.0 HasFlag method (http://msdn.microsoft.com/en-us/library/system.enum.hasflag.aspx). /// &#60;summary&#62; /// Extentions for enums. /// &#60;/summary&#62; public static class EnumExtensions { /// &#60;summary&#62; /// A FX 3.5 way to mimic the FX4 &#34;HasFlag&#34; method. /// &#60;/summary&#62; /// &#60;param name=&#34;variable&#34;&#62;The tested enum.&#60;/param&#62; /// &#60;param [...]]]></description>
			<content:encoded><![CDATA[<p>In the same idea than the previous article, here is an extension method to mimic the 4.0 HasFlag method (<a href="http://msdn.microsoft.com/en-us/library/system.enum.hasflag.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/system.enum.hasflag.aspx</a>).</p>
<pre class="brush: csharp; title: ;">
     /// &lt;summary&gt;
    /// Extentions for enums.
    /// &lt;/summary&gt;
    public static class EnumExtensions
    {
        /// &lt;summary&gt;
        /// A FX 3.5 way to mimic the FX4 &quot;HasFlag&quot; method.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;variable&quot;&gt;The tested enum.&lt;/param&gt;
        /// &lt;param name=&quot;value&quot;&gt;The value to test.&lt;/param&gt;
        /// &lt;returns&gt;True if the flag is set. Otherwise false.&lt;/returns&gt;
        public static bool HasFlag(this Enum variable, Enum value)
        {
            // check if from the same type.
            if (variable.GetType() != value.GetType())
            {
                throw new ArgumentException(&quot;The checked flag is not from the same type as the checked variable.&quot;);
            }

            Convert.ToUInt64(value);
            ulong num = Convert.ToUInt64(value);
            ulong num2 = Convert.ToUInt64(variable);

            return (num2 &amp; num) == num;
        }
    }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2011/08/enum-hasflag-method-extension-for-4-0-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stream.CopyTo method for &lt; 4.0 framework</title>
		<link>http://www.sambeauvois.be/blog/2011/08/stream-copyto-method-for-4-0-framework/</link>
		<comments>http://www.sambeauvois.be/blog/2011/08/stream-copyto-method-for-4-0-framework/#comments</comments>
		<pubDate>Tue, 02 Aug 2011 18:47:19 +0000</pubDate>
		<dc:creator>Sam Beauvois</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=902</guid>
		<description><![CDATA[The .NET Framework 4.0 introduced the CopyTo() method for the Stream class. (http://msdn.microsoft.com/en-us/library/system.io.stream.copyto.aspx) You copy a stream into one other this way: MemoryStream memoryStream = new MemoryStream(); using (Stream stream = new FileStream(@&#34;c:\input.txt&#34;, FileMode.Open)) { stream.CopyTo(memoryStream); } If you are stucked with a lower version of the framework, you might want to use it anyway. [...]]]></description>
			<content:encoded><![CDATA[<p>The .NET Framework 4.0 introduced the CopyTo() method for the Stream class. (<a href="http://msdn.microsoft.com/en-us/library/system.io.stream.copyto.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/system.io.stream.copyto.aspx</a>)</p>
<p>You copy a stream into one other this way:</p>
<pre class="brush: csharp; title: ;">

   MemoryStream memoryStream = new MemoryStream();
   using (Stream stream = new FileStream(@&quot;c:\input.txt&quot;, FileMode.Open))
   {
      stream.CopyTo(memoryStream);
   }
</pre>
<p>If you are stucked with a lower version of the framework, you might want to use it anyway.</p>
<p>A bit of reflector is realy usefull to see how the implementation is done in 4.0.</p>
<p>The CopyTo method :</p>
<pre class="brush: csharp; title: ;">

public void CopyTo(Stream destination)
{
    if (destination == null)
    {
        throw new ArgumentNullException(&quot;destination&quot;);
    }
    if (!this.CanRead &amp;&amp; !this.CanWrite)
    {
        throw new ObjectDisposedException(null, Environment.GetResourceString(&quot;ObjectDisposed_StreamClosed&quot;));
    }
    if (!destination.CanRead &amp;&amp; !destination.CanWrite)
    {
        throw new ObjectDisposedException(&quot;destination&quot;, Environment.GetResourceString(&quot;ObjectDisposed_StreamClosed&quot;));
    }
    if (!this.CanRead)
    {
        throw new NotSupportedException(Environment.GetResourceString(&quot;NotSupported_UnreadableStream&quot;));
    }
    if (!destination.CanWrite)
    {
        throw new NotSupportedException(Environment.GetResourceString(&quot;NotSupported_UnwritableStream&quot;));
    }
    this.InternalCopyTo(destination, 0x1000);
}
</pre>
<p>We see that the InternalCopyTo is used :</p>
<pre class="brush: csharp; title: ;">

private void InternalCopyTo(Stream destination, int bufferSize)
{
    int num;
    byte[] buffer = new byte[bufferSize];
    while ((num = this.Read(buffer, 0, buffer.Length)) != 0)
    {
        destination.Write(buffer, 0, num);
    }
}
</pre>
<p>Remark :<br />
0&#215;1000 is in hexadecimal, which corresponds to 4096 in decimal.</p>
<p>So we can retrieve that for use with lower versions of the language</p>
<p>For .NET FX >= 3.0 you can create an extension method</p>
<pre class="brush: csharp; title: ;">

    using System;
    using System.IO;

    /// &lt;summary&gt;
    /// Extension methods for streams.
    /// &lt;/summary&gt;
    public static class StreamExtensions
    {
        /// &lt;summary&gt;
        /// Reads all the bytes from the current stream and writes them to the destination stream.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;original&quot;&gt;The current stream.&lt;/param&gt;
        /// &lt;param name=&quot;destination&quot;&gt;The stream that will contain the contents of the current stream.&lt;/param&gt;
        /// &lt;exception cref=&quot;System.ArgumentNullException&quot;&gt;Destination is null.&lt;/exception&gt;
        /// &lt;exception cref=&quot;System.NotSupportedException&quot;&gt;The current stream does not support reading.-or-destination does not support Writing.&lt;/exception&gt;
        /// &lt;exception cref=&quot;System.ObjectDisposedException&quot;&gt;Either the current stream or destination were closed before the System.IO.Stream.CopyTo(System.IO.Stream) method was called.&lt;/exception&gt;
        /// &lt;exception cref=&quot;System.IO.IOException&quot;&gt;An I/O error occurred.&lt;/exception&gt;
        public static void CopyTo(this Stream original, Stream destination)
        {
            if (destination == null)
            {
                throw new ArgumentNullException(&quot;destination&quot;);
            }
            if (!original.CanRead &amp;&amp; !original.CanWrite)
            {
                throw new ObjectDisposedException(&quot;ObjectDisposedException&quot;);
            }
            if (!destination.CanRead &amp;&amp; !destination.CanWrite)
            {
                throw new ObjectDisposedException(&quot;ObjectDisposedException&quot;);
            }
            if (!original.CanRead)
            {
                throw new NotSupportedException(&quot;NotSupportedException source&quot;);
            }
            if (!destination.CanWrite)
            {
                throw new NotSupportedException(&quot;NotSupportedException destination&quot;);
            }

            byte[] array = new byte[4096];
            int count;
            while ((count = original.Read(array, 0, array.Length)) != 0)
            {
                destination.Write(array, 0, count);
            }
        }
    }
</pre>
<p>You use it this way (same ways as the FX 4.0):</p>
<pre class="brush: csharp; title: ;">

   MemoryStream memoryStream = new MemoryStream();
   using (Stream stream = new FileStream(@&quot;c:\input.txt&quot;, FileMode.Open))
   {
      stream.CopyTo(memoryStream);
   }
</pre>
<p>For lower version, you can create an helper class.</p>
<pre class="brush: csharp; title: ;">

    using System;
    using System.IO;

    /// &lt;summary&gt;
    /// An helper class for streams.
    /// &lt;/summary&gt;
    public class StreamHelper
    {
        /// &lt;summary&gt;
        /// Reads all the bytes from the current stream and writes them to the destination stream.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;original&quot;&gt;The original stream.&lt;/param&gt;
        /// &lt;param name=&quot;destination&quot;&gt;The stream that will contain the contents of the current stream.&lt;/param&gt;
        /// &lt;exception cref=&quot;System.ArgumentNullException&quot;&gt;Destination is null.&lt;/exception&gt;
        /// &lt;exception cref=&quot;System.NotSupportedException&quot;&gt;The current stream does not support reading.-or-destination does not support Writing.&lt;/exception&gt;
        /// &lt;exception cref=&quot;System.ObjectDisposedException&quot;&gt;Either the current stream or destination were closed before the System.IO.Stream.CopyTo(System.IO.Stream) method was called.&lt;/exception&gt;
        /// &lt;exception cref=&quot;System.IO.IOException&quot;&gt;An I/O error occurred.&lt;/exception&gt;
        public static void CopyStreamTo(Stream original, Stream destination)
        {
            if (destination == null)
            {
                throw new ArgumentNullException(&quot;destination&quot;);
            }
            if (!original.CanRead &amp;&amp; !original.CanWrite)
            {
                throw new ObjectDisposedException(&quot;ObjectDisposedException&quot;);
            }
            if (!destination.CanRead &amp;&amp; !destination.CanWrite)
            {
                throw new ObjectDisposedException(&quot;ObjectDisposedException&quot;);
            }
            if (!original.CanRead)
            {
                throw new NotSupportedException(&quot;NotSupportedException source&quot;);
            }
            if (!destination.CanWrite)
            {
                throw new NotSupportedException(&quot;NotSupportedException destination&quot;);
            }

            byte[] array = new byte[4096];
            int count;
            while ((count = original.Read(array, 0, array.Length)) != 0)
            {
                destination.Write(array, 0, count);
            }
        }
    }
</pre>
<p>Use it this way:</p>
<pre class="brush: csharp; title: ;">

   MemoryStream memoryStream = new MemoryStream();
   using (Stream stream = new FileStream(@&quot;c:\input.txt&quot;, FileMode.Open))
   {
        StreamHelper.CopyStreamTo(stream, memoryStream);
   }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2011/08/stream-copyto-method-for-4-0-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Chanel 9 &#124; Rx Workshop: Unified Programming Model</title>
		<link>http://www.sambeauvois.be/blog/2011/08/chanel-9-rx-workshop-unified-programming-model/</link>
		<comments>http://www.sambeauvois.be/blog/2011/08/chanel-9-rx-workshop-unified-programming-model/#comments</comments>
		<pubDate>Tue, 02 Aug 2011 14:46:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Quick posts]]></category>
		<category><![CDATA[Reminders]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=912</guid>
		<description><![CDATA[Learn how to wrap existing event sources, including tasks, asynchronous methods, .NET events, etc. in observable sequences.]]></description>
			<content:encoded><![CDATA[<p><iframe style="height:288px;width:512px" src="http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Unified-Programming-Model/player?w=512&#038;h=288" frameBorder="0" scrolling="no" ></iframe></p>
<p>Learn how to wrap existing event sources, including tasks, asynchronous methods, .NET events, etc. in observable sequences.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2011/08/chanel-9-rx-workshop-unified-programming-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET videos : Choosing the Right Programming Model</title>
		<link>http://www.sambeauvois.be/blog/2011/06/asp-net-videos-choosing-the-right-programming-model/</link>
		<comments>http://www.sambeauvois.be/blog/2011/06/asp-net-videos-choosing-the-right-programming-model/#comments</comments>
		<pubDate>Sun, 12 Jun 2011 20:34:09 +0000</pubDate>
		<dc:creator>Sam Beauvois</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=897</guid>
		<description><![CDATA[As mentioned by Kris van der Mast on the asp.net forums, this video was on the get started page before, but don&#8217;t appears to be there anymore. This video is great to know in 5 minutes which model is good for you. So, because I don&#8217;t want to search for it, I post this video [...]]]></description>
			<content:encoded><![CDATA[<p>As mentioned by <a href="http://blog.krisvandermast.com/" target="_blank">Kris van der Mast</a> on the asp.net forums, this video was on the get started page before, but don&#8217;t appears to be there anymore.</p>
<p>This video is great to know in 5 minutes which model is good for you.</p>
<p>So, because I don&#8217;t want to search for it, I post this video here :</p>
<p><object style="width:400px;height:338px;" autoupdate="true" data="data:application/x-silverlight-2," type="application/x-silverlight-2"><param value="2.0.31005.0" name="MinRuntimeVersion"/><param name="source" value="http://www.asp.net/clientbin/mediaplayer/MSCommunities.MediaPlayer.xap" /><param value="videoid=24686" name="InitParams"/><a href="http://go2.microsoft.com/fwlink/?LinkID=114576&amp;v=2.0"><img style="border-width: 0px;" alt="Install Silverlight" src="http://i2.asp.net/common/static-asp/asp.net/videos/silverlight.mediaplayer/slplayer_disabled.png?cdn_id=04302010"/></a></object></p>
<p>(<a href="http://www.asp.net/general/videos/choosing-the-right-programming-model" target="_blank">direct link</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2011/06/asp-net-videos-choosing-the-right-programming-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>One line how to&#8217;s : Save text in a file, or read text from a file.</title>
		<link>http://www.sambeauvois.be/blog/2011/06/one-line-how-tos-save-text-in-a-file-or-read-text-from-a-file/</link>
		<comments>http://www.sambeauvois.be/blog/2011/06/one-line-how-tos-save-text-in-a-file-or-read-text-from-a-file/#comments</comments>
		<pubDate>Sun, 12 Jun 2011 20:25:08 +0000</pubDate>
		<dc:creator>Sam Beauvois</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[HowTo]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=733</guid>
		<description><![CDATA[Sometimes your solution lies in a single line. How to save a string in a text file System.IO.File.WriteAllText(&#34;c://yourfile.txt&#34;, &#34;here is the content of my file !&#34;); How to read a text file string content =  System.IO.File.ReadAllText(&#34;c://yourfile.txt&#34;); How does it work ? A bit or Reflector gives us : For the write method public static void [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Sometimes your solution lies in a single line.</p></blockquote>
<h4>How to save a string in a text file</h4>
<pre class="brush: csharp; light: true; title: ;">

System.IO.File.WriteAllText(&quot;c://yourfile.txt&quot;,
&quot;here is the content of my file !&quot;);
</pre>
<h4>How to read a text file</h4>
<pre class="brush: csharp; light: true; title: ;">

string content =  System.IO.File.ReadAllText(&quot;c://yourfile.txt&quot;);
</pre>
<h5>How does it work ?</h5>
<p>A bit or Reflector gives us :</p>
<p>For the write method</p>
<pre class="brush: csharp; title: ;">

public static void WriteAllText(string path, string contents)
{
if (path == null)
{
throw new ArgumentNullException(&quot;path&quot;);
}
if (path.Length == 0)
{
throw new ArgumentException(Environment.GetResourceString(&quot;Argument_EmptyPath&quot;));
}
InternalWriteAllText(path, contents, StreamWriter.UTF8NoBOM);
}
</pre>
<p>and the &#8220;InternalWriteAllText&#8221; method :</p>
<pre class="brush: csharp; title: ;">

private static void InternalWriteAllText(string path, string contents, Encoding encoding)
{
using (StreamWriter writer = new StreamWriter(path, false, encoding))
{
writer.Write(contents);
}
}
</pre>
<p>For the Read method :</p>
<pre class="brush: csharp; title: ;">
public static string ReadAllText(string path)
{
    if (path == null)
    {
        throw new ArgumentNullException(&quot;path&quot;);
    }
    if (path.Length == 0)
    {
        throw new ArgumentException(Environment.GetResourceString(&quot;Argument_EmptyPath&quot;));
    }
    return InternalReadAllText(path, Encoding.UTF8);
}
</pre>
<p>And the &#8220;InternalReadAllText&#8221; :</p>
<pre class="brush: csharp; title: ;">
private static string InternalReadAllText(string path, Encoding encoding)
{
    using (StreamReader reader = new StreamReader(path, encoding))
    {
        return reader.ReadToEnd();
    }
}
</pre>
<p>As you can see it don&#8217;t check if the file exists, so you have to check it by yourself :</p>
<pre class="brush: csharp; title: ;">

if (System.IO.File.Exists(&quot;your file path&quot;))
{
string content = System.IO.File.ReadAllText(&quot;your file path&quot;);
}
</pre>
<div id="_mcePaste" class="mcePaste" style="position: absolute; left: -10000px; top: 313px; width: 1px; height: 1px; overflow: hidden;"><span style="color: #1000a0;">public</span> <span style="color: #1000a0;">static</span> <a title="System.String" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.String">string</a> <strong><a class="bold" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.IO.File/ReadAllText%28String%29:String">ReadAllText</a></strong>(<a title="System.String" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.String">string</a> path) {     <span style="color: #1000a0;">if</span> (<a title="string path; // Parameter">path</a> == <span style="color: #800000;">null</span>)     {         <span style="color: #1000a0;">throw</span> <span style="color: #1000a0;">new</span> <a title="System.ArgumentNullException.ArgumentNullException(string paramName);" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.ArgumentNullException/.ctor%28String%29">ArgumentNullException</a>(<span style="color: #800000;">&#8220;path&#8221;</span>);     }     <span style="color: #1000a0;">if</span> (<a title="string path; // Parameter">path</a>.<a title="int System.String.Length { ... }" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.String/property:Length:Int32">Length</a> == <span style="color: #800000;">0</span>)     {         <span style="color: #1000a0;">throw</span> <span style="color: #1000a0;">new</span> <a title="System.ArgumentException.ArgumentException(string message);" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.ArgumentException/.ctor%28String%29">ArgumentException</a>(<a title="System.Environment" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Environment">Environment</a>.<a title="string System.Environment.GetResourceString(string key);" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Environment/GetResourceString%28String%29:String">GetResourceString</a>(<span style="color: #800000;">&#8220;Argument_EmptyPath&#8221;</span>));     }     <span style="color: #1000a0;">return</span> <a title="string System.IO.File.InternalReadAllText(string path, Encoding encoding);" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.IO.File/InternalReadAllText%28String,System.Text.Encoding%29:String">InternalReadAllText</a>(<a title="string path; // Parameter">path</a>, <a title="System.Text.Encoding" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Text.Encoding">Encoding</a>.<a title="Encoding System.Text.Encoding.UTF8 { ... }" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:4.0.0.0:b77a5c561934e089/System.Text.Encoding/property:UTF8:System.Text.Encoding">UTF8</a>); }</div>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2011/06/one-line-how-tos-save-text-in-a-file-or-read-text-from-a-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>6+ sources of videocasts</title>
		<link>http://www.sambeauvois.be/blog/2011/03/6-sources-of-videocasts/</link>
		<comments>http://www.sambeauvois.be/blog/2011/03/6-sources-of-videocasts/#comments</comments>
		<pubDate>Thu, 03 Mar 2011 11:52:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Resources]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=868</guid>
		<description><![CDATA[Here is a list of sites where you can find videos to form youself and learn a bit of new things]]></description>
			<content:encoded><![CDATA[<p>Here is a list of sites where you can find videos to form youself and learn a bit of new things</p>

<!-- Beginning of Link Library Output -->

<div id='linklist8' class='linklist'>
<div class="">
	<table class='linklisttable'>
<p style='display:table;width:100%;'><a href="http://channel9.msdn.com/" id="162" class="track_this_link"  title="Channel 9 keeps you up to date with videos from people behind the scenes building products at Microsoft." target="_blank"><img src="http://open.thumbshots.org/image.aspx?url=http://channel9.msdn.com/" alt="Chanel 9" title="Channel 9 keeps you up to date with videos from people behind the scenes building products at Microsoft." class="alignleft" /></a> <a href="http://channel9.msdn.com/" id="162" class="track_this_link"  title="Channel 9 keeps you up to date with videos from people behind the scenes building products at Microsoft." target="_blank">Chanel 9</a>
<br/>Channel 9 keeps you up to date with videos from people behind the scenes building products at Microsoft.</p><br/>
<p style='display:table;width:100%;'><a href="http://channel9.msdn.com/Browse/Shows" id="166" class="track_this_link"  title="Different shows on Chanel 9" target="_blank"><img src="http://open.thumbshots.org/image.aspx?url=http://channel9.msdn.com/Browse/Shows" alt="Chanel 9 Shows !" title="Different shows on Chanel 9" class="alignleft" /></a> <a href="http://channel9.msdn.com/Browse/Shows" id="166" class="track_this_link"  title="Different shows on Chanel 9" target="_blank">Chanel 9 Shows !</a>
<br/>Different shows on Chanel 9</p><br/>
<p style='display:table;width:100%;'><a href="http://www.dnrtv.com/default.aspx" id="186" class="track_this_link"  title="dnrTv is a fusion of a training video and an interview show." target="_blank"><img src="http://open.thumbshots.org/image.aspx?url=http://www.dnrtv.com/default.aspx" alt="dnrTV" title="dnrTv is a fusion of a training video and an interview show." class="alignleft" /></a> <a href="http://www.dnrtv.com/default.aspx" id="186" class="track_this_link"  title="dnrTv is a fusion of a training video and an interview show." target="_blank">dnrTV</a>
<br/>dnrTv is a fusion of a training video and an interview show.</p><br/>
<p style='display:table;width:100%;'><a href="http://www.youtube.com/user/microsoftlearning" id="193" class="track_this_link"  title="Microsoft Learning Training" target="_blank"><img src="http://open.thumbshots.org/image.aspx?url=http://www.youtube.com/user/microsoftlearning" alt="Microsoft Learning&#039;s Channel" title="Microsoft Learning Training" class="alignleft" /></a> <a href="http://www.youtube.com/user/microsoftlearning" id="193" class="track_this_link"  title="Microsoft Learning Training" target="_blank">Microsoft Learning&#039;s Channel</a>
<br/>Microsoft Learning Training</p><br/>
<p style='display:table;width:100%;'><a href="http://ontwik.com/" id="169" class="track_this_link"  title="Lectures, Screencasts and conferences for real web developers &amp; designers" target="_blank"><img src="http://open.thumbshots.org/image.aspx?url=http://ontwik.com/" alt="Ontwik" title="Lectures, Screencasts and conferences for real web developers &amp; designers" class="alignleft" /></a> <a href="http://ontwik.com/" id="169" class="track_this_link"  title="Lectures, Screencasts and conferences for real web developers &amp; designers" target="_blank">Ontwik</a>
<br/>Lectures, Screencasts and conferences for real web developers &amp; designers</p><br/>
<p style='display:table;width:100%;'><a href="http://feeds2.feedburner.com/SpaghettiCodePodcasts" id="194" class="track_this_link"  title="Collection of video/screencasts by Jeff Brand. There are three main components to Spaghetti Code : ScreenCasts, Interviews and &quot;Almost Live&quot;" target="_blank"><img src="http://open.thumbshots.org/image.aspx?url=http://feeds2.feedburner.com/SpaghettiCodePodcasts" alt="Spaghetti Code Podcasts" title="Collection of video/screencasts by Jeff Brand. There are three main components to Spaghetti Code : ScreenCasts, Interviews and &quot;Almost Live&quot;" class="alignleft" /></a> <a href="http://feeds2.feedburner.com/SpaghettiCodePodcasts" id="194" class="track_this_link"  title="Collection of video/screencasts by Jeff Brand. There are three main components to Spaghetti Code : ScreenCasts, Interviews and &quot;Almost Live&quot;" target="_blank">Spaghetti Code Podcasts</a>
<br/>Collection of video/screencasts by Jeff Brand. There are three main components to Spaghetti Code : ScreenCasts, Interviews and &quot;Almost Live&quot;</p><br/>
<p style='display:table;width:100%;'><a href="http://tekpub.com/channels/free" id="190" class="track_this_link"  title="This is the .NET Open Source channel where we do what we can to give back to the community. Project leaders can create screencasts for their projects, give them to us to polish and render, and we stream them from our streaming servers. " target="_blank"><img src="http://open.thumbshots.org/image.aspx?url=http://tekpub.com/channels/free" alt="TekPub" title="This is the .NET Open Source channel where we do what we can to give back to the community. Project leaders can create screencasts for their projects, give them to us to polish and render, and we stream them from our streaming servers. " class="alignleft" /></a> <a href="http://tekpub.com/channels/free" id="190" class="track_this_link"  title="This is the .NET Open Source channel where we do what we can to give back to the community. Project leaders can create screencasts for their projects, give them to us to polish and render, and we stream them from our streaming servers. " target="_blank">TekPub</a>
<br/>This is the .NET Open Source channel where we do what we can to give back to the community. Project leaders can create screencasts for their projects, give them to us to polish and render, and we stream them from our streaming servers. </p><br/>
<p style='display:table;width:100%;'><a href="http://tv.telerik.com/" id="189" class="track_this_link"  title="Training videos, webinars, Tips &amp; Tricks" target="_blank"><img src="http://open.thumbshots.org/image.aspx?url=http://tv.telerik.com/" alt="Telerik TV" title="Training videos, webinars, Tips &amp; Tricks" class="alignleft" /></a> <a href="http://tv.telerik.com/" id="189" class="track_this_link"  title="Training videos, webinars, Tips &amp; Tricks" target="_blank">Telerik TV</a>
<br/>Training videos, webinars, Tips &amp; Tricks</p><br/>
	</table>
</div><script type='text/javascript'>
jQuery(document).ready(function()
{
jQuery('a.track_this_link').click(function() {
jQuery.post('http://www.sambeauvois.be/blog/wp-content/plugins/link-library/tracker.php', {id:this.id});
return true;
});
});
</script></div>

<!-- End of Link Library Output -->


]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2011/03/6-sources-of-videocasts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get the first day of the current week</title>
		<link>http://www.sambeauvois.be/blog/2011/02/get-the-first-day-of-the-current-week/</link>
		<comments>http://www.sambeauvois.be/blog/2011/02/get-the-first-day-of-the-current-week/#comments</comments>
		<pubDate>Thu, 24 Feb 2011 16:00:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Extension Methods]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=871</guid>
		<description><![CDATA[Here is a quick way to get the first day of the current week. If you are happy with sunday as the first day of the week, then you can simply do this : public static DateTime FirstDayOfWeek(this DateTime date) { return DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek); } But if you want that the first day of the week [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a quick way to get the first day of the current week.</p>
<p>If you are happy with sunday as the first day of the week, then you can simply do this :</p>
<pre class="brush: csharp; title: ;">

 public static DateTime FirstDayOfWeek(this DateTime date)
 {
            return DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek);
 }
</pre>
<p>But if you want that the first day of the week matches your culture (eg: the belgian week starts on monday), you have to take care of the culture&#8217;s DateTime format.</p>
<p>So the method will change a bit :</p>
<pre class="brush: csharp; title: ;">

public static DateTime FirstDayOfWeek(this DateTime date)
{
     return DateTime.Today.AddDays(-((int)DateTime.Today.DayOfWeek - (int)CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek));
}
</pre>
</pre>
<h5>Usage :</h5>
<pre class="brush: csharp; title: ;">

    DateTime FirstDayOfWeek = DateTime.Today.FirstDayOfWeek();
</pre>
<p>or</p>
<pre class="brush: csharp; title: ;">
 DateTime FirstDayOfWeek = DateTime.Now.FirstDayOfWeek();
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2011/02/get-the-first-day-of-the-current-week/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Phone 7 Numeric TextBox</title>
		<link>http://www.sambeauvois.be/blog/2011/01/windows-phone-7-numeric-textbox/</link>
		<comments>http://www.sambeauvois.be/blog/2011/01/windows-phone-7-numeric-textbox/#comments</comments>
		<pubDate>Tue, 11 Jan 2011 16:39:36 +0000</pubDate>
		<dc:creator>Sam Beauvois</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=827</guid>
		<description><![CDATA[There is no “built in” numeric textbox in the current Silverlight for Windows phone. Here a few solutions to realize one anyway : it remembers me the early years of the .NET framework or nothing was in the framework … All my solutions are based on the same principle : we handle the keydown event [...]]]></description>
			<content:encoded><![CDATA[<p>There is no “built in” numeric textbox in the current Silverlight for Windows phone.</p>
<blockquote><p>Here a few solutions to realize one anyway : it remembers me the early years of the .NET framework or nothing was in the framework …</p></blockquote>
<p>All my solutions are based on the same principle : we handle the keydown event of a textbox then we check the code of the pressed key.</p>
<p>If the code matches a number, we let it do, in the other case we stop the process.</p>
<h3>First solution :  A simple textbox</h3>
<p>In the xaml of the application, we add a textbox and we set it’s InputScrope property to “TelephoneNumber” to set the keyboard to a layout with numbers (we should also use the “Number” value for this property but the keys are smaller, this is not the best for a small device) so the input keyboard will look like this</p>
<p><img class="alignnone size-full wp-image-821" title="image.png" src="http://www.sambeauvois.be/blog/wp-content/uploads/2011/01/image.png" alt="" width="329" height="233" /></p>
<p>This is not enough, because we can use the special characters (*, #, ., / and the space bar).</p>
<p>So we add an handler for the keydown event</p>
<pre class="brush: xml; title: ;">

&lt;TextBox Name=&quot;SimpleTbx&quot; InputScope=&quot;TelephoneNumber&quot; KeyDown=&quot;SimpleTbx_KeyDown&quot;/&gt;
</pre>
<p>In the code behind, we will add our logic:</p>
<p>First, we specify an array of the allowed key codes :</p>
<pre class="brush: csharp; title: ;">

private readonly Key[] numeric = new Key[] {Key.Back, Key.NumPad0, Key.NumPad1, Key.NumPad2, Key.NumPad3, Key.NumPad4,
Key.NumPad5, Key.NumPad6, Key.NumPad7, Key.NumPad8, Key.NumPad9 };
</pre>
<p>(don’t forget the back button because we still want to use it ! It works also if I don’t put it in the array but I prefer to let it just in case)</p>
<p>In the keydown event handler we check the pressed key code:</p>
<pre class="brush: csharp; title: ;">

private void SimpleTbx_KeyDown(object sender, KeyEventArgs e)
{
// handles non numeric
if (Array.IndexOf(numeric, e.Key) == -1)
{
e.Handled = true;
}
}
</pre>
<p>If the array don’t contains the code we stop to process the key.</p>
<p>That’s it for the first solution.</p>
<h3>Second solution : create an user control</h3>
<p>If we don’t want to repeat the operations of the first solution on every textbox in the project we can use a user control.</p>
<p>So we add an user control to the project (right click on the project-&gt; Add –&gt; new item)</p>
<p><img class="alignnone size-medium wp-image-823" title="image.png" src="http://www.sambeauvois.be/blog/wp-content/uploads/2011/01/image1-480x320.png" alt="" width="480" height="320" /></p>
<p>In this user control we add a textbox and we repeat exactly the same operations than for the first solution.</p>
<pre class="brush: xml; title: ;">

&lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;{StaticResource PhoneChromeBrush}&quot; Height=&quot;Auto&quot; Width=&quot;Auto&quot;&gt;
&lt;TextBox Name=&quot;NumericTextBox&quot; KeyDown=&quot;NumericTextBox_KeyDown&quot; InputScope=&quot;TelephoneNumber&quot;/&gt;
&lt;/Grid&gt;
</pre>
<p>We still have a little additional work to do : add a property linked to the text of the textbox. So we can retrieve the result in our page.</p>
<pre class="brush: csharp; title: ;">
public string Text
{
  get
  {
    return NumericTextBox.Text;
  }
  set
  {
    NumericTextBox.Text = value;
  }
}
</pre>
<p>To use it in the mainpage, we need to reference the namespace of the usercontrol:</p>
<pre class="brush: xml; title: ;">

xmlns:my=&quot;clr-namespace:WPNumericTextBox.Controls&quot;
</pre>
<p>then we can use it this way :</p>
<pre class="brush: xml; title: ;">

&lt;my:NumericTextBoxUserControl x:Name=&quot;NumericTbxUC&quot; /&gt;
</pre>
<p>End of the second solution.</p>
<h3>Third solution : inherit the textbox to create a numeric textbox</h3>
<p>We can inherit the textbox and made it responsive to numbers only:</p>
<ul>
<li> Add a class to your project</li>
<li> Inherit from textbox</li>
<li> Set the InputScope to InputScopeNameValue.TelephoneLocalNumber</li>
<li> Override the keydown event</li>
<li> That&#8217;s it .</li>
</ul>
<p>Here is the complete code :</p>
<pre class="brush: csharp; title: ;">

using System;
using System.Windows.Controls;
using System.Windows.Input;

namespace WPNumericTextBox.Controls
{
public class NumericTextBox : TextBox
{
private readonly Key[] numeric = new Key[] {Key.Back, Key.NumPad0, Key.NumPad1, Key.NumPad2, Key.NumPad3, Key.NumPad4,
Key.NumPad5, Key.NumPad6, Key.NumPad7, Key.NumPad8, Key.NumPad9 };

public NumericTextBox()
{
this.InputScope = new InputScope();
this.InputScope.Names.Add(new InputScopeName() { NameValue = InputScopeNameValue.TelephoneLocalNumber });
}

protected override void OnKeyDown(KeyEventArgs e)
{
if(Array.IndexOf(numeric,e.Key) == -1)
{
e.Handled = true;
}
base.OnKeyDown(e); // important, if not called the back button is not handled
}
}

}
</pre>
<p>do not forgot to call the base.OnKeyDown method, otherwise your back button will be inefficient.</p>
<p>To use it in the mainpage : reference the namespace of the usercontrol:</p>
<pre class="brush: xml; title: ;">

xmlns:my=&quot;clr-namespace:WPNumericTextBox.Controls&quot;
</pre>
<p>then use the control :</p>
<pre class="brush: xml; title: ;">

&lt;my:NumericTextBox x:Name=&quot;NumTbx&quot;/&gt;
</pre>
<h3>Fourth Solution : create a numeric textbox in a control library</h3>
<p>This solution is an improvement of the third : we add our control in a windows phone library so we can reuse it for another project !</p>
<p>To use it in the mainpage : reference the namespace of the usercontrol:</p>
<pre class="brush: xml; title: ;">

xmlns:my1=&quot;clr-namespace:WPControls;assembly=WPControls&quot;
</pre>
<p>then use the control :</p>
<pre class="brush: xml; title: ;">

&lt;my1:NumericTextBox Name=&quot;NumericTextBox&quot;/&gt;
</pre>
<p>I created a demo app :</p>
<p><img class="alignnone size-full wp-image-825" title="image.png" src="http://www.sambeauvois.be/blog/wp-content/uploads/2011/01/image2.png" alt="" width="325" height="542" /></p>
<p>The full demo source is available for download :</p>
<p><a href="http://www.sambeauvois.be/Demos/WP7/NumericTextBox/WPNumericTextBox.zip" target="_blank">http://www.sambeauvois.be/Demos/WP7/NumericTextBox/WPNumericTextBox.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2011/01/windows-phone-7-numeric-textbox/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Do not overuse the custom exceptions, use the ones provided by the framework</title>
		<link>http://www.sambeauvois.be/blog/2011/01/do-not-overuse-the-custom-exceptions-use-the-ones-provided-by-the-framework/</link>
		<comments>http://www.sambeauvois.be/blog/2011/01/do-not-overuse-the-custom-exceptions-use-the-ones-provided-by-the-framework/#comments</comments>
		<pubDate>Thu, 06 Jan 2011 07:42:45 +0000</pubDate>
		<dc:creator>Sam Beauvois</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=525</guid>
		<description><![CDATA[As a .NET developper you may be tempted to create a custom exception class for each of your exceptions you throw. But plenty of them are already present in the .NET framework. If your need matches one of these Exceptions, use it instead of reinvent the wheel. I generated a list of the available exceptions, [...]]]></description>
			<content:encoded><![CDATA[<p>As a .NET developper you may be tempted to create a custom exception class for each of your exceptions you throw.</p>
<p>But plenty of them are already present in the .NET framework.</p>
<p>If your need matches one of these Exceptions, use it instead of reinvent the wheel.</p>
<p>I generated a list of the available exceptions, you can consult it <a href="http://www.sambeauvois.be/Docs/Generated/FrameworkExceptions.html" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2011/01/do-not-overuse-the-custom-exceptions-use-the-ones-provided-by-the-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

