<?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>Ken Kopczyk</title>
	<atom:link href="http://kenkopczyk.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://kenkopczyk.com</link>
	<description>Hurdles in .NET WinForms Development</description>
	<lastBuildDate>Sat, 13 Mar 2010 03:50:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='kenkopczyk.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/60348bde5d188332d5268692846b25c7?s=96&#038;d=http://s2.wp.com/i/buttonw-com.png</url>
		<title>Ken Kopczyk</title>
		<link>http://kenkopczyk.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://kenkopczyk.com/osd.xml" title="Ken Kopczyk" />
	<atom:link rel='hub' href='http://kenkopczyk.com/?pushpress=hub'/>
		<item>
		<title>Debugging Javascript in Visual Studio 2005</title>
		<link>http://kenkopczyk.com/2010/03/12/debugging-javascript-in-visual-studio-2005/</link>
		<comments>http://kenkopczyk.com/2010/03/12/debugging-javascript-in-visual-studio-2005/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 03:50:05 +0000</pubDate>
		<dc:creator>Ken</dc:creator>
				<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://kenkopczyk.com/?p=296</guid>
		<description><![CDATA[A feature of Visual Studio that is not enabled by default is the ability to debug javascript. To enable this feature, you need to uncheck &#8220;Disable script debugging (Internet Explorer)&#8221; in the &#8220;Advanced&#8221; tab of the &#8220;Internet Options&#8221; dialog in IE: Debugging is now enabled: Doing this will also give you access to Visual Studio&#8217;s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kenkopczyk.com&blog=6344943&post=296&subd=kkopczyk&ref=&feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A feature of Visual Studio that is not enabled by default is the ability to debug javascript.</p>
<p>To enable this feature, you need to uncheck &#8220;Disable script debugging (Internet Explorer)&#8221; in the &#8220;Advanced&#8221; tab of the &#8220;Internet Options&#8221; dialog in IE:</p>
<div style="text-align:center;">
<img src="http://kkopczyk.files.wordpress.com/2010/03/ieadvanced.png" />
</div>
<p>Debugging is now enabled:</p>
<div style="text-align:center;">
<img src="http://kkopczyk.files.wordpress.com/2010/03/jsbreak.png" />
</div>
<p>Doing this will also give you access to Visual Studio&#8217;s <a href="http://msdn.microsoft.com/en-us/library/afys1kyy(VS.80).aspx">Script Explorer</a> which allows you to view and trace through the stack of scripts that are running within your ASP.NET application behind the scenes:</p>
<div style="text-align:center;">
<img src="http://kkopczyk.files.wordpress.com/2010/03/scriptexplorer.png" />
</div>
<p><b>Warning:</b>  Client-side script debugging does slow down the application quite a bit during development.  It would be wise to only have this feature enabled when you need to debug javascript.</p>
<p><b>Note:</b>  This information assumes that you are using IE as your default development browser.  If you would like to change default browsers, select your website project in the Solution Explorer, and then select &#8220;Browse With&#8230;&#8221; from the File menu:</p>
<div style="text-align:center;">
<img src="http://kkopczyk.files.wordpress.com/2010/03/browsers.png" />
</div>
<p>Alternatively, while the application is running in Debug mode, you can attach the process to another browser and run the two browsers in tandem.  Select &#8220;Attach to Process&#8230;&#8221; from the Debug menu to accomplish this:</p>
<div style="text-align:center;">
<img src="http://kkopczyk.files.wordpress.com/2010/03/attachscript.png" />
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kkopczyk.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kkopczyk.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kkopczyk.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kkopczyk.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kkopczyk.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kkopczyk.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kkopczyk.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kkopczyk.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kkopczyk.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kkopczyk.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kkopczyk.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kkopczyk.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kkopczyk.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kkopczyk.wordpress.com/296/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kenkopczyk.com&blog=6344943&post=296&subd=kkopczyk&ref=&feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kenkopczyk.com/2010/03/12/debugging-javascript-in-visual-studio-2005/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/df43ecaeb5e162064d67f882431983c6?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Ken</media:title>
		</media:content>

		<media:content url="http://kkopczyk.files.wordpress.com/2010/03/ieadvanced.png" medium="image" />

		<media:content url="http://kkopczyk.files.wordpress.com/2010/03/jsbreak.png" medium="image" />

		<media:content url="http://kkopczyk.files.wordpress.com/2010/03/scriptexplorer.png" medium="image" />

		<media:content url="http://kkopczyk.files.wordpress.com/2010/03/browsers.png" medium="image" />

		<media:content url="http://kkopczyk.files.wordpress.com/2010/03/attachscript.png" medium="image" />
	</item>
		<item>
		<title>Persisting User Settings Using Serialization</title>
		<link>http://kenkopczyk.com/2010/01/31/persisting-user-settings-using-serialization/</link>
		<comments>http://kenkopczyk.com/2010/01/31/persisting-user-settings-using-serialization/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 23:17:02 +0000</pubDate>
		<dc:creator>Ken</dc:creator>
				<category><![CDATA[.NET SDK]]></category>
		<category><![CDATA[Serialization]]></category>
		<category><![CDATA[XSD]]></category>

		<guid isPermaLink="false">http://kkopczyk.wordpress.com/?p=6</guid>
		<description><![CDATA[Recently, I was faced with the task of implementing custom user settings that were to be saved between sessions. My solution was to save these settings to a file during application tear down and to load the file as part of the application&#8217;s startup. To accomplish this, I used the following steps: Create an XML [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kenkopczyk.com&blog=6344943&post=6&subd=kkopczyk&ref=&feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently, I was faced with the task of implementing custom user settings that were to be saved between sessions.  My solution was to save these settings to a file during application tear down and to load the file as part of the application&#8217;s startup.  To accomplish this, I used the following steps:</p>
<ol>
<li>Create an XML schema definition file (xsd) to define the data being stored.</li>
<li>Create a Serializable class based on the xsd so the data may be instantiated/accessed in the code.</li>
<li>Use serialization and deserialization to load and unload the user settings.</li>
</ol>
<p><strong>Using xsd.exe to generate a serializable class.</strong><br />
The first step I took was to create an <a href="http://msdn.microsoft.com/en-us/magazine/cc302086.aspx">XML schema definition file</a> to represent my user settings data.  Once the schema was finished, I used the <a href="http://msdn.microsoft.com/en-us/library/x6c1kb0s(VS.80).aspx">XML Schema Definition Tool (xsd.exe)</a> to generate a serializable class from the schema.  This executable is part of the .NET SDK and is a real time saver.  Use the following command line parameters to generate a serializable class based on an xsd file:</p>
<pre class="brush: plain;">
xsd.exe -c -l:c# -n:[namespace for the generated class] [XML Schema Definition File]
</pre>
<p>Example:</p>
<pre class="brush: plain;">
xsd.exe -c -l:c# -n:MyProgram.Utilities MyUserSettings.xsd
</pre>
<p>This example will create a serializable class called MyUserSettings.cs.</p>
<p><strong>Serialization and Deserialization</strong><br />
Simply stated, serialization is the process of converting an object instance into a stream of bytes, text, XML or other formats so that it can be persisted into storage medium or transfered across a network.  Deserialization is the opposite process which converts the persisted data back into an object instance.  The following are sample methods for each process:</p>
<pre class="brush: csharp;">
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace MyProgram.Utilities
{
    public static class Serialization
    {
        public enum SerializationMethod { Binary, XML };

        public static void Serialize(string sFilePath, Type type, object objectToSerialize, SerializationMethod serializationMethod)
        {
            if (!File.Exists(sFilePath))
            {
                return;
            }

            Stream writeStream = null;
            XmlTextWriter xtw = null;
            try
            {
                writeStream = File.Open(sFilePath, FileMode.Truncate);
                if (serializationMethod == SerializationMethod.XML)
                {
                    XmlSerializer xs = new XmlSerializer(type);
                    xtw = new XmlTextWriter(writeStream, null);
                    xs.Serialize(xtw, objectToSerialize);
                }
                else if (serializationMethod == SerializationMethod.Binary)
                {
                    new BinaryFormatter().Serialize(writeStream, objectToSerialize);
                }
            }
            finally
            {
                if (xtw != null)
                {
                    xtw.Close();
                }
                if (writeStream != null)
                {
                    writeStream.Close();
                    writeStream.Dispose();
                }
            }
        }

        public static object Deserialize(string sFilePath, Type type, SerializationMethod serializationMethod)
        {
            if (!File.Exists(sFilePath))
            {
                return Activator.CreateInstance(type);
            }

            Stream stream = null;
            object deserializedObject = null;
            try
            {
                stream = File.OpenRead(sFilePath);
                if (serializationMethod == SerializationMethod.XML)
                {
                    XmlSerializer xmlSerializer = new XmlSerializer(type);
                    deserializedObject = xmlSerializer.Deserialize(stream);
                }
                else if (serializationMethod == SerializationMethod.Binary)
                {
                    deserializedObject = new BinaryFormatter().Deserialize(stream);
                }
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                    stream.Dispose();
                }
            }
            return deserializedObject;
        }
    }
}
</pre>
<p>Note that these methods support both XML (human readable) and binary (gibberish) de/serialization.  This comes in handy if you want to prevent the settings files from being tampered with in a production environment, but you&#8217;d prefer them easier to work with during development.  Using preprocessor directives, you can do something like the following to make the files human readable at development time, but garbled when they are released into the wild:</p>
<pre class="brush: csharp;">
MyUserSettings userSettings = GetMySettings();
#if DEBUG
Serialization.SerializationMethod serializationMethod = Serialization.SerializationMethod.XML;
#else
Serialization.SerializationMethod serializationMethod = Serialization.SerializationMethod.Binary;
#endif
Serialization.Serialize(sFullSettingsFileName, typeof(MyUserSettings), userSettings, serializationMethod);
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kkopczyk.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kkopczyk.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kkopczyk.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kkopczyk.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kkopczyk.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kkopczyk.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kkopczyk.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kkopczyk.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kkopczyk.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kkopczyk.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kkopczyk.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kkopczyk.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kkopczyk.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kkopczyk.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kenkopczyk.com&blog=6344943&post=6&subd=kkopczyk&ref=&feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kenkopczyk.com/2010/01/31/persisting-user-settings-using-serialization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/df43ecaeb5e162064d67f882431983c6?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Ken</media:title>
		</media:content>
	</item>
		<item>
		<title>Disabling and Enabling the Close Button in .NET 2.0 WinForms</title>
		<link>http://kenkopczyk.com/2010/01/23/disabling-and-enabling-the-close-button-in-net-2-0-winforms/</link>
		<comments>http://kenkopczyk.com/2010/01/23/disabling-and-enabling-the-close-button-in-net-2-0-winforms/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 20:01:35 +0000</pubDate>
		<dc:creator>Ken</dc:creator>
				<category><![CDATA[WinForms Tips]]></category>
		<category><![CDATA[WinForms]]></category>
		<category><![CDATA[Close Button]]></category>

		<guid isPermaLink="false">http://kenkopczyk.com/?p=234</guid>
		<description><![CDATA[In .NET 2.0 WinForms, the user is given the following control over the minimize/maximize/close buttons (otherwise known as the ControlBox): Disable/enable the Minimize button via the Form.MinimizeBox property Disable/enable the Maximize button via the Form.MaximizeBox property Show/hide the entire ControlBox via the Form.ControlBox property However, you may want to allow maximizing and minimizing, but remove [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kenkopczyk.com&blog=6344943&post=234&subd=kkopczyk&ref=&feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In .NET 2.0 WinForms, the user is given the following control over the minimize/maximize/close buttons (otherwise known as the ControlBox):</p>
<ul>
<li>Disable/enable the Minimize button via the Form.MinimizeBox property</li>
<li>Disable/enable the Maximize button via the Form.MaximizeBox property</li>
<li>Show/hide the entire ControlBox via the Form.ControlBox property</li>
</ul>
<p>However, you may want to allow maximizing and minimizing, but remove the user&#8217;s ability to close the application using the close button for any number of reasons.  For example:</p>
<ul>
<li>You want to run some process that cannot be cancelled midway through.</li>
<li>You want to ensure a user completes some number of tasks before being able to exit.</li>
</ul>
<p>Unfortunately, this functionality is not supported by default.  One must leverage the unmanaged code of the Windows API to achieve this behavior:</p>
<pre class="brush: csharp;">
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

public class SuperForm : Form
{
    private const int MF_BYPOSITION = 0x400;

    protected void DisableCloseButton()
    {
        IntPtr hMenu = GetSystemMenu(this.Handle, false);
        int menuItemCount = GetMenuItemCount(hMenu);
        RemoveMenu(hMenu, menuItemCount - 1, MF_BYPOSITION);
        DrawMenuBar((int)this.Handle);
    }
    protected void EnableCloseButton()
    {
        GetSystemMenu(this.Handle, true);
        DrawMenuBar((int)this.Handle);
    }

    // Win32 API declarations
    [DllImport(&quot;User32&quot;)]
    private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
    [DllImport(&quot;User32&quot;)]
    private static extern int GetMenuItemCount(IntPtr hWnd);
    [DllImport(&quot;User32&quot;)]
    private static extern int RemoveMenu(IntPtr hMenu, int nPosition, int wFlags);
    [DllImport(&quot;User32&quot;)]
    private static extern IntPtr DrawMenuBar(int hwnd);
}
</pre>
<p>Notice that I incorporated this functionality into a base class that all your forms can inherit from to gain this ability.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kkopczyk.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kkopczyk.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kkopczyk.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kkopczyk.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kkopczyk.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kkopczyk.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kkopczyk.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kkopczyk.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kkopczyk.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kkopczyk.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kkopczyk.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kkopczyk.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kkopczyk.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kkopczyk.wordpress.com/234/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kenkopczyk.com&blog=6344943&post=234&subd=kkopczyk&ref=&feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kenkopczyk.com/2010/01/23/disabling-and-enabling-the-close-button-in-net-2-0-winforms/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/df43ecaeb5e162064d67f882431983c6?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Ken</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating COM Interop Assemblies with .NET 2.0</title>
		<link>http://kenkopczyk.com/2009/08/18/net-com-and-interop-assemblies/</link>
		<comments>http://kenkopczyk.com/2009/08/18/net-com-and-interop-assemblies/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 03:14:11 +0000</pubDate>
		<dc:creator>Ken</dc:creator>
				<category><![CDATA[.NET SDK]]></category>
		<category><![CDATA[COM Interop]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[Interop]]></category>
		<category><![CDATA[tlbimp]]></category>
		<category><![CDATA[Strong Naming]]></category>

		<guid isPermaLink="false">http://kenkopczyk.com/?p=189</guid>
		<description><![CDATA[If you work with .NET long enough, sooner or later you&#8217;ll probably need to leverage older Win32 COM components. To allow the CLR managed code of .NET to communicate with the unmanaged code of COM, a &#8220;middleman&#8221; in the form of an interop assembly must be created. This can be done via Visual Studio or [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kenkopczyk.com&blog=6344943&post=189&subd=kkopczyk&ref=&feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you work with .NET long enough, sooner or later you&#8217;ll probably need to leverage older Win32 COM components.  To allow the CLR managed code of .NET to communicate with the unmanaged code of COM, a &#8220;middleman&#8221; in the form of an interop assembly must be created.  This can be done via Visual Studio or the Type Library Importer.</p>
<p><b>Creating an interop assembly with Visual Studio</b><br />
Enter the &#8220;Add reference&#8221; dialog of your project, browse for your registered COM server and select it.  Now take a look at the properties of the newly created reference.  It is actually pointing to a new assembly called Interop.COMServerName.dll:  If your COM server is foo.dll, the resulting assembly is called Interop.foo.dll.  You will find this assembly in your bin directory after you build.</p>
<p>If your project uses an .snk or .pfx for strong naming, the interop assembly will also be strong named using that file.</p>
<p>A major limitation of this method I found was the fact that you can&#8217;t change the version number of the interop assembly.  It is <i>always</i> 1.0.0.0.  Bummer.</p>
<p><b>Creating an interop assembly with Type Library Importer</b><br />
If you need more control, then you should use the <a href="http://msdn.microsoft.com/en-us/library/tt0cf3sx(VS.80).aspx">Type Library Importer (tlbimp)</a>.  This application is included with the .NET SDK.</p>
<p>Running the following command will create an interop assembly with a version number of your choosing:<br />
Using our foo.dll example:</p>
<pre class="brush: bash;">
tlbimp foo.dll /out:Interop.foo.dll /asmversion:2.0.0.0
</pre>
<p>If you need the interop assembly strongly named, you can do that also.  If you are using an .snk, use the following:</p>
<pre class="brush: bash;">
tlbimp foo.dll /out:Interop.foo.dll /asmversion:2.0.0.0 /keyfile:MyKey.snk
</pre>
<p>If you are using a .pfx for strong naming, it&#8217;s a bit trickier.  You will also need to leverage the <a href="http://msdn.microsoft.com/en-us/library/k5b5tt23(VS.80).aspx">Strong Name Tool (sn)</a> to create a keycontainer:</p>
<pre class="brush: bash;">
echo Prompts you for .pfx password
sn -i MyKey.pfx KeyContainerName

tlbimp foo.dll /out:Interop.foo.dll /asmversion:2.0.0.0 /keycontainer:KeyContainerName

echo Housecleaning.  Removes the key container from memory.
sn -d KeyContainerName
</pre>
<p>Now add it as a reference and you&#8217;re good to go!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kkopczyk.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kkopczyk.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kkopczyk.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kkopczyk.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kkopczyk.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kkopczyk.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kkopczyk.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kkopczyk.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kkopczyk.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kkopczyk.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kkopczyk.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kkopczyk.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kkopczyk.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kkopczyk.wordpress.com/189/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kenkopczyk.com&blog=6344943&post=189&subd=kkopczyk&ref=&feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kenkopczyk.com/2009/08/18/net-com-and-interop-assemblies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/df43ecaeb5e162064d67f882431983c6?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Ken</media:title>
		</media:content>
	</item>
		<item>
		<title>Referencing GAC Assemblies With Visual Studio 2005</title>
		<link>http://kenkopczyk.com/2009/08/15/referencing-gac-assemblies-with-visual-studio-2005/</link>
		<comments>http://kenkopczyk.com/2009/08/15/referencing-gac-assemblies-with-visual-studio-2005/#comments</comments>
		<pubDate>Sun, 16 Aug 2009 02:56:26 +0000</pubDate>
		<dc:creator>Ken</dc:creator>
				<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[GAC]]></category>

		<guid isPermaLink="false">http://kenkopczyk.com/?p=185</guid>
		<description><![CDATA[In Visual Studio 2005, adding an assembly reference is straight-forward and trivial, that is, unless the assembly you are trying to reference only exists in the GAC. There are a number of tabs in the Add Reference dialog, but they browse assemblies that are all located in standard directories. Global Assembly Cache The GAC is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kenkopczyk.com&blog=6344943&post=185&subd=kkopczyk&ref=&feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In Visual Studio 2005, adding an assembly reference is straight-forward and trivial, that is, unless the assembly you are trying to reference only exists in the GAC.  There are a number of tabs in the Add Reference dialog, but they browse assemblies that are all located in standard directories.</p>
<p><b>Global Assembly Cache</b><br />
The <a href="http://msdn.microsoft.com/en-us/library/yf1d93sz(VS.80).aspx">GAC</a> is special because it allows a pc to store multiple versions of the same .NET assembly.  This is made possible by strong naming.  More importantly, it provides a centralized location for .NET assemblies that need to be shared across multiple applications.  </p>
<p>When viewing the GAC via the Windows shell, you go here:  C:\Windows\Assembly.  However, the Explorer-like UI actually represents an aggregate of files and folders.  Windows is just trying to make it look nice and user friendly for us.</p>
<p><b>Tricking Visual Studio</b><br />
To trick Visual Studio into referencing a GAC assembly, you can do the following:<br />
1.)  Reference a copy of the assembly that is located outside of the GAC via the Add Reference dialog.  You can throw a copy on your Desktop and then reference it from there.  It doesn&#8217;t matter what the file&#8217;s location is.<br />
2.)  Install the assembly into the GAC.  There are a number of ways to do this.  The easiest way is to use the &#8220;Microsoft .NET Framework 2.0 Configuration&#8221; app.  You can find it by going to Control Panel &#8211;&gt;  Administrative Tools.  Once in the app, click &#8220;Manage the Assembly Cache&#8221; and then &#8220;Add an Assembly to the Assembly Cache.&#8221;<br />
3.)  Delete the assembly file that you referenced in step 1.  Go into Visual Studio and refresh the project.  The path of the reference should have automatically changed over to its GAC location (C:\Windows\assembly\&#8230;).<br />
4.)  You may want to set the reference&#8217;s &#8220;Copy Local&#8221; property to False so that the build does not produce a copy of the GAC assembly in the bin folder (to avoid confusion).  In doing so, you can be confident that your app is in fact hitting the GAC!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kkopczyk.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kkopczyk.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kkopczyk.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kkopczyk.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kkopczyk.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kkopczyk.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kkopczyk.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kkopczyk.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kkopczyk.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kkopczyk.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kkopczyk.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kkopczyk.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kkopczyk.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kkopczyk.wordpress.com/185/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kenkopczyk.com&blog=6344943&post=185&subd=kkopczyk&ref=&feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kenkopczyk.com/2009/08/15/referencing-gac-assemblies-with-visual-studio-2005/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/df43ecaeb5e162064d67f882431983c6?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Ken</media:title>
		</media:content>
	</item>
		<item>
		<title>Impressive (and Free) WinForm Controls!</title>
		<link>http://kenkopczyk.com/2009/02/25/impressive-and-free-winform-controls/</link>
		<comments>http://kenkopczyk.com/2009/02/25/impressive-and-free-winform-controls/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 00:21:42 +0000</pubDate>
		<dc:creator>Ken</dc:creator>
				<category><![CDATA[WinForms Components]]></category>

		<guid isPermaLink="false">http://kkopczyk.wordpress.com/?p=170</guid>
		<description><![CDATA[Recently, I was searching for a third party WinForm component solution in an attempt to make my application look enterprise worthy.  Doing some googling yields all the heavy hitters:  Telerik, ComponentOne, etc.  These are very nice, but come at a hefty price (about $1000 per seat).  Digging deeper, I stumbled upon the Krypton Toolkit from [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kenkopczyk.com&blog=6344943&post=170&subd=kkopczyk&ref=&feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently, I was searching for a third party WinForm component solution in an attempt to make my application look enterprise worthy.  Doing some googling yields all the heavy hitters:  Telerik, ComponentOne, etc.  These are very nice, but come at a hefty price (about $1000 per seat).  Digging deeper, I stumbled upon the <a href="http://www.componentfactory.com/free-windows-forms-controls.php">Krypton Toolkit</a> from <a href="http://www.componentfactory.com/">ComponentFactory</a>.  </p>
<p>For a freebie suite of controls, I was impressed.  The toolkit includes all your basic controls (Label, ComboBox, etc), 38 in all, and are very customizable.  You can also apply out of the box themes, such as Office2007, also free.  It integrates seemlessly into Visual Studio (I was using VS2005) and includes a very nice demo app that shows off what all the controls can do.</p>
<p>Also in the Krypton family are the <a href="http://www.componentfactory.com/windows-forms-products.php">Ribbon, tab control, and workspace control</a>.  These are upgrades that you have to pay for, but still cheap when you consider all the very expensive alternatives out there.</p>
<p>Next time you are building an little app from the ground up, consider using these controls.  You should be able to make your app look a ton better at no extra cost.</p>
<div><a title="Bookmark and Share" href="http://www.addthis.com/bookmark.php?pub=kkopczyk&amp;url=http://kkopczyk.wordpress.com/2009/02/25/impressive-and-free-winform-controls/" target="_blank"><img style="border:0;padding:0;" src="http://s7.addthis.com/static/btn/lg-share-en.gif" alt="Bookmark and Share" width="125" height="16" /></a></div>
<p><!-- AddThis Button END --></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kkopczyk.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kkopczyk.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kkopczyk.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kkopczyk.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kkopczyk.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kkopczyk.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kkopczyk.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kkopczyk.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kkopczyk.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kkopczyk.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kkopczyk.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kkopczyk.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kkopczyk.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kkopczyk.wordpress.com/170/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kenkopczyk.com&blog=6344943&post=170&subd=kkopczyk&ref=&feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kenkopczyk.com/2009/02/25/impressive-and-free-winform-controls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/df43ecaeb5e162064d67f882431983c6?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Ken</media:title>
		</media:content>

		<media:content url="http://s7.addthis.com/static/btn/lg-share-en.gif" medium="image">
			<media:title type="html">Bookmark and Share</media:title>
		</media:content>
	</item>
		<item>
		<title>My New Favorite Regular Expression Tester</title>
		<link>http://kenkopczyk.com/2009/02/03/my-new-favorite-regular-expression-tester/</link>
		<comments>http://kenkopczyk.com/2009/02/03/my-new-favorite-regular-expression-tester/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 03:53:58 +0000</pubDate>
		<dc:creator>Ken</dc:creator>
				<category><![CDATA[Regular Expressions]]></category>

		<guid isPermaLink="false">http://kkopczyk.wordpress.com/?p=164</guid>
		<description><![CDATA[Awesomeness &#8212;&#62; http://www.gskinner.com/RegExr/ Use it. &#8216;Nuf said.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kenkopczyk.com&blog=6344943&post=164&subd=kkopczyk&ref=&feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Awesomeness &#8212;&gt;  <a href="http://www.gskinner.com/RegExr/">http://www.gskinner.com/RegExr/</a></p>
<p>Use it.  &#8216;Nuf said.</p>
<div><a title="Bookmark and Share" href="http://www.addthis.com/bookmark.php?pub=kkopczyk&amp;url=http://kkopczyk.wordpress.com/2009/02/03/my-new-favorite-regular-expression-tester/" target="_blank"><img style="border:0;padding:0;" src="http://s7.addthis.com/static/btn/lg-share-en.gif" alt="Bookmark and Share" width="125" height="16" /></a></div>
<p><!-- AddThis Button END --></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kkopczyk.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kkopczyk.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kkopczyk.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kkopczyk.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kkopczyk.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kkopczyk.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kkopczyk.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kkopczyk.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kkopczyk.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kkopczyk.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kkopczyk.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kkopczyk.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kkopczyk.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kkopczyk.wordpress.com/164/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kenkopczyk.com&blog=6344943&post=164&subd=kkopczyk&ref=&feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kenkopczyk.com/2009/02/03/my-new-favorite-regular-expression-tester/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/df43ecaeb5e162064d67f882431983c6?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Ken</media:title>
		</media:content>

		<media:content url="http://s7.addthis.com/static/btn/lg-share-en.gif" medium="image">
			<media:title type="html">Bookmark and Share</media:title>
		</media:content>
	</item>
		<item>
		<title>Fun With the &#8220;ref&#8221; Keyword</title>
		<link>http://kenkopczyk.com/2009/02/03/fun-with-the-ref-keyword/</link>
		<comments>http://kenkopczyk.com/2009/02/03/fun-with-the-ref-keyword/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 02:28:05 +0000</pubDate>
		<dc:creator>Ken</dc:creator>
				<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://kkopczyk.wordpress.com/?p=147</guid>
		<description><![CDATA[By default, parameters are passed by value in C#.  Passing by reference requires the &#8220;ref&#8221; or &#8220;out&#8221; keywords to precede the parameter in both the method declaration and the call to the method.  Using &#8220;ref&#8221; or &#8220;out&#8221; is fairly straight forward&#8230;..or so I thought. I recently came across two cases where parameters are valid if [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kenkopczyk.com&blog=6344943&post=147&subd=kkopczyk&ref=&feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>By default, parameters are passed by value in C#.  Passing by reference requires the &#8220;ref&#8221; or &#8220;out&#8221; keywords to precede the parameter in both the method declaration and the call to the method.  Using &#8220;ref&#8221; or &#8220;out&#8221; is fairly straight forward&#8230;..or so I thought.</p>
<p>I recently came across two cases where parameters are valid if passing by value, but result in compilation errors after adding &#8220;ref&#8221;.  Consider the following member and method:</p>
<pre class="brush: csharp;">
// SuperDataTable inherits from DataTable
// Indexing a SuperDataTable yields a SuperDataRow
// which inherits from DataRow.
private SuperDataTable mySuperDataTable = new SuperDataTable();

public void DoSomethingSuper(ref DataRow myDataRow)
{
	return;
}
</pre>
<p>Now examine the following three scenarios:</p>
<pre class="brush: csharp;">
// #1 You receive a compiler error &quot;A property or indexer
// may not be passed as an out or ref parameter&quot;
DoSomethingSuper(ref mySuperDataTable[0]);

// #2 You receive a compiler error &quot;Cannot convert from
// 'ref SuperDataRow' to 'ref DataRow'
SuperDataRow mySuperDataRow = mySuperDataTable[0];
DoSomethingSuper(ref mySuperDataRow);

// #3 Only does it work in the following manner, when you
// explicitly &quot;upcast&quot; the row to the exact type in the
// signature of the method
DataRow myDataRow = mySuperDataTable[0];
DoSomethingSuper(ref myDataRow);
</pre>
<p>Try it again, this time passing by value.  No compiler errors!  I probably am just lacking an intimate understanding of &#8220;ref&#8221;, but this came out of left field for me and I haven&#8217;t seen it documented online.  <b>Can anybody fill me in as to why scenarios #1 and #2 don&#8217;t work?</b></p>
<div><a title="Bookmark and Share" href="http://www.addthis.com/bookmark.php?pub=kkopczyk&amp;url=http://kkopczyk.wordpress.com/2009/02/03/fun-with-the-ref-keyword/" target="_blank"><img style="border:0;padding:0;" src="http://s7.addthis.com/static/btn/lg-share-en.gif" alt="Bookmark and Share" width="125" height="16" /></a></div>
<p><!-- AddThis Button END --></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kkopczyk.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kkopczyk.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kkopczyk.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kkopczyk.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kkopczyk.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kkopczyk.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kkopczyk.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kkopczyk.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kkopczyk.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kkopczyk.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kkopczyk.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kkopczyk.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kkopczyk.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kkopczyk.wordpress.com/147/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kenkopczyk.com&blog=6344943&post=147&subd=kkopczyk&ref=&feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kenkopczyk.com/2009/02/03/fun-with-the-ref-keyword/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/df43ecaeb5e162064d67f882431983c6?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Ken</media:title>
		</media:content>

		<media:content url="http://s7.addthis.com/static/btn/lg-share-en.gif" medium="image">
			<media:title type="html">Bookmark and Share</media:title>
		</media:content>
	</item>
		<item>
		<title>Displaying Source Code in a WordPress Post</title>
		<link>http://kenkopczyk.com/2009/02/01/displaying-source-code-in-a-wordpress-post/</link>
		<comments>http://kenkopczyk.com/2009/02/01/displaying-source-code-in-a-wordpress-post/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 04:26:18 +0000</pubDate>
		<dc:creator>Ken</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[pastebin]]></category>

		<guid isPermaLink="false">http://kkopczyk.wordpress.com/?p=70</guid>
		<description><![CDATA[While setting up this blog, I came upon my first challenge:  How can you display source code in a WordPress post? There are many solutions to this problem which include various WordPress.org plug-ins.  The problem with the plug-ins is that they don&#8217;t work with freebee WordPress.com blogs.  The simplest solution that I found for WordPress.com [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kenkopczyk.com&blog=6344943&post=70&subd=kkopczyk&ref=&feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>While setting up this blog, I came upon my first challenge:  How can you display source code in a WordPress post?</p>
<p>There are many solutions to this problem which include various <a href="http://www.wordpress.org">WordPress.org</a> plug-ins.  The problem with the plug-ins is that they don&#8217;t work with freebee <a href="http://www.wordpress.com">WordPress.com</a> blogs.  The <a href="http://support.wordpress.com/code/#posting-source-code">simplest solution</a> that I found for <a href="http://www.wordpress.com">WordPress.com</a> blogs was to simply wrap the code you want to post in <a href="http://support.wordpress.com/code/#posting-source-code">&#8220;sourcecode&#8221; tags</a> and let javascript take care of the rest.  Implementing this is easy because you don&#8217;t have to worry about a big blob of HTML.  All that is required is the code you want to paste and the javascript tags.  Example:</p>
<pre class="brush: csharp;">
static void Main(string[] args)
{
      Console.Out.WriteLine(&quot;Hello World!&quot;);
      return;
}
</pre>
<p>Being the perfectionist that I am, I wanted to see if I could get the code to look closer to the default fonts and colors used in Visual Studio.  Thanks to <a href="http://robburke.net/2008/08/04/pasting-code-into-wordpress-easily/">this posting</a>, I discovered <a href="http://www.pastebin.com">pastebin.com</a>.  It does a nice job of converting source code into html.  And it has syntax highlighting for most languages, including C#.  To streamline the process, I wrote a parser.  This code will parse the full source of the pastebin output, yank out the relevent html, and add style to make it look close to Visual Studio.  The following source code is a solution to the problem and also a demonstration.  <b>Which method do you think looks better?</b></p>
<div style="font-family:monospace;font-size:1.3em;">
<div style="background:#ffffff;">
<div><span style="color:#0600FF;">using</span> <span style="color:#000000;">System</span>;</div>
</div>
<div style="background:#f4f4f4;">
<div><span style="color:#0600FF;">using</span> <span style="color:#000000;">System</span>.<span style="color:#0000FF;">IO</span>;</div>
</div>
<div style="background:#ffffff;">
<div><span style="color:#0600FF;">using</span> <span style="color:#000000;">System</span>.<span style="color:#0000FF;">Text</span>.<span style="color:#0000FF;">RegularExpressions</span>;</div>
</div>
<div style="background:#f4f4f4;">
<div> </div>
</div>
<div style="background:#ffffff;">
<div><span style="color:#0600FF;">namespace</span> PasteBinCodeScrubber</div>
</div>
<div style="background:#f4f4f4;">
<div><span style="color:#008000;">{</span></div>
</div>
<div style="background:#ffffff;">
<div>    <span style="color:#0600FF;">class</span> Program</div>
</div>
<div style="background:#f4f4f4;">
<div>    <span style="color:#008000;">{</span></div>
</div>
<div style="background:#ffffff;">
<div>        <span style="color:#0600FF;">static</span> <span style="color:#0600FF;">void</span> Main<span style="color:#008000;">(</span><span style="color:#0600FF;">string</span><span style="color:#008000;">[</span><span style="color:#008000;">]</span> args<span style="color:#008000;">)</span></div>
</div>
<div style="background:#f4f4f4;">
<div>        <span style="color:#008000;">{</span></div>
</div>
<div style="background:#ffffff;">
<div>            FileInfo<span style="color:#008000;">[</span><span style="color:#008000;">]</span> allHtmlFiles = <span style="color:#0600FF;">new</span> DirectoryInfo<span style="color:#008000;">(</span><span style="color:maroon;">&#8220;.&#8221;</span><span style="color:#008000;">)</span>.<span style="color:#0000FF;">GetFiles</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;*.htm*&#8221;</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#f4f4f4;">
<div>            <span style="color:#0600FF;">foreach</span> <span style="color:#008000;">(</span>FileInfo htmlFile <span style="color:#0600FF;">in</span> allHtmlFiles<span style="color:#008000;">)</span></div>
</div>
<div style="background:#ffffff;">
<div>            <span style="color:#008000;">{</span></div>
</div>
<div style="background:#f4f4f4;">
<div>                <span style="color:#0600FF;">string</span> allHtml = File.<span style="color:#0000FF;">ReadAllText</span><span style="color:#008000;">(</span>htmlFile.<span style="color:#0000FF;">FullName</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#ffffff;">
<div> </div>
</div>
<div style="background:#f4f4f4;">
<div>                <span style="color:green;">// capture all relevent html</span></div>
</div>
<div style="background:#ffffff;">
<div>                Regex sourceCodeRegex = <span style="color:#0600FF;">new</span> Regex<span style="color:#008000;">(</span><span style="color:maroon;">&#8220;&lt;div class=<span style="color:#008080;">&#8220;</span>csharp<span style="color:#008080;">&#8220;</span> style=<span style="color:#008080;">&#8220;</span>font-family: monospace;<span style="color:#008080;">&#8220;</span>&gt;&lt;ol&gt;[<span style="color:#008080;">\</span>s<span style="color:#008080;">\</span>S]*?&lt;/ol&gt;&lt;/div&gt;&#8221;</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#f4f4f4;">
<div>                <span style="color:#0600FF;">string</span> sourceCodeHtml = sourceCodeRegex.<span style="color:#0000FF;">Match</span><span style="color:#008000;">(</span>allHtml<span style="color:#008000;">)</span>.<span style="color:#0000FF;">Value</span>;</div>
</div>
<div style="background:#ffffff;">
<div> </div>
</div>
<div style="background:#f4f4f4;">
<div>                <span style="color:green;">// doctor the html</span></div>
</div>
<div style="background:#ffffff;">
<div>                sourceCodeHtml = ScrubHtml<span style="color:#008000;">(</span>sourceCodeHtml<span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#f4f4f4;">
<div>                sourceCodeHtml = ReplaceCssClassWithStyle<span style="color:#008000;">(</span>sourceCodeHtml<span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#ffffff;">
<div> </div>
</div>
<div style="background:#f4f4f4;">
<div>                File.<span style="color:#0000FF;">WriteAllText</span><span style="color:#008000;">(</span>htmlFile.<span style="color:#0000FF;">FullName</span> + <span style="color:maroon;">&#8220;.out&#8221;</span>, sourceCodeHtml<span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#ffffff;">
<div>            <span style="color:#008000;">}</span></div>
</div>
<div style="background:#f4f4f4;">
<div>        <span style="color:#008000;">}</span></div>
</div>
<div style="background:#ffffff;">
<div> </div>
</div>
<div style="background:#f4f4f4;">
<div>        <span style="color:#0600FF;">private</span> <span style="color:#0600FF;">static</span> <span style="color:#0600FF;">string</span> ReplaceCssClassWithStyle<span style="color:#008000;">(</span><span style="color:#0600FF;">string</span> sourceCodeHtml<span style="color:#008000;">)</span></div>
</div>
<div style="background:#ffffff;">
<div>        <span style="color:#008000;">{</span></div>
</div>
<div style="background:#f4f4f4;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;class=<span style="color:#008080;">&#8220;</span>de1<span style="color:#008080;">&#8220;</span>&#8220;</span>, <span style="color:#0600FF;">string</span>.<span style="color:#0000FF;">Empty</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#ffffff;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;class=<span style="color:#008080;">&#8220;</span>de2<span style="color:#008080;">&#8220;</span>&#8220;</span>, <span style="color:#0600FF;">string</span>.<span style="color:#0000FF;">Empty</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#f4f4f4;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;class=<span style="color:#008080;">&#8220;</span>inp<span style="color:#008080;">&#8220;</span>&#8220;</span>, <span style="color:maroon;">&#8220;style=<span style="color:#008080;">&#8220;</span>color: red;<span style="color:#008080;">&#8220;</span>&#8220;</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#ffffff;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;class=<span style="color:#008080;">&#8220;</span>li1<span style="color:#008080;">&#8220;</span>&#8220;</span>, <span style="color:maroon;">&#8220;style=<span style="color:#008080;">&#8220;</span>background: #ffffff;<span style="color:#008080;">&#8220;</span>&#8220;</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#f4f4f4;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;class=<span style="color:#008080;">&#8220;</span>li2<span style="color:#008080;">&#8220;</span>&#8220;</span>, <span style="color:maroon;">&#8220;style=<span style="color:#008080;">&#8220;</span>background: #f4f4f4;<span style="color:#008080;">&#8220;</span>&#8220;</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#ffffff;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;class=<span style="color:#008080;">&#8220;</span>kw1<span style="color:#008080;">&#8220;</span>&#8220;</span>, <span style="color:maroon;">&#8220;style=<span style="color:#008080;">&#8220;</span>color: #0600FF;<span style="color:#008080;">&#8220;</span>&#8220;</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#f4f4f4;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;class=<span style="color:#008080;">&#8220;</span>kw2<span style="color:#008080;">&#8220;</span>&#8220;</span>, <span style="color:maroon;">&#8220;style=<span style="color:#008080;">&#8220;</span>color: #FF8000;<span style="color:#008080;">&#8220;</span>&#8220;</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#ffffff;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;class=<span style="color:#008080;">&#8220;</span>kw3<span style="color:#008080;">&#8220;</span>&#8220;</span>, <span style="color:maroon;">&#8220;style=<span style="color:#008080;">&#8220;</span>color: #0600FF;<span style="color:#008080;">&#8220;</span>&#8220;</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#f4f4f4;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;class=<span style="color:#008080;">&#8220;</span>kw4<span style="color:#008080;">&#8220;</span>&#8220;</span>, <span style="color:maroon;">&#8220;style=<span style="color:#008080;">&#8220;</span>color: #0600FF;<span style="color:#008080;">&#8220;</span>&#8220;</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#ffffff;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;class=<span style="color:#008080;">&#8220;</span>kw5<span style="color:#008080;">&#8220;</span>&#8220;</span>, <span style="color:maroon;">&#8220;style=<span style="color:#008080;">&#8220;</span>color: #000000;<span style="color:#008080;">&#8220;</span>&#8220;</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#f4f4f4;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;class=<span style="color:#008080;">&#8220;</span>co1<span style="color:#008080;">&#8220;</span>&#8220;</span>, <span style="color:maroon;">&#8220;style=<span style="color:#008080;">&#8220;</span>color: green;<span style="color:#008080;">&#8220;</span>&#8220;</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#ffffff;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;class=<span style="color:#008080;">&#8220;</span>co2<span style="color:#008080;">&#8220;</span>&#8220;</span>, <span style="color:maroon;">&#8220;style=<span style="color:#008080;">&#8220;</span>color: green;<span style="color:#008080;">&#8220;</span>&#8220;</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#f4f4f4;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;class=<span style="color:#008080;">&#8220;</span>coMULTI<span style="color:#008080;">&#8220;</span>&#8220;</span>, <span style="color:maroon;">&#8220;style=<span style="color:#008080;">&#8220;</span>color: green;<span style="color:#008080;">&#8220;</span>&#8220;</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#ffffff;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;class=<span style="color:#008080;">&#8220;</span>es0<span style="color:#008080;">&#8220;</span>&#8220;</span>, <span style="color:maroon;">&#8220;style=<span style="color:#008080;">&#8220;</span>color: #008080;<span style="color:#008080;">&#8220;</span>&#8220;</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#f4f4f4;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;class=<span style="color:#008080;">&#8220;</span>br0<span style="color:#008080;">&#8220;</span>&#8220;</span>, <span style="color:maroon;">&#8220;style=<span style="color:#008080;">&#8220;</span>color: #008000;<span style="color:#008080;">&#8220;</span>&#8220;</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#ffffff;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;class=<span style="color:#008080;">&#8220;</span>st0<span style="color:#008080;">&#8220;</span>&#8220;</span>, <span style="color:maroon;">&#8220;style=<span style="color:#008080;">&#8220;</span>color: maroon;<span style="color:#008080;">&#8220;</span>&#8220;</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#f4f4f4;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;class=<span style="color:#008080;">&#8220;</span>nu0<span style="color:#008080;">&#8220;</span>&#8220;</span>, <span style="color:maroon;">&#8220;style=<span style="color:#008080;">&#8220;</span>color: #FF0000;<span style="color:#008080;">&#8220;</span>&#8220;</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#ffffff;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;class=<span style="color:#008080;">&#8220;</span>me1<span style="color:#008080;">&#8220;</span>&#8220;</span>, <span style="color:maroon;">&#8220;style=<span style="color:#008080;">&#8220;</span>color: #0000FF;<span style="color:#008080;">&#8220;</span>&#8220;</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#f4f4f4;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;class=<span style="color:#008080;">&#8220;</span>me2<span style="color:#008080;">&#8220;</span>&#8220;</span>, <span style="color:maroon;">&#8220;style=<span style="color:#008080;">&#8220;</span>color: #0000FF;<span style="color:#008080;">&#8220;</span>&#8220;</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#ffffff;">
<div>            <span style="color:#0600FF;">return</span> sourceCodeHtml;</div>
</div>
<div style="background:#f4f4f4;">
<div>        <span style="color:#008000;">}</span></div>
</div>
<div style="background:#ffffff;">
<div> </div>
</div>
<div style="background:#f4f4f4;">
<div>        <span style="color:#0600FF;">private</span> <span style="color:#0600FF;">static</span> <span style="color:#0600FF;">string</span> ScrubHtml<span style="color:#008000;">(</span><span style="color:#0600FF;">string</span> sourceCodeHtml<span style="color:#008000;">)</span></div>
</div>
<div style="background:#ffffff;">
<div>        <span style="color:#008000;">{</span></div>
</div>
<div style="background:#f4f4f4;">
<div>            <span style="color:green;">// add font size</span></div>
</div>
<div style="background:#ffffff;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;&lt;div class=<span style="color:#008080;">&#8220;</span>csharp<span style="color:#008080;">&#8220;</span> style=<span style="color:#008080;">&#8220;</span>font-family: monospace;<span style="color:#008080;">&#8220;</span>&gt;&#8221;</span>,</div>
</div>
<div style="background:#f4f4f4;">
<div>                                                    <span style="color:maroon;">&#8220;&lt;div style=<span style="color:#008080;">&#8220;</span>font-family:monospace; font-size:1.3em;<span style="color:#008080;">&#8220;</span>&gt;&#8221;</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#ffffff;">
<div> </div>
</div>
<div style="background:#f4f4f4;">
<div>            <span style="color:green;">// remove list tags</span></div>
</div>
<div style="background:#ffffff;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;&lt;ol&gt;&#8221;</span>, <span style="color:#0600FF;">string</span>.<span style="color:#0000FF;">Empty</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#f4f4f4;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;&lt;/ol&gt;&#8221;</span>, <span style="color:#0600FF;">string</span>.<span style="color:#0000FF;">Empty</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#ffffff;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;&lt;li &#8220;</span>, <span style="color:maroon;">&#8220;&lt;div &#8220;</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#f4f4f4;">
<div>            sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span><span style="color:maroon;">&#8220;&lt;/li&gt;&#8221;</span>, <span style="color:maroon;">&#8220;&lt;/div&gt;&#8221;</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#ffffff;">
<div> </div>
</div>
<div style="background:#f4f4f4;">
<div>            <span style="color:green;">// remove hyperlinks</span></div>
</div>
<div style="background:#ffffff;">
<div>            Regex hyperLinkRegex = <span style="color:#0600FF;">new</span> Regex<span style="color:#008000;">(</span><span style="color:maroon;">&#8220;&lt;a href=.*?&gt;(?&#8217;linkWrappedHtml&#8217;[<span style="color:#008080;">\</span>s<span style="color:#008080;">\</span>S]*?)&lt;/a&gt;&#8221;</span>, RegexOptions.<span style="color:#0000FF;">ExplicitCapture</span><span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#f4f4f4;">
<div>            MatchCollection hyperLinkMatches = hyperLinkRegex.<span style="color:#0000FF;">Matches</span><span style="color:#008000;">(</span>sourceCodeHtml<span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#ffffff;">
<div>            <span style="color:#0600FF;">foreach</span> <span style="color:#008000;">(</span>Match hyperLinkMatch <span style="color:#0600FF;">in</span> hyperLinkMatches<span style="color:#008000;">)</span></div>
</div>
<div style="background:#f4f4f4;">
<div>            <span style="color:#008000;">{</span></div>
</div>
<div style="background:#ffffff;">
<div>                <span style="color:#0600FF;">string</span> sHtmlInsideHyperLink = hyperLinkMatch.<span style="color:#0000FF;">Groups</span><span style="color:#008000;">[</span><span style="color:maroon;">"linkWrappedHtml"</span><span style="color:#008000;">]</span>.<span style="color:#0000FF;">Value</span>;</div>
</div>
<div style="background:#f4f4f4;">
<div>                <span style="color:#0600FF;">string</span> sFullHyperLink = hyperLinkMatch.<span style="color:#0000FF;">Value</span>;</div>
</div>
<div style="background:#ffffff;">
<div>                sourceCodeHtml = sourceCodeHtml.<span style="color:#0000FF;">Replace</span><span style="color:#008000;">(</span>sFullHyperLink, sHtmlInsideHyperLink<span style="color:#008000;">)</span>;</div>
</div>
<div style="background:#f4f4f4;">
<div>            <span style="color:#008000;">}</span></div>
</div>
<div style="background:#ffffff;">
<div> </div>
</div>
<div style="background:#f4f4f4;">
<div>            <span style="color:#0600FF;">return</span> sourceCodeHtml;</div>
</div>
<div style="background:#ffffff;">
<div>        <span style="color:#008000;">}</span></div>
</div>
<div style="background:#f4f4f4;">
<div>    <span style="color:#008000;">}</span></div>
</div>
<div style="background:#ffffff;">
<div><span style="color:#008000;">}</span></div>
</div>
</div>
<p><!-- AddThis Button BEGIN --></p>
<div><a title="Bookmark and Share" href="http://www.addthis.com/bookmark.php?pub=kkopczyk&amp;url=http://kkopczyk.wordpress.com/2009/02/01/displaying-source-code-in-a-wordpress-post/" target="_blank"><img style="border:0;padding:0;" src="http://s7.addthis.com/static/btn/lg-share-en.gif" alt="Bookmark and Share" width="125" height="16" /></a></div>
<p><!-- AddThis Button END --></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kkopczyk.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kkopczyk.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kkopczyk.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kkopczyk.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kkopczyk.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kkopczyk.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kkopczyk.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kkopczyk.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kkopczyk.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kkopczyk.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kkopczyk.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kkopczyk.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kkopczyk.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kkopczyk.wordpress.com/70/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kenkopczyk.com&blog=6344943&post=70&subd=kkopczyk&ref=&feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kenkopczyk.com/2009/02/01/displaying-source-code-in-a-wordpress-post/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/df43ecaeb5e162064d67f882431983c6?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Ken</media:title>
		</media:content>

		<media:content url="http://s7.addthis.com/static/btn/lg-share-en.gif" medium="image">
			<media:title type="html">Bookmark and Share</media:title>
		</media:content>
	</item>
	</channel>
</rss>