<?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>Huddled Masses &#187; CSharp</title>
	<atom:link href="http://huddledmasses.org/tag/csharp/feed/" rel="self" type="application/rss+xml" />
	<link>http://huddledmasses.org</link>
	<description>You can do more than breathe for free...</description>
	<lastBuildDate>Sat, 28 Jan 2012 21:37:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<cloud domain='huddledmasses.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>Clip.exe and the missing Paste.exe</title>
		<link>http://huddledmasses.org/clipexe-and-the-missing-pasteexe/</link>
		<comments>http://huddledmasses.org/clipexe-and-the-missing-pasteexe/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 16:13:23 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Clipboard]]></category>
		<category><![CDATA[Command Line]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Threading]]></category>
		<category><![CDATA[Utilities]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=783</guid>
		<description><![CDATA[One of the guys on #PowerShell in IRC was asking about how to get the contents of the clipboard in PowerShell, and after we had tried several different scripts, we realized that in Version 1, because PowerShell runs in an MTA thread, you cannot access the clipboard without creating a new thread (in STA mode). [...]]]></description>
			<content:encoded><![CDATA[	<p>One of the guys on <a href="irc://irc.freenode.net/PowerShell">#PowerShell in IRC</a> was asking about how to <strong>get</strong> the contents of the clipboard in PowerShell, and after we had tried several different scripts, we realized that in Version 1, because PowerShell runs in an <a href="http://support.microsoft.com/kb/150777"><span class="caps">MTA</span> thread</a>, you cannot access the clipboard without creating a new thread (in <span class="caps">STA</span> mode).  After I got done ranting, and pointing out that everyone needs to use PowerShell v2 (yeah, it&#8217;s still in <span class="caps">CTP</span>, so I was mostly kidding) in <a href="http://support.microsoft.com/kb/150777">-STA</a> mode &#8230; I whipped together the C# one liner and stuck it into a class with instructions for compiling, and figured I might as well share.</p>

	<p>The code is <a href="clipexe-and-the-missing-pasteexe#more-783">below</a>. There are two files: Clip.cs and Paste.cs &#8230; you probably only need Paste.cs, because Clip.exe is <a href="http://weblogs.asp.net/owscott/archive/2006/12/15/clip-saving-command-line-and-powershell-output-directly-to-the-clipboard.aspx">already included</a> in Windows <em>after</em> Windows XP, but for the sake of completeness (and because it was just a few lines), I wrote them both.</p>

	<p>To use them, you must compile them using <code>Csc.exe</code>, which is included as part of the .Net Framework.  If it&#8217;s not already on your path, it&#8217;s in the folder for your most recent .Net Framework version (eg: C:\WINDOWS\Microsoft.NET\Framework\v3.5\csc.exe  or C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe). All you have to do is run: <code>csc Paste.cs</code> and <code>csc Clip.cs</code> and you should end up with a <code>Paste.exe</code> and <code>Clip.exe</code> which you can use to copy and paste from the command-line&#8230; <span id="more-783"></span></p>

	<h3>Paste.cs</h3>

	<div class="csharp code csharp" style="font-family:monospace;"><br />
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Windows.Forms</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Threading</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #0600FF;">namespace</span> Huddled <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Paste <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>STAThread<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args <span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0600FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> line <span style="color: #0600FF;">in</span> Clipboard.<span style="color: #0000FF;">GetText</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Split</span><span style="color: #000000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#123;</span><span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\r</span><span style="color: #008080; font-weight: bold;">\n</span>&quot;</span>,<span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\n</span>&quot;</span><span style="color: #000000;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StringSplitOptions.<span style="color: #0000FF;">None</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span> line <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div>

	<h3>Clip.cs</h3>

	<div class="csharp code csharp" style="font-family:monospace;"><br />
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Windows.Forms</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Threading</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #0600FF;">namespace</span> Huddled <span style="color: #000000;">&#123;</span><br />
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Clip <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000000;">&#91;</span>STAThread<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp;<span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args <span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">string</span> s<span style="color: #008000;">;</span> <br />
&nbsp; &nbsp; &nbsp; StringBuilder output <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> StringBuilder<span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Join</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot; &quot;</span>, args<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>s <span style="color: #008000;">=</span> Console.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;output.<span style="color: #0000FF;">AppendLine</span><span style="color: #000000;">&#40;</span>s<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; Clipboard.<span style="color: #0000FF;">SetText</span><span style="color: #000000;">&#40;</span> output.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/clipexe-and-the-missing-pasteexe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visual Studio 2008</title>
		<link>http://huddledmasses.org/visual-studio-2008/</link>
		<comments>http://huddledmasses.org/visual-studio-2008/#comments</comments>
		<pubDate>Sat, 24 Nov 2007 02:51:50 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[VS2008]]></category>

		<guid isPermaLink="false">http://HuddledMasses.org/visual-studio-2008/</guid>
		<description><![CDATA[Well, Visual Studio 2008 launched while I was off in Houston, Texas &#8230; if you don&#8217;t have an MSDN subscription, you can check out Visual C# Express 2008 and the rest of the Visual 2008 Express editions, or the trial versions and of course, the new .Net Framework 3.5]]></description>
			<content:encoded><![CDATA[	<p>Well, <a href="http://msdn2.microsoft.com/en-us/vstudio/default.aspx">Visual Studio 2008</a> launched while I was off in Houston, Texas &#8230; if you don&#8217;t have an <a href="http://msdn2.microsoft.com/subscriptions/bb608344.aspx"><span class="caps">MSDN</span> subscription</a>, you can check out <a href="http://www.microsoft.com/express/vcsharp/">Visual C# Express 2008</a> and the rest of the Visual <a href="http://www.microsoft.com/express">2008 Express</a> editions, or the <a href="http://msdn2.microsoft.com/en-us/vstudio/products/aa700831.aspx">trial versions</a> and of course, the new <a href="http://go.microsoft.com/?linkid=7755937">.Net Framework 3.5</a></p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/visual-studio-2008/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

