<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dotnet thoughts &#187; Windows Forms</title>
	<atom:link href="http://www.dotnetthoughts.net/category/windows-forms/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetthoughts.net</link>
	<description>a dotnet developer&#039;s technical blog</description>
	<lastBuildDate>Wed, 08 Feb 2012 03:18:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Drive combo box in C#</title>
		<link>http://www.dotnetthoughts.net/2012/02/07/drive-combo-box-in-c/</link>
		<comments>http://www.dotnetthoughts.net/2012/02/07/drive-combo-box-in-c/#comments</comments>
		<pubDate>Wed, 08 Feb 2012 03:18:03 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[Win 32 API]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Drive Combobox]]></category>
		<category><![CDATA[SHGetFileInfo]]></category>
		<category><![CDATA[WIN32 API]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=2361</guid>
		<description><![CDATA[As most of the .Net developers, I am also started my development career with VB6. VB6 comes with few file system controls, like DriveListbox, DirectoryListbox, FileListbox etc. But in .Net framework didn&#8217;t support these controls. Here is a solution for &#8230; <a href="http://www.dotnetthoughts.net/2012/02/07/drive-combo-box-in-c/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As most of the .Net developers, I am also started my development career with VB6. <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  VB6 comes with few file system controls, like DriveListbox, DirectoryListbox, FileListbox etc. But in .Net framework didn&#8217;t support these controls. Here is a solution for creating a drive listbox(it is not a listbox, it is dropdown list).</p>
<div id="attachment_2362" class="wp-caption aligncenter" style="width: 473px"><img class="size-full wp-image-2362" title="Drive Combo box in C#" src="http://www.dotnetthoughts.net/wp-content/uploads/2012/02/drivecombo.jpg" alt="Drive Combo box in C#" width="463" height="169" /><p class="wp-caption-text">Drive Combo box in C#</p></div>
<p>The drive information can be retrieved using DriveInfo.GetDrives() method. And for getting the corresponding icons for drive letters, I am using the SHGetFileInfo WIN32 API call.</p>
<p>Here is the implementation.</p>
<pre class="brush: csharp; title: ; notranslate">
private void Form1_Load(object sender, EventArgs e)
{
    comboBox1.DrawMode = DrawMode.OwnerDrawFixed;
    comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
    comboBox1.DrawItem += new DrawItemEventHandler(comboBox1_DrawItem);

    var drives = DriveInfo.GetDrives()
        .Where(drive =&gt; drive.Name != string.Empty).ToArray();
    comboBox1.Items.AddRange(drives);
}
</pre>
<p>And here is the DrawItem event</p>
<pre class="brush: csharp; title: ; notranslate">
private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
    if (e.Index != -1)
    {
        e.DrawBackground();
        var icon = GetIcon(comboBox1.Items[e.Index].ToString());
        e.Graphics.DrawIcon(icon, 3, e.Bounds.Top);
        e.Graphics.DrawString(comboBox1.Items[e.Index].ToString(),
            comboBox1.Font, Brushes.Black, icon.Width + 2, e.Bounds.Top);
        e.DrawFocusRectangle();
    }
}
</pre>
<p>And here is the GetIcon method and API declaration.</p>
<pre class="brush: csharp; title: ; notranslate">
private const uint SHGFI_ICON = 0x100;
private const uint SHGFI_LARGEICON = 0x0;
private const uint SHGFI_SMALLICON = 0x1;

[DllImport(&quot;shell32.dll&quot;)]
private static extern IntPtr SHGetFileInfo(string pszPath,
                            uint dwFileAttributes,
                            ref SHFILEINFO psfi,
                            uint cbSizeFileInfo,
                            uint uFlags);
[StructLayout(LayoutKind.Sequential)]
private struct SHFILEINFO
{
    public IntPtr hIcon;
    public IntPtr iIcon;
    public uint dwAttributes;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
    public string szDisplayName;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
    public string szTypeName;
};

private Icon GetIcon(string fileName)
{
    IntPtr hImgSmall;
    SHFILEINFO shinfo = new SHFILEINFO();
    hImgSmall = SHGetFileInfo(fileName, 0, ref shinfo,
                (uint)Marshal.SizeOf(shinfo),
                    SHGFI_ICON |
                    SHGFI_SMALLICON);
    return Icon.FromHandle(shinfo.hIcon);
}
</pre>
<p>This implementation is using normal Combobox, you can do same thing by extending Combobox. So that it can be used in any project without any dependency.</p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2010/09/26/how-to-make-a-form-stay-always-on-top/" title="Permanent link to How to make a form stay always on top">How to make a form stay always on top</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/06/30/how-to-use-taskdialog-api-in-c/" title="Permanent link to How to use TaskDialog API in C#">How to use TaskDialog API in C#</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/12/25/setting-an-application-on-top-other-windows-using-c/" title="Permanent link to Setting an application on top other windows using C#">Setting an application on top other windows using C#</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2007/04/17/font-enumeration-in-vbnet/" title="Permanent link to Font Enumeration in VB.Net">Font Enumeration in VB.Net</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/08/25/how-to-disable-close-button-of-windows-forms-application/" title="Permanent link to How to disable Close button of Windows Forms Application">How to disable Close button of Windows Forms Application</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2012/02/07/drive-combo-box-in-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to debug Windows Live Writer plugins</title>
		<link>http://www.dotnetthoughts.net/2011/11/20/how-to-debug-windows-live-writer-plugins/</link>
		<comments>http://www.dotnetthoughts.net/2011/11/20/how-to-debug-windows-live-writer-plugins/#comments</comments>
		<pubDate>Sun, 20 Nov 2011 09:29:07 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Live Writer Plugin]]></category>
		<category><![CDATA[Windows Live Writer]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=2042</guid>
		<description><![CDATA[This is final post related to live writer plugins and its about debugging the Live writer plugins. While developing I don&#8217;t think there is a way we can debug the plugin code. This is after deployment. Initially I faced one &#8230; <a href="http://www.dotnetthoughts.net/2011/11/20/how-to-debug-windows-live-writer-plugins/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">This is final post related to live writer plugins and its about debugging the Live writer plugins. While developing I don&#8217;t think there is a way we can debug the plugin code. This is after deployment. Initially I faced one issue with options dialog, it was related to object reference issue, I got a message like this.</p>
<div id="attachment_2044" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/plugin_settings_error.jpg"><img class="size-medium wp-image-2044" title="Plug-in Error occured - Messagebox from Windows Live Writer" src="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/plugin_settings_error-300x197.jpg" alt="Plug-in Error occured - Messagebox from Windows Live Writer" width="300" height="197" /></a><p class="wp-caption-text">Plug-in Error occured - Messagebox from Windows Live Writer</p></div>
<p style="text-align: justify;">It only shows the exception message, not the stack trace or any other information which helps to find the exception. For debugging, you need to attach the Windows Live writer to Visual Studio(we may need to run visual studio as Administrator) using Attach Process feature of Visual Studio from Debug menu.</p>
<div id="attachment_2043" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/attachprocess.jpg"><img class="size-medium wp-image-2043" title="Attach Windows Live Writer to Visual Studio" src="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/attachprocess-300x190.jpg" alt="Attach Windows Live Writer to Visual Studio" width="300" height="190" /></a><p class="wp-caption-text">Attach Windows Live Writer to Visual Studio</p></div>
<p>Happy Programming.</p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2011/11/16/how-to-create-a-windows-live-writer-plugin-using-c-part-1/" title="Permanent link to How to create a Windows Live writer plugin using C# Part 1">How to create a Windows Live writer plugin using C# Part 1</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/11/19/how-to-create-a-windows-live-writer-plugin-using-c-part-2/" title="Permanent link to How to create a Windows Live writer plugin using C# Part 2">How to create a Windows Live writer plugin using C# Part 2</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/08/03/windows-7-sdk-installation-success-or-error-status-1603/" title="Permanent link to Windows 7 SDK Installation success or error status: 1603">Windows 7 SDK Installation success or error status: 1603</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/06/02/how-to-integrate-fxcop-to-visual-studio-2010-professional/" title="Permanent link to How to integrate FxCop to Visual Studio 2010 Professional">How to integrate FxCop to Visual Studio 2010 Professional</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2012/02/05/fuslogvw-exe-and-diagnosing-net-assembly-binding-issues/" title="Permanent link to Fuslogvw.exe and diagnosing .NET assembly binding issues">Fuslogvw.exe and diagnosing .NET assembly binding issues</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2011/11/20/how-to-debug-windows-live-writer-plugins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create a Windows Live writer plugin using C# Part 2</title>
		<link>http://www.dotnetthoughts.net/2011/11/19/how-to-create-a-windows-live-writer-plugin-using-c-part-2/</link>
		<comments>http://www.dotnetthoughts.net/2011/11/19/how-to-create-a-windows-live-writer-plugin-using-c-part-2/#comments</comments>
		<pubDate>Sat, 19 Nov 2011 18:43:12 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Link Shortner]]></category>
		<category><![CDATA[Live Writer Plugin]]></category>
		<category><![CDATA[Windows Live Writer]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=2030</guid>
		<description><![CDATA[This is the second part of live writer plugin post, in this post I am implementing settings for the live writer plugin. First post I was about creating basic Live writer which help to short link using bit.ly shortening service. &#8230; <a href="http://www.dotnetthoughts.net/2011/11/19/how-to-create-a-windows-live-writer-plugin-using-c-part-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is the second part of live writer plugin post, in this post I am implementing settings for the live writer plugin. <a href="http://www.dotnetthoughts.net/2011/11/16/how-to-create-a-windows-live-writer-plugin-using-c-part-1/" title="How to create a Windows Live writer plugin using C# Part 1">First post</a> I was about creating basic Live writer which help to short link using bit.ly shortening service. Now I am adding a few more link shortening services like tiny.cc and tinyurl. Also I am providing an option which helps to decide whether the link should open in a new Window or not, or more precisely adding a target=&#8221;blank&#8221; attribute to the inserted anchor tag.</p>
<p>First we need to inform Live Writer that the plugin has settings, which can be done using HasEditableOptions=true in plugin attributes. Now we will create the settings form, which will be like the following.</p>
<div id="attachment_2032" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/settings_design_view.jpg"><img class="size-medium wp-image-2032" title="Plugin settings - Design View" src="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/settings_design_view-300x135.jpg" alt="Plugin settings - Design View" width="300" height="135" /></a><p class="wp-caption-text">Plugin settings - Design View</p></div>
<p>Live writer will invoke the EditOptions method in the Plugin class for displaying the settings, so we need to override the method for displaying the form.</p>
<pre class="brush: csharp; title: ; notranslate">
public override void EditOptions(IWin32Window dialogOwner)
{
    Settings settings = new Settings(_pluginSettings);
    settings.ShowDialog();
}
</pre>
<p>For implementing plugin settings we can use IProperties, which helps plugin to read/write the settings. The Live writer understands the basic types, like string, int, float, bool and decimal. IProperties exposes methods to get and set the values. Like this</p>
<pre class="brush: csharp; title: ; notranslate">
private IProperties _properties;
public bool UseBlank
{
    get
    {
        return _properties.GetBoolean(&quot;UseBlank&quot;, true);
    }
    set
    {
        _properties.SetBoolean(&quot;UseBlank&quot;, value);
    }
}
</pre>
<p>To save and retrieve the setting the following methods of IProperties class can be used.</p>
<pre class="brush: csharp; title: ; notranslate">
private PluginSettings _settings;
private void cmdSave_Click(object sender, EventArgs e)
{
	_settings.UseBlank = chkBlankTarget.Checked;
	_settings.Provider = ddlProvider.SelectedItem.ToString();
	Close();
}
//Constructor of the Settings Form.
public Settings(PluginSettings settings)
{
    InitializeComponent();
    _settings = settings;
    chkBlankTarget.Checked = _settings.UseBlank;
	ddlProvider.SelectedItem = _settings.Provider;
}
</pre>
<p>For accessing settings in the Plugin, we need to override the Initialize() method of the Plugin class, which takes the IProperties as parameter, LiveWriter will invoke the plugin with the settings.</p>
<pre class="brush: csharp; title: ; notranslate">
private PluginSettings _pluginSettings;
public override void Initialize(IProperties pluginOptions)
{
    base.Initialize(pluginOptions);
    _pluginSettings = new PluginSettings(pluginOptions);
}
</pre>
<p>Build the project, launch the Windows Live Writer, click on the Plugin options, which will show the Plugin options dialog.</p>
<div id="attachment_2031" class="wp-caption aligncenter" style="width: 282px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/plugin_options.jpg"><img class="size-medium wp-image-2031" title="Live Writer - Plugin Options" src="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/plugin_options-272x300.jpg" alt="Live Writer - Plugin Options" width="272" height="300" /></a><p class="wp-caption-text">Live Writer - Plugin Options</p></div>
<p>Next select Link shortener plugin and click on Options button, which will display the plugin settings dialog we designed.</p>
<div id="attachment_2033" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/shortner_settings.jpg"><img class="size-medium wp-image-2033" title="Live writer Plugin - Settings" src="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/shortner_settings-300x133.jpg" alt="Live writer Plugin - Settings" width="300" height="133" /></a><p class="wp-caption-text">Live writer Plugin - Settings</p></div>
<p>Change the settings and Save the changes, try run the plugin and verify the results.</p>
<p>Happy Programming. Next post will be about debugging Live writer plugin.</p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2011/11/16/how-to-create-a-windows-live-writer-plugin-using-c-part-1/" title="Permanent link to How to create a Windows Live writer plugin using C# Part 1">How to create a Windows Live writer plugin using C# Part 1</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/11/20/how-to-debug-windows-live-writer-plugins/" title="Permanent link to How to debug Windows Live Writer plugins">How to debug Windows Live Writer plugins</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2008/06/04/ghost-doc-document-this/" title="Permanent link to GhostDoc &#8211; Document this">GhostDoc &#8211; Document this</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/10/29/test-impact-analysis-in-visual-studio-2010/" title="Permanent link to Test impact analysis in Visual Studio 2010">Test impact analysis in Visual Studio 2010</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/10/05/developing-a-single-instance-application-in-c/" title="Permanent link to Developing a Single Instance Application in C#">Developing a Single Instance Application in C#</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2011/11/19/how-to-create-a-windows-live-writer-plugin-using-c-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create a Windows Live writer plugin using C# Part 1</title>
		<link>http://www.dotnetthoughts.net/2011/11/16/how-to-create-a-windows-live-writer-plugin-using-c-part-1/</link>
		<comments>http://www.dotnetthoughts.net/2011/11/16/how-to-create-a-windows-live-writer-plugin-using-c-part-1/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 17:16:56 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Link Shortner]]></category>
		<category><![CDATA[Live Writer Plugin]]></category>
		<category><![CDATA[Windows Live Writer]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=1991</guid>
		<description><![CDATA[Recently I got chance to explore Windows Live Writer. So I thought I will create few posts around Live Writer plugins. In this post I am covering the basics of creating Live Writer plugin. I found various plugins which helps &#8230; <a href="http://www.dotnetthoughts.net/2011/11/16/how-to-create-a-windows-live-writer-plugin-using-c-part-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Recently I got chance to explore Windows Live Writer. So I thought I will create few posts around Live Writer plugins. In this post I am covering the basics of creating Live Writer plugin. I found various plugins which helps to insert syntax highlighting code in wordpress. So I thought I will create one different, this plugin helps to insert a shorten link using bit.ly site.</p>
<p style="text-align: justify;">So first create a class library, make sure you are selecting the target framework as .Net 2.0, otherwise it may not work. The add refernce of Live Writer API(WindowsLive.Writer.Api.dll), which will be available in C:\Program Files (x86)\Windows Live\Writer. Inherit from ContentSource class or SmartContentSource class. In this post I am using ContentSource class, both of them can be used to create the Plugin. Override the CreateContent method, this method will be invoked when users click on the Plugin in LiveWriter. Create a Windows Form, with one textbox and two buttons.</p>
<div id="attachment_1993" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/dotnetthoughts_1.png"><img class="size-medium wp-image-1993" title="Link shortner - Windows Form Design View" src="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/dotnetthoughts_1-300x95.png" alt="Link shortner - Windows Form Design View" width="300" height="95" /></a><p class="wp-caption-text">Link shortner - Windows Form Design View</p></div>
<p>And add following attributes to the plugin class which helps live writer to identify the Plugin properties.</p>
<pre class="brush: csharp; title: ; notranslate">
[InsertableContentSource(&quot;Link shortner&quot;)]
[WriterPlugin(&quot;9E560094-F1BA-433D-9FB7-4DEA9A4C3F2F&quot;,
	&quot;Link shortner&quot;,
	PublisherUrl = &quot;www.dotnetthoughts.net&quot;,
	Description = &quot;Helps to insert shorten links.&quot;,
	HasEditableOptions = false,
	ImagePath = &quot;wlwicon.png&quot;)]
public class LinkShortner : ContentSource
{
}
</pre>
<p style="text-align: justify;">HasEditableOptions parameter, helps to provide settings for the live writer plugin. And the ImagePath parameter helps to provide Icon for the plugin. The size should be 16&#215;16. And it should added and Build action should be Embedded Resource.</p>
<p>And here is the overriden CreateContent() method.</p>
<pre class="brush: csharp; title: ; notranslate">
public override DialogResult CreateContent(IWin32Window dialogOwner, ref string content)
{
    using (Editor editor = new Editor())
    {
        editor.StartPosition = FormStartPosition.CenterParent;
        DialogResult result = editor.ShowDialog(dialogOwner);
        if (result == DialogResult.OK)
        {
			//This function will convert long
			//url to short url using bit.ly REST API.
			//Editor.Url property returns the
			//text of the textbox control.
			string resultUrl = CreateShortUrl(editor.Url);
			string url = string.Format
				(&quot;&lt;a href=&quot;\&quot;http://{0}/\&quot;&quot;&gt;{0}&lt;/a&gt;&quot;, resultUrl);
            content = url;
        }
        return result;
    }
}
</pre>
<p style="text-align: justify;">Thats it. We are done with the creation of live writer plugin. Now the next part is deployment. Change the project output path to C:\Program Files (x86)\Windows Live\Writer\Plugins location, you may need to run Visual Studio as Administrator. Now launch the Windows Live Writer, you can see the plugin loaded <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<div id="attachment_1994" class="wp-caption aligncenter" style="width: 248px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/dotnetthoughts_2.png"><img class="size-full wp-image-1994" title="Link Shortner - Windows Live Writer Plugin" src="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/dotnetthoughts_2.png" alt="Link Shortner - Windows Live Writer Plugin" width="238" height="94" /></a><p class="wp-caption-text">Link Shortner - Windows Live Writer Plugin</p></div>
<p>Clicking on it will popup the Windows form, with textbox, and clicking on Shorten button will insert a link on the post.</p>
<div id="attachment_1995" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/dotnetthoughts_3.png"><img class="size-medium wp-image-1995" title="Link shortner in Windows Live writer - Running" src="http://www.dotnetthoughts.net/wp-content/uploads/2011/11/dotnetthoughts_3-300x86.png" alt="Link shortner in Windows Live writer - Running" width="300" height="86" /></a><p class="wp-caption-text">Link shortner in Windows Live writer - Running</p></div>
<p>Next part I will post about how to create settings for plugin. Happy Blogging <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2011/11/19/how-to-create-a-windows-live-writer-plugin-using-c-part-2/" title="Permanent link to How to create a Windows Live writer plugin using C# Part 2">How to create a Windows Live writer plugin using C# Part 2</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/11/20/how-to-debug-windows-live-writer-plugins/" title="Permanent link to How to debug Windows Live Writer plugins">How to debug Windows Live Writer plugins</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/10/11/silverlight-in-sharepoint-wss-3-0/" title="Permanent link to Silverlight in Sharepoint (WSS 3.0)">Silverlight in Sharepoint (WSS 3.0)</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/10/09/creating-a-webpart-using-visual-web-developer-express/" title="Permanent link to Creating a WebPart using Visual Web Developer Express">Creating a WebPart using Visual Web Developer Express</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/11/26/how-to-upload-file-using-httpwebrequest-class/" title="Permanent link to How to upload file using HttpWebRequest class">How to upload file using HttpWebRequest class</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2011/11/16/how-to-create-a-windows-live-writer-plugin-using-c-part-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How redirect output from a console application</title>
		<link>http://www.dotnetthoughts.net/2011/11/12/how-redirect-output-from-a-console-application/</link>
		<comments>http://www.dotnetthoughts.net/2011/11/12/how-redirect-output-from-a-console-application/#comments</comments>
		<pubDate>Sat, 12 Nov 2011 10:46:28 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Commandline]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=1969</guid>
		<description><![CDATA[GUI tools are offers better User experience than command line tools. But in few scenarios we don’t require GUI, like MS Build tasks, and in some cases the application may not have a UI, example: ImageMagik tools. If check codeplex.com, &#8230; <a href="http://www.dotnetthoughts.net/2011/11/12/how-redirect-output-from-a-console-application/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">GUI tools are offers better User experience than command line tools. But in few scenarios we don’t require GUI, like MS Build tasks, and in some cases the application may not have a UI, example: ImageMagik tools. If check codeplex.com, you can find n number of applications, which doesn&#8217;t have a UI.</p>
<p style="text-align: justify;">The process class supports redirection of output, error and input to streams instead of normal console output stream. Process class also supports events, which will be raised on error or output data received.</p>
<p style="text-align: justify;">And here is the implementation, which invokes the regasm.exe in .Net Framework location, and executes regasm.exe without any command line argument, which will write the help text to the Text box.</p>
<pre class="brush: csharp; title: ; notranslate">
string app = @&quot;C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe&quot;;
Process process = Process.Start(app);

process.EnableRaisingEvents = true;
process.OutputDataReceived += (o, dre) =&gt;
{
    //To avoid cross thread exceptions.
    if (txtOutput.InvokeRequired)
    {
        this.txtOutput.BeginInvoke((Action)
            delegate { this.txtOutput.Text += dre.Data + Environment.NewLine; });
    }
    else
    {
        this.txtOutput.Text += dre.Data + Environment.NewLine;
    }
};
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.UseShellExecute = false;
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
</pre>
<p style="text-align: justify;">The external tools option in Visual Studio works in similar fashion. You can use this technique for creating user interface for command line tools you use frequently.</p>
<p>Happy coding <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2010/12/25/setting-an-application-on-top-other-windows-using-c/" title="Permanent link to Setting an application on top other windows using C#">Setting an application on top other windows using C#</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/12/10/process-start-and-directory-setcurrentdirectory/" title="Permanent link to Process.Start() and Directory.SetCurrentDirectory()">Process.Start() and Directory.SetCurrentDirectory()</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/11/25/raven-db-introduction/" title="Permanent link to Raven DB &#8211; Introduction">Raven DB &#8211; Introduction</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2012/01/11/how-to-use-net-assembly-in-vbscript/" title="Permanent link to How to use .Net assembly in VBScript">How to use .Net assembly in VBScript</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/10/05/developing-a-single-instance-application-in-c/" title="Permanent link to Developing a Single Instance Application in C#">Developing a Single Instance Application in C#</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2011/11/12/how-redirect-output-from-a-console-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

