<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Guy Starbuck</title><subtitle type="html" /><id>http://weblogs.asp.net/guystarbuck/atom.aspx</id><link rel="alternate" type="text/html" href="http://weblogs.asp.net/guystarbuck/default.aspx" /><link rel="self" type="application/atom+xml" href="http://weblogs.asp.net/guystarbuck/atom.aspx" /><generator uri="http://communityserver.org" version="3.0.20510.895">Community Server</generator><updated>2008-01-31T10:36:12Z</updated><entry><title>Load a ComboBox from Excel</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/guystarbuck/archive/2009/02/03/load-a-combobox-from-excel.aspx" /><id>http://weblogs.asp.net/guystarbuck/archive/2009/02/03/load-a-combobox-from-excel.aspx</id><published>2009-02-04T03:40:55Z</published><updated>2009-02-04T03:40:55Z</updated><content type="html">&lt;p&gt;This is another post that came from a &lt;a href="http://stackoverflow.com/questions/509749/loading-excel-column-data-using-c-in-a-dropdown-menu"&gt;question on StackOverflow&lt;/a&gt; – The idea is to load up a drop-down (I used a System.Windows.Forms.ComboBox) using values defined in an Excel document.&lt;/p&gt;  &lt;p&gt;As usual, almost all of the Office Interop samples on the web are written in VB.NET – this makes sense, since it is a lot easier to program interop using VBNet and its support for optional parameters.&amp;#160; I got a great start from this forum post, I just simplified and converted it to C#.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;
&lt;span class="kwrd"&gt;using&lt;/span&gt; Excel = Microsoft.Office.Interop.Excel;

&lt;span class="kwrd"&gt;namespace&lt;/span&gt; CSharpClassLibrary
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ComboBoxLoader
    {
        &lt;span class="rem"&gt;// Define an object to pass to the API for missing parameters&lt;/span&gt;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; missing = Type.Missing;

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; FillDropDown(&lt;span class="kwrd"&gt;ref&lt;/span&gt; System.Windows.Forms.ComboBox cbo)
        {
            Excel.Application excel = &lt;span class="kwrd"&gt;new&lt;/span&gt; Excel.Application();
            Excel.Workbook workbook;
            Excel.Worksheet worksheet;

            &lt;span class="kwrd"&gt;if&lt;/span&gt; (excel == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt;;
            }
            &lt;span class="kwrd"&gt;else&lt;/span&gt;
            {
                &lt;span class="rem"&gt;// Set Excel to be hidden&lt;/span&gt;
                excel.Visible = &lt;span class="kwrd"&gt;false&lt;/span&gt;;

                &lt;span class="rem"&gt;// Open the workbook -- note the passing of the &amp;quot;missing&amp;quot; parameter&lt;/span&gt;
                &lt;span class="rem"&gt;// for everything except the file name&lt;/span&gt;
                workbook = excel.Workbooks.Open(&lt;span class="str"&gt;@&amp;quot;c:\temp\test.xlsx&amp;quot;&lt;/span&gt;, missing,
                    missing, missing, missing, missing, missing, missing,
                    missing, missing, missing, missing, missing, missing, missing);

                &lt;span class="rem"&gt;// This example assumes the first worksheet&lt;/span&gt;
                worksheet = workbook.Worksheets[1] &lt;span class="kwrd"&gt;as&lt;/span&gt; Excel.Worksheet;

                &lt;span class="rem"&gt;// This example assumes that there are five values, in cells&lt;/span&gt;
                &lt;span class="rem"&gt;// A1 to A5, that need to be loaded&lt;/span&gt;
                Excel.Range range;
                range = worksheet.get_Range(&lt;span class="str"&gt;&amp;quot;A1&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;A5&amp;quot;&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; Excel.Range;

                &lt;span class="rem"&gt;// Loop through the cells in the Range and add their values to&lt;/span&gt;
                &lt;span class="rem"&gt;// the combo box&lt;/span&gt;
                &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Excel.Range cell &lt;span class="kwrd"&gt;in&lt;/span&gt; range.Cells)
                {
                    cbo.Items.Add(cell.Value2 &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;);
                }

                &lt;span class="rem"&gt;// Clean up -- important with PIA Interop, as lots of&lt;/span&gt;
                &lt;span class="rem"&gt;// instances of Excel might be left around in memory&lt;/span&gt;
                workbook.Close(missing, missing, missing);
                excel.Quit();
            }
        }
    }
}&lt;/pre&gt;

&lt;p&gt;&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/p&gt;

&lt;p&gt;This is not something I would necessarily do (using Office Interop is a big thing to bite off in a project, and while I can see how feeding drop-down options from Excel could provide ease of use for non-technical admins, there are lots of less heavy-handed approaches), but it was interesting to figure out how to get the code working, and I thought it might help someone with other Excel automation tasks.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6879666" width="1" height="1"&gt;</content><author><name>gstarbuck</name><uri>http://weblogs.asp.net/members/gstarbuck.aspx</uri></author></entry><entry><title>Trace Points in Visual Studio 2008</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/guystarbuck/archive/2009/01/29/trace-points-in-visual-studio-2008.aspx" /><id>http://weblogs.asp.net/guystarbuck/archive/2009/01/29/trace-points-in-visual-studio-2008.aspx</id><published>2009-01-30T03:24:04Z</published><updated>2009-01-30T03:24:04Z</updated><content type="html">&lt;p&gt;This is a little piece of functionality I stumbled across in Visual Studio 2008.&lt;/p&gt;  &lt;p&gt;You can set up a “Trace Point”, which is like a breakpoint that doesn’t break, it logs a trace message to the debug trace listener.&lt;/p&gt;  &lt;p&gt;Here’s how to set one up: &lt;/p&gt;  &lt;h4&gt;1: Set a breakpoint on the line where you want to log the trace&lt;/h4&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/guystarbuck/CropperCapture5_419DF0F2.png"&gt;&lt;img title="CropperCapture[5]" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="177" alt="CropperCapture[5]" src="http://weblogs.asp.net/blogs/guystarbuck/CropperCapture5_thumb_33CE3BA8.png" width="590" border="0" /&gt;&lt;/a&gt;&amp;#160; &lt;/p&gt;  &lt;h4&gt;2: Right click the breakpoint, and select “When Hit…”&lt;/h4&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/guystarbuck/CropperCapture1_6A3EEDAA.png"&gt;&lt;img title="CropperCapture[1]" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="276" alt="CropperCapture[1]" src="http://weblogs.asp.net/blogs/guystarbuck/CropperCapture1_thumb_13498CA7.png" width="264" border="0" /&gt;&lt;/a&gt;&amp;#160; &lt;/p&gt;  &lt;h4&gt;3: In the dialog, enter the message&lt;/h4&gt;  &lt;p&gt;Variables can be logged using “{}”, as specified in the dialog instructions.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/guystarbuck/CropperCapture6_22EC2869.png"&gt;&lt;img title="CropperCapture[6]" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="268" alt="CropperCapture[6]" src="http://weblogs.asp.net/blogs/guystarbuck/CropperCapture6_thumb_0BC0ADEB.png" width="307" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Now the code shows a “diamond” instead of circle for the trace point:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/guystarbuck/CropperCapture7_4F9772F3.png"&gt;&lt;img title="CropperCapture[7]" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="159" alt="CropperCapture[7]" src="http://weblogs.asp.net/blogs/guystarbuck/CropperCapture7_thumb_060824F6.png" width="542" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h4&gt;4: Finally, run the code and see the trace messages in the Debug Output (in the Output window in Visual Studio)&lt;/h4&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/guystarbuck/CropperCapture8_5C93E3B5.png"&gt;&lt;img title="CropperCapture[8]" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="286" alt="CropperCapture[8]" src="http://weblogs.asp.net/blogs/guystarbuck/CropperCapture8_thumb_727D5605.png" width="506" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;This is really useful when you have some complicated looping or recursion that you need to debug; stepping through takes a lot of time and is confusing, you lose the forest for the trees.&amp;#160; But if you can spool out traces you can see exactly what has happened after the code is done running, and run it multiple times with different input to see how it changes.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;A few notes:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;The trace message is logged before the line is evaluated – so in the sample code, I am tracing the value of “depth” before 1 is added to it.&amp;#160; If you want to get the value after execution of the line, set the trace to the line below it.&lt;/li&gt;    &lt;li&gt;These trace points are only as stable as breakpoints, as they are stored in your VS user options file.&amp;#160; If the code structure is modified outside of your editor (such as by another developer, then updated through source control), the positions can be thrown off and the traces will not work.&amp;#160; If you need stable tracing, use System.Diagnostics.Trace.Write in an explicit call in your code; trace points are really only for specific debugging efforts.&lt;/li&gt; &lt;/ul&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6868894" width="1" height="1"&gt;</content><author><name>gstarbuck</name><uri>http://weblogs.asp.net/members/gstarbuck.aspx</uri></author></entry><entry><title>WPF Debugging -- "Unable to cast object of type 'System.Windows.Controls.Grid' to type 'System.Windows.Window'</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/guystarbuck/archive/2008/11/10/wpf-debugging-quot-unable-to-cast-object-of-type-system-windows-controls-grid-to-type-system-windows-window.aspx" /><id>http://weblogs.asp.net/guystarbuck/archive/2008/11/10/wpf-debugging-quot-unable-to-cast-object-of-type-system-windows-controls-grid-to-type-system-windows-window.aspx</id><published>2008-11-11T03:26:22Z</published><updated>2008-11-11T03:26:22Z</updated><content type="html">&lt;p&gt;I hunted down a kind of a tricky error message today, and thought I'd write a quick post about it.&lt;/p&gt;  &lt;h3&gt;The Scenario:&lt;/h3&gt;  &lt;p&gt;I was doing some refactoring of a WPF app, encapsulating a section of one large-ish UserControl into a second UserControl.&amp;#160; &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Prior to the refactoring, the single combined UserControl was running directly as the StartupURI of a test harness app.xaml, which resulted in it being hosted in a NavigationWindow when run &lt;/li&gt;    &lt;li&gt;The new extracted User Control contained most of the business functionality of the containing control &lt;/li&gt;    &lt;li&gt;The original UserControl was converted into a Window, containing a Grid, which then contained the extracted UserControl &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;The Error:&lt;/h3&gt;  &lt;p&gt;In the designer and at runtime, the following dialog popped up one time:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/guystarbuck/WindowsLiveWriter/WPFDebuggingUnabletocastobjectoft.Window_12D7B/image_6.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="136" alt="image" src="http://weblogs.asp.net/blogs/guystarbuck/WindowsLiveWriter/WPFDebuggingUnabletocastobjectoft.Window_12D7B/image_thumb_2.png" width="613" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;As soon as the dialog was cleared, both the designer surface and the app worked as expected.&lt;/p&gt;  &lt;h3&gt;The Solution:&lt;/h3&gt;  &lt;p&gt;It turns out that I had two lines in the constructor of my original user control (for positioning of the hosting window), which I had moved to the constructor in the extracted UserControl, which referenced the parent cast as a Window:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;((&lt;font color="#0080ff"&gt;Window&lt;/font&gt;)Parent.Left = 0;
((&lt;font color="#0080ff"&gt;Window&lt;/font&gt;)Parent).Top = 0;&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Obvious -- the Designer and WPF at runtime both evaluated this code, and since the parent was no longer a Window, the cast didn't work.&lt;/p&gt;

&lt;p&gt;I moved these lines into the constructor and this resolved the issue.&lt;/p&gt;

&lt;h3&gt;Summary:&lt;/h3&gt;

&lt;p&gt;I'm not surprised that the error was thrown, but I was interested in two aspects:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The Designer (Cider) evaluated the constructor code in the UserControl to the point that it threw casting errors on the Parent property.&amp;#160; I guess this is necessary to make sure everything renders correctly in the Designer surface, but I shudder to think of the amount of logic that Visual Studio must run to decide what code to run and what to ignore when loading up the Designer surface. &lt;/li&gt;

  &lt;li&gt;At runtime, WPF handled this error and generated its own error dialog, rather than throwing an unhandled exception.&amp;#160; This would've been a lot easier to debug if it had thrown like a normal unhandled exception in Visual Studio. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All in all, it was an interesting exercise.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6728987" width="1" height="1"&gt;</content><author><name>gstarbuck</name><uri>http://weblogs.asp.net/members/gstarbuck.aspx</uri></author></entry><entry><title>Shared Message Area in WPF Using Publish/Subscribe</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/guystarbuck/archive/2008/10/08/shared-message-area-in-wpf-using-publish-subscribe.aspx" /><id>http://weblogs.asp.net/guystarbuck/archive/2008/10/08/shared-message-area-in-wpf-using-publish-subscribe.aspx</id><published>2008-10-09T03:44:23Z</published><updated>2008-10-09T03:44:23Z</updated><content type="html">&lt;p&gt;I posted a quick answer a little while ago on &lt;a href="http://stackoverflow.com" target="_blank"&gt;StackOverflow&lt;/a&gt;, where the question was &amp;quot;&lt;a href="http://stackoverflow.com/questions/50151/what-is-the-best-way-to-display-a-status-message-in-wpf" target="_blank"&gt;What is the best way to display a status message in WPF?&lt;/a&gt;&amp;quot;&lt;/p&gt;  &lt;p&gt;My answer:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;You may want to consider doing a publish/subscribe (&amp;quot;Observer&amp;quot; pattern) -- define a &amp;quot;status changed&amp;quot; event on a base page, and create a custom control that sets up a delegate and event handler to listen for status updates.&lt;/p&gt;    &lt;p&gt;Then you could drop the custom control on any page that inherits from the base, and it would automatically listen for and display status messages whenever the event is fired.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I thought this would be fun to prove out, so last night I threw together a sample app that implements this solution.&amp;#160; Here is a walkthrough.&lt;/p&gt;  &lt;h3&gt;Custom Event Args&lt;/h3&gt;  &lt;p&gt;The first thing that is needed is an &amp;quot;EventArgs&amp;quot; class to be able to pass message text through an event.&amp;#160; Here is the class declaration.&amp;#160; It's simply a class derived from &amp;quot;EventArgs&amp;quot; that defines a single string property to hold the message text:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;

&lt;span class="kwrd"&gt;namespace&lt;/span&gt; MessageAreaBlogDemo
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; DisplayMessageEventArgs : EventArgs
    {
        &lt;span class="rem"&gt;// Constructor&lt;/span&gt;
        &lt;span class="kwrd"&gt;public&lt;/span&gt; DisplayMessageEventArgs(&lt;span class="kwrd"&gt;string&lt;/span&gt; s) { MessageText = s; }
        
        &lt;span class="rem"&gt;// Read-only property&lt;/span&gt;
        &lt;span class="kwrd"&gt;public&lt;/span&gt; String MessageText { get; &lt;span class="kwrd"&gt;private&lt;/span&gt; set; }
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;h3&gt;Creating the Custom Base Class&lt;/h3&gt;

&lt;p&gt;Next, create a new class for the custom System.Windows.Window-derived base class, which I called &amp;quot;CustomWindowBase&amp;quot;, that defines the event.&amp;#160; Here is the code:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Windows;

&lt;span class="kwrd"&gt;namespace&lt;/span&gt; MessageAreaBlogDemo
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CustomWindowBase : Window
    {
        &lt;span class="rem"&gt;// Declare the event handler&lt;/span&gt;
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;delegate&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DisplayMessageEventHandler(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, DisplayMessageEventArgs e);

        &lt;span class="rem"&gt;// Declare the event&lt;/span&gt;
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;event&lt;/span&gt; DisplayMessageEventHandler DisplayMessage;

        &lt;span class="rem"&gt;// Create a method that can be called to publish the message to any listeners&lt;/span&gt;
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; PublishMessage(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, &lt;span class="kwrd"&gt;string&lt;/span&gt; text)
        {
            &lt;span class="rem"&gt;// Check if the event is null, meaning there are no Message Areas subscribed&lt;/span&gt;
            &lt;span class="rem"&gt;// to it.  If you don't check this, the app will throw an exception when it&lt;/span&gt;
            &lt;span class="rem"&gt;// tries to display a message on a form without a Message Area!&lt;/span&gt;
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (DisplayMessage != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
                DisplayMessage(sender, &lt;span class="kwrd"&gt;new&lt;/span&gt; DisplayMessageEventArgs(text));
            }
        }
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;h4&gt;&lt;/h4&gt;

&lt;h3&gt;Setting a Window to Inherit From the Custom Base Class&lt;/h3&gt;

&lt;p&gt;Changing the base class of a WPF Window requires changes in both the code and the xaml.&amp;#160; In the XAML, start by adding a new namespace for the local assembly, and changing the &amp;quot;Window&amp;quot; class definition to your new type.&amp;#160; Note that both files must be changed before you can build.&lt;/p&gt;

&lt;p&gt;XAML before:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Window&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;MessageAreaBlogDemo.Window1&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;Title&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Window1&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;300&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;300&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Window&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;XAML After:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;local:CustomWindowBase&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;MessageAreaBlogDemo.Window1&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns:local&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;clr-namespace:MessageAreaBlogDemo&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;Title&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Window1&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;300&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;300&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;local:CustomWindowBase&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Code for Window1.xaml.cs:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;
&lt;span class="kwrd"&gt;namespace&lt;/span&gt; MessageAreaBlogDemo
{
    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// Interaction logic for Window1.xaml&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    
    &lt;span class="rem"&gt;// Modify to inherit from CustomWindowBase&lt;/span&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Window1 : CustomWindowBase
    {
        &lt;span class="kwrd"&gt;public&lt;/span&gt; Window1()
        {
            InitializeComponent();
        }
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;h3&gt;Creating the Message Area&lt;/h3&gt;

&lt;p&gt;Now you can create a new User Control to house the message area.&amp;#160; I just defined a simple user control that contains a grid that holds a label.&amp;#160; I set the color of the grid so that it jumps out on the page.&amp;#160; Also, note the &amp;quot;Loaded&amp;quot; event handler to the control declaration in XAML -- this is used to fire the event that registers the control with the parent Window to receive messages.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/guystarbuck/WindowsLiveWriter/SharedMessageAreainWPFUsingPubSub_124C2/image_2.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="50" alt="image" src="http://weblogs.asp.net/blogs/guystarbuck/WindowsLiveWriter/SharedMessageAreainWPFUsingPubSub_124C2/image_thumb.png" width="244" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;MessageAreaBlogDemo.MessageArea&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;30&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;300&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;Background&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;AliceBlue&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Label&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;labelMessage&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Message Goes Here&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;And here is the code behind:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Windows;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Windows.Controls;

&lt;span class="kwrd"&gt;namespace&lt;/span&gt; MessageAreaBlogDemo
{
    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// Interaction logic for MessageArea.xaml&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MessageArea : UserControl
    {
        &lt;span class="kwrd"&gt;public&lt;/span&gt; MessageArea()
        {
            InitializeComponent();
        }

        &lt;span class="rem"&gt;// Event that fires after the Window and all controls have been loaded and&lt;/span&gt;
        &lt;span class="rem"&gt;// are about to be rendered&lt;/span&gt;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; UserControl_Loaded(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, System.Windows.RoutedEventArgs e)
        {
            &lt;span class="rem"&gt;// Get the containing Window using the static &amp;quot;Window.GetWindow&amp;quot; method,&lt;/span&gt;
            &lt;span class="rem"&gt;// then cast it to a CustomWindowBase&lt;/span&gt;
            CustomWindowBase parent = (CustomWindowBase)Window.GetWindow(&lt;span class="kwrd"&gt;this&lt;/span&gt;);

            &lt;span class="rem"&gt;// Register with the event delegate&lt;/span&gt;
            parent.DisplayMessage += &lt;span class="kwrd"&gt;new&lt;/span&gt; CustomWindowBase.DisplayMessageEventHandler(parent_DisplayMessage);
        }

        &lt;span class="rem"&gt;// Event handler, called whenever the parent Window raises the custom event&lt;/span&gt;
        &lt;span class="kwrd"&gt;void&lt;/span&gt; parent_DisplayMessage(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, DisplayMessageEventArgs e)
        {
            &lt;span class="rem"&gt;// Display the text in the message area&lt;/span&gt;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.labelMessage.Content = e.MessageText;
        }
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;h3&gt;Put the Controls on the Form&lt;/h3&gt;

&lt;p&gt;The last step is to just put the MessageArea on the form, and fire the event to display messages on it.&amp;#160; Without going into how to add the control to the toolbox, we can just add the controls in the xaml editor like so:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/guystarbuck/WindowsLiveWriter/SharedMessageAreainWPFUsingPubSub_124C2/image_4.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="242" alt="image" src="http://weblogs.asp.net/blogs/guystarbuck/WindowsLiveWriter/SharedMessageAreainWPFUsingPubSub_124C2/image_thumb_1.png" width="244" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;local:CustomWindowBase&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;MessageAreaBlogDemo.Window1&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns:local&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;clr-namespace:MessageAreaBlogDemo&amp;quot;&lt;/span&gt;
    &lt;span class="attr"&gt;Title&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Window1&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;300&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;300&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;23&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Left&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Margin&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;12,12,0,0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;button1&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Top&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;75&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Click&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;button1_Click&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Log Message&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;local:MessageArea&lt;/span&gt; &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Bottom&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;200&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;local:CustomWindowBase&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Now, in the code behind for the Window, simply have the &amp;quot;Click&amp;quot; handler fire the event with an appropriate message.&amp;#160; I just have it display the date/time so that&amp;#160; you can see the seconds refresh to verify that it is working:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; button1_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, System.Windows.RoutedEventArgs e)
{
    &lt;span class="kwrd"&gt;this&lt;/span&gt;.PublishMessage(sender, &lt;span class="str"&gt;&amp;quot;Date/Time:&amp;quot;&lt;/span&gt; + System.DateTime.Now.ToString());
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;h3&gt;Conclusions&lt;/h3&gt;

&lt;p&gt;Any number of message areas could be added to a Window, and they will all register with the delegate and display the message when the event fires; likewise, windows that inherit from the custom base class don't have to have a message area, the event just won't fire.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6666624" width="1" height="1"&gt;</content><author><name>gstarbuck</name><uri>http://weblogs.asp.net/members/gstarbuck.aspx</uri></author></entry><entry><title>Stack Overflow</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/guystarbuck/archive/2008/09/17/stack-overflow.aspx" /><id>http://weblogs.asp.net/guystarbuck/archive/2008/09/17/stack-overflow.aspx</id><published>2008-09-18T01:55:51Z</published><updated>2008-09-18T01:55:51Z</updated><content type="html">&lt;p&gt;I just wanted to mention a great new site for programmers called &lt;a href="http://stackoverflow.com" target="_blank"&gt;Stack Overflow&lt;/a&gt; that just went into public beta.&lt;/p&gt;  &lt;p&gt;It's a mix of a technical question forum and a wiki, focused on software development and architecture, and has a few &amp;quot;hooks&amp;quot; that pull you in -- as you ask and answer questions, you get &amp;quot;reputation&amp;quot;, which unlocks more privileges (such as editing the wiki).&amp;#160; You also earn &amp;quot;badges&amp;quot; for doing things like asking a popular question or giving the best answer.&amp;#160; &lt;/p&gt;  &lt;p&gt;It ends up being really addictive and also valuable, people are rushing to provide the best answer the fastest to questions you ask, so if you have a focused technical question, it's a great way to get multiple answers fast.&amp;#160; I asked a question on Word 2007 automation, and had two great answers with code samples within 15 minutes.&lt;/p&gt;  &lt;p&gt;Anyhow, I say check it out.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6631016" width="1" height="1"&gt;</content><author><name>gstarbuck</name><uri>http://weblogs.asp.net/members/gstarbuck.aspx</uri></author></entry><entry><title>SQL 2005 Database Diagrams Error: "database does not have a valid owner"</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/guystarbuck/archive/2008/09/08/sql-2005-database-diagrams-error-quot-database-does-not-have-a-valid-owner-quot.aspx" /><id>http://weblogs.asp.net/guystarbuck/archive/2008/09/08/sql-2005-database-diagrams-error-quot-database-does-not-have-a-valid-owner-quot.aspx</id><published>2008-09-08T18:32:19Z</published><updated>2008-09-08T18:32:19Z</updated><content type="html">&lt;p&gt;Ok, I've been bitten by this twice now, so here is the error and solution:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;u&gt;Error:&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;TITLE: Microsoft SQL Server Management Studio   &lt;br /&gt;------------------------------ &lt;/p&gt;  &lt;p&gt;Database diagram support objects cannot be installed because this database does not have a valid owner.&amp;#160; To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;u&gt;Solution:&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;In my case, it's because my domain login is set as the database owner but I am working remotely.&amp;#160; My PC can't validate my login against the domain, so SQL Server errors out with &amp;quot;invalid owner&amp;quot;.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The easy solution is to change ownership of the database to sa, using sp_changedbowner.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6610244" width="1" height="1"&gt;</content><author><name>gstarbuck</name><uri>http://weblogs.asp.net/members/gstarbuck.aspx</uri></author></entry><entry><title>Footers and Replacement Counts in Word 2007 Search and Replace</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/guystarbuck/archive/2008/08/15/footers-and-replacement-counts-in-word-2007-search-and-replace.aspx" /><id>http://weblogs.asp.net/guystarbuck/archive/2008/08/15/footers-and-replacement-counts-in-word-2007-search-and-replace.aspx</id><published>2008-08-15T15:22:00Z</published><updated>2008-08-15T15:22:00Z</updated><content type="html">&lt;p&gt;I had a couple of great questions from &lt;a href="http://weblogs.asp.net/guystarbuck/archive/2008/05/13/automated-search-and-replace-in-multiple-word-2007-documents-with-c.aspx" target="_blank"&gt;my post on automated search-and-replace in Word documents&lt;/a&gt;:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h6&gt;&lt;em&gt;Hello&lt;/em&gt;&lt;/h6&gt;  &lt;p&gt;&lt;em&gt;&lt;font size="1"&gt;I just want to know what I have to change in order to search in the footer of the page only ?&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;&lt;font size="1"&gt;My goal is to update the version of a document which is written in the footer. I don't need to search in the core of the document.&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;&lt;font size="1"&gt;Thanks for your great code !&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;&lt;font size="1"&gt;Longin Benoit&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;There is an enumeration that determines the type of each Range, Microsoft.Office.Interop.Word.WdStoryType.&amp;#160; The values available that have to do with footers are:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;wdPrimaryFooterStory -- main footer story range &lt;/li&gt;    &lt;li&gt;wdFirstPageFooterStory -- override for the first page footer &lt;/li&gt;    &lt;li&gt;wdEvenPagesFooterStory -- override for even numbered pages (odd would inherit wdPrimaryFooterStory) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;So to run the code in my previous post for the wdPrimaryFooterStory, you could do something like this (omitting the setup and cleanup code):&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;// Get the primary footer range&lt;/span&gt;
Word.Range primaryFooterRange = doc.StoryRanges[Word.WdStoryType.wdPrimaryFooterStory];

&lt;span class="rem"&gt;// Set the find and replace text (I set a hard-coded token of &amp;quot;Document Version: 2.0&amp;quot; as the starting version,&lt;/span&gt;
&lt;span class="rem"&gt;// but this could be initialized to your previous version programmatically)&lt;/span&gt;
primaryFooterRange.Find.Text = &lt;span class="str"&gt;&amp;quot;Document Version: 2.0&amp;quot;&lt;/span&gt;;
primaryFooterRange.Find.Replacement.Text = &lt;span class="str"&gt;&amp;quot;Document Version: 2.1&amp;quot;&lt;/span&gt;;

&lt;span class="rem"&gt;// Set the option to wdReplace.wdReplaceOne (assuming you only have the version appearing once in the footer)&lt;/span&gt;
&lt;span class="kwrd"&gt;object&lt;/span&gt; replaceAll = Word.WdReplace.wdReplaceOne;
primaryFooterRange.Find.Execute(&lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing,
                                &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing,
                                &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; replaceAll,
                                &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing);&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Note that f you have differing alternating-page footers, you will have to run this twice, once on the wdPrimaryFooterStory, and a second time on the wdEvenPagesFooterStory.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Second Question: &lt;/p&gt;

&lt;p&gt;&lt;font size="1"&gt;I've improvised a little into your code as I need to implement an app&amp;#160; to find the occurence of a certain word . &lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="1"&gt;However I don't how to find the Occurence number !! &lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="1"&gt;That's my Code &lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="1"&gt;public void Search(Document docObj)&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="1"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="1"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; int Counter = 0;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="1"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; foreach (Range tmpRange in docObj.StoryRanges)&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="1"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="1"&gt;tmpRange.Find.Text = &amp;quot;Blob&amp;quot;;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="1"&gt;tmpRange.Find.Wrap = FindWrap.wdFindContinue;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="1"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Here should kind of property or method that should check if &amp;quot;Blob&amp;quot; 's been found then Counter++;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="1"&gt;}&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="1"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; System.Windows.Forms.MessageBox.Show(Counter.ToString());&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="1"&gt; }&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="1"&gt;Thanks .&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="1"&gt;Fatla &lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;This one is a little trickier -- I wasn't able to find any property after the &amp;quot;Find&amp;quot; that tells you how many were found.&amp;#160; I did find a good hack on this website where they suggest doing a count of characters before and after, divided by the difference in length of the two strings, to get a count of replacements (by Bart Verbeek and &lt;a href="http://word.mvps.org/AboutMVPs/dave_rado.htm"&gt;Dave Rado&lt;/a&gt;):&lt;/p&gt;

&lt;p&gt;&lt;a title="http://word.mvps.org/FAQs/MacrosVBA/GetNoOfReplacements.htm" href="http://word.mvps.org/FAQs/MacrosVBA/GetNoOfReplacements.htm"&gt;http://word.mvps.org/FAQs/MacrosVBA/GetNoOfReplacements.htm&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For situations where the search and replace strings are the same length, they suggest replacing with an additional &amp;quot;#&amp;quot; character, getting the count, and then doing another replace to strip out the &amp;quot;#&amp;quot;.&amp;#160; This seems like a lot of work, but I wasn't able to find anything in the API to do this, so it's probably a decent option if you abstract it into a method.&amp;#160; Anyone who has any other ideas, please let me know.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6523036" width="1" height="1"&gt;</content><author><name>gstarbuck</name><uri>http://weblogs.asp.net/members/gstarbuck.aspx</uri></author></entry><entry><title>A Few Links</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/guystarbuck/archive/2008/06/27/a-few-links.aspx" /><id>http://weblogs.asp.net/guystarbuck/archive/2008/06/27/a-few-links.aspx</id><published>2008-06-27T17:09:02Z</published><updated>2008-06-27T17:09:02Z</updated><content type="html">&lt;p&gt;&lt;a href="http://weblogs.asp.net/cumpsd/default.aspx" target="_blank"&gt;David Cumps&lt;/a&gt; has started a very nice series of posts on design patterns which I have been following -- well written and clear:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://weblogs.asp.net/cumpsd/archive/2008/06/25/6318835.aspx" target="_blank"&gt;Strategy Pattern&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://weblogs.asp.net/cumpsd/archive/2008/06/26/6324010.aspx" target="_blank"&gt;Observer Pattern&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://weblogs.asp.net/cumpsd/archive/2008/06/27/6327751.aspx" target="_blank"&gt;Observer/Event Pattern&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;A former coworker, &lt;a href="http://blog.magenic.com/blogs/daniels/default.aspx" target="_blank"&gt;Dan Sniderman&lt;/a&gt;, has published an article in &lt;a href="http://dotnet.sys-con.com/" target="_blank"&gt;Dot Net Developers Journal&lt;/a&gt; on Continuous Integration in TFS 2008 -- nice work Dan!&amp;#160; &lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6328117" width="1" height="1"&gt;</content><author><name>gstarbuck</name><uri>http://weblogs.asp.net/members/gstarbuck.aspx</uri></author></entry><entry><title>Automated Search and Replace in Word 2007 documents with C#</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/guystarbuck/archive/2008/05/13/automated-search-and-replace-in-multiple-word-2007-documents-with-c.aspx" /><id>http://weblogs.asp.net/guystarbuck/archive/2008/05/13/automated-search-and-replace-in-multiple-word-2007-documents-with-c.aspx</id><published>2008-05-14T03:34:10Z</published><updated>2008-05-14T03:34:10Z</updated><content type="html">&lt;p&gt;I worked on an interesting problem last night and thought I'd post the code.&amp;#160; I'm working on a software conversion project which has a new requirements/use case structure, and I had a list of about 700 requirement numbers that each needed to be replaced with a new requirement number, throughout 20 Word documents that averaged 20 pages apiece.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Going through each document and doing 700 &amp;quot;Replace Alls&amp;quot; didn't sound like much fun, and there are lots more documents and requirements coming down the pike that will need this same operation done to them, so I embarked on a VSTO expedition.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I created a console app in Visual Studio to run the code, and the first thing I noticed is that the Office 12 (Office 2007) Primary Interop Assemblies were not registered on my PC.&amp;#160; A quick search came up with &lt;a href="http://go.microsoft.com/fwlink/?LinkId=72637" target="_blank"&gt;this Microsoft download&lt;/a&gt; that lets you install these to your GAC with an MSI.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Next, I found a &lt;a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=372813&amp;amp;SiteID=1" target="_blank"&gt;great VB.Net code snippet&lt;/a&gt; in a Microsoft forum (it's the second post in the thread, from &amp;quot;Spotty&amp;quot;) that gives the basic code needed to do this for a single file.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I would say that if you are going to do a lot of interop work, it may be worthwhile to use VB.Net; the support for optional parameters saves a lot of time.&amp;#160; But my initial conversion of Spotty's VB code looks like this:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Spotty's original VB.Net code:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Dim&lt;/span&gt; word &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; Microsoft.Office.Interop.Word.Application
&lt;span class="kwrd"&gt;Dim&lt;/span&gt; doc &lt;span class="kwrd"&gt;As&lt;/span&gt; Microsoft.Office.Interop.Word.Document
&lt;span class="kwrd"&gt;Try&lt;/span&gt;
doc = word.Documents.Open(&lt;span class="str"&gt;&amp;quot;c:\test.doc&amp;quot;&lt;/span&gt;)
doc.Activate()
&lt;span class="kwrd"&gt;Dim&lt;/span&gt; myStoryRange &lt;span class="kwrd"&gt;As&lt;/span&gt; Microsoft.Office.Interop.Word.Range
&lt;span class="kwrd"&gt;For&lt;/span&gt; &lt;span class="kwrd"&gt;Each&lt;/span&gt; myStoryRange &lt;span class="kwrd"&gt;In&lt;/span&gt; doc.StoryRanges
&lt;span class="kwrd"&gt;With&lt;/span&gt; myStoryRange.Find
.Text = &lt;span class="str"&gt;&amp;quot;findme&amp;quot;&lt;/span&gt;
.Replacement.Text = &lt;span class="str"&gt;&amp;quot;findyou&amp;quot;&lt;/span&gt;
.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue
.Execute(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)
&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;With&lt;/span&gt;
&lt;span class="kwrd"&gt;Next&lt;/span&gt; myStoryRange
doc.SaveAs(&lt;span class="str"&gt;&amp;quot;c:\test1.doc&amp;quot;&lt;/span&gt;)
&lt;span class="kwrd"&gt;Catch&lt;/span&gt; ex &lt;span class="kwrd"&gt;As&lt;/span&gt; Exception
MessageBox.Show(&lt;span class="str"&gt;&amp;quot;Error accessing Word document.&amp;quot;&lt;/span&gt;)
&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Try&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;My conversion to C#:&lt;/p&gt;

&lt;p&gt;(note: add a reference to Microsoft.Office.Interop.Word (version 12) and the Using statement below)&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; Word = Microsoft.Office.Interop.Word;&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DoSearchAndReplaceInWord()
        {
            &lt;span class="rem"&gt;// Create the Word application and declare a document&lt;/span&gt;
            Word.Application word = &lt;span class="kwrd"&gt;new&lt;/span&gt; Word.Application();
            Word.Document doc = &lt;span class="kwrd"&gt;new&lt;/span&gt; Word.Document();

            &lt;span class="rem"&gt;// Define an object to pass to the API for missing parameters&lt;/span&gt;
            &lt;span class="kwrd"&gt;object&lt;/span&gt; missing = System.Type.Missing;

            &lt;span class="kwrd"&gt;try&lt;/span&gt;
            {
                &lt;span class="rem"&gt;// Everything that goes to the interop must be an object&lt;/span&gt;
                &lt;span class="kwrd"&gt;object&lt;/span&gt; fileName = &lt;span class="str"&gt;@&amp;quot;C:\myDocument.doc&amp;quot;&lt;/span&gt;;

                &lt;span class="rem"&gt;// Open the Word document.&lt;/span&gt;
                &lt;span class="rem"&gt;// Pass the &amp;quot;missing&amp;quot; object defined above to all optional&lt;/span&gt;
                &lt;span class="rem"&gt;// parameters.  All parameters must be of type object,&lt;/span&gt;
                &lt;span class="rem"&gt;// and passed by reference.&lt;/span&gt;
                doc = word.Documents.Open(&lt;span class="kwrd"&gt;ref&lt;/span&gt; fileName,
                    &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing,
                    &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing,
                    &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing,
                    &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing);

                &lt;span class="rem"&gt;// Activate the document&lt;/span&gt;
                doc.Activate();

                &lt;span class="rem"&gt;// Loop through the StoryRanges (sections of the Word doc)&lt;/span&gt;
                &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Word.Range tmpRange &lt;span class="kwrd"&gt;in&lt;/span&gt; doc.StoryRanges)
                {
                    &lt;span class="rem"&gt;// Set the text to find and replace&lt;/span&gt;
                    tmpRange.Find.Text = &lt;span class="str"&gt;&amp;quot;findme&amp;quot;&lt;/span&gt;;
                    tmpRange.Find.Replacement.Text = &lt;span class="str"&gt;&amp;quot;findyou&amp;quot;&lt;/span&gt;;

                    &lt;span class="rem"&gt;// Set the Find.Wrap property to continue (so it doesn't&lt;/span&gt;
                    &lt;span class="rem"&gt;// prompt the user or stop when it hits the end of&lt;/span&gt;
                    &lt;span class="rem"&gt;// the section)&lt;/span&gt;
                    tmpRange.Find.Wrap = Word.WdFindWrap.wdFindContinue;

                    &lt;span class="rem"&gt;// Declare an object to pass as a parameter that sets&lt;/span&gt;
                    &lt;span class="rem"&gt;// the Replace parameter to the &amp;quot;wdReplaceAll&amp;quot; enum&lt;/span&gt;
                    &lt;span class="kwrd"&gt;object&lt;/span&gt; replaceAll = Word.WdReplace.wdReplaceAll;

                    &lt;span class="rem"&gt;// Execute the Find and Replace -- notice that the&lt;/span&gt;
                    &lt;span class="rem"&gt;// 11th parameter is the &amp;quot;replaceAll&amp;quot; enum object&lt;/span&gt;
                    tmpRange.Find.Execute(&lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing,
                        &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing,
                        &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; replaceAll,
                        &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing);
                }

                &lt;span class="rem"&gt;// Save the changes&lt;/span&gt;
                doc.Save();

                &lt;span class="rem"&gt;// Close the doc and exit the app&lt;/span&gt;
                doc.Close(&lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing);
                word.Application.Quit(&lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing);
            }
            &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
            {
                doc.Close(&lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing);
                word.Application.Quit(&lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing, &lt;span class="kwrd"&gt;ref&lt;/span&gt; missing);
            }
        }&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;After this was up and running, setting up the data reader and looping though the directory to operate on all files was pretty straightforward -- the biggest tricks were declaring the &amp;quot;missing&amp;quot; object variable for Type.Missing, and adding the code to close the doc and exit the application.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;If you set up a VSTO project, you get the &amp;quot;missing&amp;quot; object declared as a global variable, so you don't need to declare it.&amp;#160; But for stand-alone Word interop, I think this is pretty clean.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6188093" width="1" height="1"&gt;</content><author><name>gstarbuck</name><uri>http://weblogs.asp.net/members/gstarbuck.aspx</uri></author></entry><entry><title>The Most Powerful Windows Keyboard Shortcut</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/guystarbuck/archive/2008/04/10/the-most-powerful-windows-keyboard-shortcut.aspx" /><id>http://weblogs.asp.net/guystarbuck/archive/2008/04/10/the-most-powerful-windows-keyboard-shortcut.aspx</id><published>2008-04-10T13:21:23Z</published><updated>2008-04-10T13:21:23Z</updated><content type="html">&lt;p&gt;Okay, so Ctl-C, Ctl-X and Ctl-V are really the most powerful, but at the patterns &amp;amp; practices summit in Redmond a couple of years ago, &lt;a href="http://www.peterprovost.org/"&gt;Peter Provost&lt;/a&gt; wowed the room with a keyboard shortcut that many of us had never seen before, and which I have used nearly every day since then.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;It's &lt;strong&gt;&lt;u&gt;Shift-Alt and the arrow keys&lt;/u&gt;&lt;/strong&gt;.&amp;#160; This lets you re-order text, bullets, or numbered lists.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;So if you have a bulleted list or numbered list in Word or PowerPoint that you need to re-sort, this is a no-brainer -- get the cursor on the row you want to move (or select multiple rows to move together), hold down Shift-Alt, and drive those rows around with the arrow keys.&amp;#160; Left and Right arrows indent or promote the text in the list.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;This also works for tables in Word and PowerPoint.&amp;#160; I've found it to be invaluable when doing BA work, it's a lot easier to re-organize bullets in presentations and outline numbered lists.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Give it a try!&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6082611" width="1" height="1"&gt;</content><author><name>gstarbuck</name><uri>http://weblogs.asp.net/members/gstarbuck.aspx</uri></author></entry><entry><title>.NET 2.0 WSDL DateTime Parsing Bug</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/guystarbuck/archive/2008/02/22/net-2-0-wsdl-datetime-parsing-bug.aspx" /><id>http://weblogs.asp.net/guystarbuck/archive/2008/02/22/net-2-0-wsdl-datetime-parsing-bug.aspx</id><published>2008-02-22T18:31:56Z</published><updated>2008-02-22T18:31:56Z</updated><content type="html">&lt;p&gt;I've built a wrapper application that abstracts Salesforce.com integration with our CRM, and came across a bit of an obscure bug yesterday.&lt;/p&gt;  &lt;p&gt;The issue came up when assigning a .NET DateTime value to a DateTime field in the generated SFDC proxy:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;font color="#80c9ff"&gt;SFDCObject__c&lt;/font&gt; _sfdcObject = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;font color="#80c9ff"&gt;SFDCObject__c&lt;/font&gt;();
_sfdcObject.Created_Date__c = DateTime.Now;
_sfdcObject.Created_Date__cSpecified = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;When assigning the .NET DateTime value to the _sfdcObject.Created_Date__c member, an error is thrown:&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ex = {&amp;quot;'2008-02-20' is not a valid value for the type xsd:dateTime&amp;quot;}&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;A bit of digging brought up &lt;a href="http://community.salesforce.com/sforce/board/message?board.id=NET_development&amp;amp;message.id=4069"&gt;this thread&lt;/a&gt; on the Salesforce.com developer discussion boards.&amp;#160; It turns out that the culprit is actually a bug in .NET 2.0 (quote is from the discussion thread):&lt;/p&gt;

&lt;p&gt;&lt;i&gt;If a schema contains both &amp;#8220;xsd:date&amp;#8221; with nillable=true and &amp;#8220;xsd:dateTime&amp;#8221; with nillable=true, we will import either both as &amp;#8220;date&amp;#8221; or both as &amp;#8220;dateTime&amp;#8221;. In your case, both probably get imported as &amp;#8220;date&amp;#8221;, hence the time component cases a failure. This is a known bug and there is a hotfix available (&lt;a href="http://support.microsoft.com/kb/925272"&gt;KB 925272&lt;/a&gt;), available by calling PSS.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt; The hotfix would need to be installed on all servers and dev machines, which seems like a non-optimal solution, so I went with the workaround of hand-modifying the WSDL to replace all instances of &amp;quot;xsd:date&amp;quot; with &amp;quot;xsd:dateTime&amp;quot;.&amp;#160; This worked for me because my application only needs to work with SFDC objects that are defined as &amp;quot;xsd:dateTime&amp;quot;.&amp;#160; If you have an app that needs to work with both xsd:date and xsd:dateTime typed fields, you will most likely need to install the hotfix from Microsoft, or move your solution to .NET 3.0 or 3.5.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5840759" width="1" height="1"&gt;</content><author><name>gstarbuck</name><uri>http://weblogs.asp.net/members/gstarbuck.aspx</uri></author></entry><entry><title>Invoking cmd.exe from .NET</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/guystarbuck/archive/2008/02/06/invoking-cmd-exe-from-net.aspx" /><id>http://weblogs.asp.net/guystarbuck/archive/2008/02/06/invoking-cmd-exe-from-net.aspx</id><published>2008-02-06T15:40:00Z</published><updated>2008-02-06T15:40:00Z</updated><content type="html">&lt;p&gt;One of the primary reasons I am writing this blog is to give back to the community -- technical blogs and message board archives have saved my bacon many times, so my plan is, whenever I spend an hour or two figuring something out and I wasn't able to find any concise resources about it, I'll write a post on it so that the next person may stumble across it and save some time.&lt;/p&gt;  &lt;p&gt;Yesterday I was working on calling cmd.exe from within .NET, and had to piece together a few things from various places.&amp;#160; Here is the code I ended up with.&amp;#160; I've added comments to explain the reason for each line of code -- hopefully someone will find this helpful.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Diagnostics;

&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Utilities
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Command
    {
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ExecuteCmd(&lt;span class="kwrd"&gt;string&lt;/span&gt; arguments)
        {
            &lt;span class="rem"&gt;// Create the Process Info object with the overloaded constructor&lt;/span&gt;
            &lt;span class="rem"&gt;// This takes in two parameters, the program to start and the&lt;/span&gt;
            &lt;span class="rem"&gt;// command line arguments.&lt;/span&gt;
            &lt;span class="rem"&gt;// The arguments parm is prefixed with &amp;quot;@&amp;quot; to eliminate the need&lt;/span&gt;
            &lt;span class="rem"&gt;// to escape special characters (i.e. backslashes) in the&lt;/span&gt;
            &lt;span class="rem"&gt;// arguments string and has &amp;quot;/C&amp;quot; prior to the command to tell&lt;/span&gt;
            &lt;span class="rem"&gt;// the process to execute the command quickly without feedback.&lt;/span&gt;
            ProcessStartInfo _info =
                &lt;span class="kwrd"&gt;new&lt;/span&gt; ProcessStartInfo(&lt;span class="str"&gt;&amp;quot;cmd&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;@&amp;quot;/C &amp;quot;&lt;/span&gt; + arguments);

            &lt;span class="rem"&gt;// The following commands are needed to redirect the&lt;/span&gt;
            &lt;span class="rem"&gt;// standard output.  This means that it will be redirected&lt;/span&gt;
            &lt;span class="rem"&gt;// to the Process.StandardOutput StreamReader.&lt;/span&gt;
            _info.RedirectStandardOutput = &lt;span class="kwrd"&gt;true&lt;/span&gt;;

            &lt;span class="rem"&gt;// Set UseShellExecute to false.  This tells the process to run&lt;/span&gt;
            &lt;span class="rem"&gt;// as a child of the invoking program, instead of on its own.&lt;/span&gt;
            &lt;span class="rem"&gt;// This allows us to intercept and redirect the standard output.&lt;/span&gt;
            _info.UseShellExecute = &lt;span class="kwrd"&gt;false&lt;/span&gt;;

            &lt;span class="rem"&gt;// Set CreateNoWindow to true, to supress the creation of&lt;/span&gt;
            &lt;span class="rem"&gt;// a new window&lt;/span&gt;
            _info.CreateNoWindow = &lt;span class="kwrd"&gt;true&lt;/span&gt;;

            &lt;span class="rem"&gt;// Create a process, assign its ProcessStartInfo and start it&lt;/span&gt;
            Process _p = &lt;span class="kwrd"&gt;new&lt;/span&gt; Process();
            _p.StartInfo = _info;
            _p.Start();

            &lt;span class="rem"&gt;// Capture the results in a string&lt;/span&gt;
            &lt;span class="kwrd"&gt;string&lt;/span&gt; _processResults = _p.StandardOutput.ReadToEnd();

            &lt;span class="rem"&gt;// Close the process to release system resources&lt;/span&gt;
            _p.Close();

            &lt;span class="rem"&gt;// Return the output stream to the caller&lt;/span&gt;
            &lt;span class="kwrd"&gt;return&lt;/span&gt; _processResults;
        }
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&lt;span style="font-family: consolas; mso-bidi-font-family: " times="times" new="new" roman?;="roman?;" mso-no-proof:="mso-no-proof:" yes?="yes?"&gt;&amp;#160;&lt;/span&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5723247" width="1" height="1"&gt;</content><author><name>gstarbuck</name><uri>http://weblogs.asp.net/members/gstarbuck.aspx</uri></author></entry><entry><title>SSIS Flat File Export - "Fixed Width" vs "Ragged Right"</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/guystarbuck/archive/2008/01/31/ssis-flat-file-export-quot-fixed-width-quot-vs-quot-ragged-right-quot.aspx" /><id>http://weblogs.asp.net/guystarbuck/archive/2008/01/31/ssis-flat-file-export-quot-fixed-width-quot-vs-quot-ragged-right-quot.aspx</id><published>2008-01-31T16:36:12Z</published><updated>2008-01-31T16:36:12Z</updated><content type="html">&lt;p&gt;Back in the late 90s, I worked on a number of projects where we had to generate fixed width flat files to send to external systems -- we would use the SQL Server DTS wizard to generate them, and everything worked fine.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I recently needed to generate fixed width flat files from SQL Server 2005, so I ran SSIS and everything looks pretty much the same as DTS -- except when choosing &amp;quot;Fixed Width&amp;quot; as the export option, the entire flat file was generated with no linefeeds/carriage returns in it.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;It turns out there is another option, &amp;quot;&lt;strong&gt;Ragged Right&lt;/strong&gt;&amp;quot;, which is exactly the same as &amp;quot;Fixed Width&amp;quot;, except that it gives you the option to insert a linefeed character (or CRLF, etc.) at the end of each line of data.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Here's a quick walkthrough for generating fixed width flat files with line breaks from SSIS.&amp;#160; For this example, I'm assuming that we'll be selecting data &amp;quot;as-is&amp;quot; from a staging table that is already set up with the correct column widths and contains data exactly as it should be in the fixed width file.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;1) In SQL Server Management Studio, right click on the database containing the table or data you want to export, and select &amp;quot;Tasks/Export Data...&amp;quot;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/guystarbuck/WindowsLiveWriter/SSISFlatFileExportFixedWidthvsRaggedRigh_950D/image_2.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="60" alt="image" src="http://weblogs.asp.net/blogs/guystarbuck/WindowsLiveWriter/SSISFlatFileExportFixedWidthvsRaggedRigh_950D/image_thumb.png" width="283" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;2) For the data source, you can leave the default settings.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/guystarbuck/WindowsLiveWriter/SSISFlatFileExportFixedWidthvsRaggedRigh_950D/image_4.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="279" alt="image" src="http://weblogs.asp.net/blogs/guystarbuck/WindowsLiveWriter/SSISFlatFileExportFixedWidthvsRaggedRigh_950D/image_thumb_1.png" width="295" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;3) For the target, select &amp;quot;Flat File Destination&amp;quot; as the Destination, pick a file name, and under &amp;quot;Format&amp;quot;, select &amp;quot;&lt;strong&gt;Ragged right&lt;/strong&gt;&amp;quot;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/guystarbuck/WindowsLiveWriter/SSISFlatFileExportFixedWidthvsRaggedRigh_950D/image_6.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="281" alt="image" src="http://weblogs.asp.net/blogs/guystarbuck/WindowsLiveWriter/SSISFlatFileExportFixedWidthvsRaggedRigh_950D/image_thumb_2.png" width="297" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;4) Click through the next dialog, which gives you the option to specify a query or just select straight from a table.&amp;#160; We're going to select from a table here.&amp;#160; On the &amp;quot;Configure Flat File Destination&amp;quot; screen, pick the table you want to export, and choose the row delimiter.&amp;#160; The default is &amp;quot;CRLF&amp;quot;, which is generally good for windows, but if you are sending the file to be processed on another OS or for a specific app, you may need to choose a different linefeed character or sequence.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/guystarbuck/WindowsLiveWriter/SSISFlatFileExportFixedWidthvsRaggedRigh_950D/image_10.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="279" alt="image" src="http://weblogs.asp.net/blogs/guystarbuck/WindowsLiveWriter/SSISFlatFileExportFixedWidthvsRaggedRigh_950D/image_thumb_4.png" width="295" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;That's it!&amp;#160; Execute the package or save it off, and you should have a fixed width flat file with linefeeds.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5682603" width="1" height="1"&gt;</content><author><name>gstarbuck</name><uri>http://weblogs.asp.net/members/gstarbuck.aspx</uri></author></entry></feed>
