<?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>doodle dabbles &#187; dotnet</title>
	<atom:link href="http://ashish.tonse.com/tag/dotnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://ashish.tonse.com</link>
	<description>a little nerdery for everyone</description>
	<lastBuildDate>Thu, 17 Sep 2009 21:35:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Serializing XML in .NET &#8211; UTF-8 and UTF-16</title>
		<link>http://ashish.tonse.com/2008/04/serializing-xml-in-net-utf-8-and-utf-16/</link>
		<comments>http://ashish.tonse.com/2008/04/serializing-xml-in-net-utf-8-and-utf-16/#comments</comments>
		<pubDate>Tue, 15 Apr 2008 14:40:24 +0000</pubDate>
		<dc:creator>Ashish</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://ashish.tonse.com/?p=30</guid>
		<description><![CDATA[When working with xml to object mapping, most modern languages have powerful tools or libraries that serialize and deserialize objects for you automatically, or even create classes for you based on xml schema definitions (XSDs). In the .NET world, these classes reside in the System.Xml.Serialization namespace. There is plenty of documentation available on how to [...]]]></description>
			<content:encoded><![CDATA[<p>When working with xml to object mapping, most modern languages have powerful tools or libraries that serialize and deserialize objects for you automatically, or even create classes for you based on xml schema definitions (XSDs). In the .NET world, these classes reside in the System.Xml.Serialization namespace. There is plenty of documentation available on how to use it.</p>
<p>However, you might encounter an issue when trying to serialize your object to XML, especially if you use a StringWriter to serialize your object to an XML string instead of a file. Since .NET strings are always stored in UTF-16, your resulting xml file will have the encoding of UTF-16. One way to get around this is by creating a MemoryStream, creating a StreamWriter, and applying the UTF-8 encoding to that StreamWriter.</p>
<p>The easy way of serializing an object to xml as a string (not to a file):</p>
<pre class="code csharp">XmlSerializer serializer = new XmlSerializer(typeof(YourObject));
System.IO.StringWriter sWriter = new System.IO.StringWriter();

serializer.Serialize(sWriter, yourObjectInstance);
sWriter.Flush();

string result = sWriter.ToString();</pre>
<p>But since this will result in an xml file with encoding UTF-16, we have the following block:</p>
<pre class="code csharp">XmlSerializer serializer = new XmlSerializer(typeof(YourObject));

// create a MemoryStream here, we are just working
// exclusively in memory
System.IO.Stream stream = new System.IO.MemoryStream();

// The XmlTextWriter takes a stream and encoding
// as one of its constructors
System.Xml.XmlTextWriter xtWriter = new System.Xml.XmlTextWriter(stream, Encoding.UTF8);

serializer.Serialize(xtWriter, yourObjectInstance);

xtWriter.Flush();

// go back to the beginning of the Stream to read its contents
stream.Seek(0, System.IO.SeekOrigin.Begin);

// read back the contents of the stream and supply the encoding
System.IO.StreamReader reader = new System.IO.StreamReader(stream, Encoding.UTF8);

string result = reader.ReadToEnd();</pre>
<p><strong>Update 5/5/09</strong> &#8211; From MumHaBR in the comments, instead of using the final StreamReader, you can use this:</p>
<pre>Encoding.UTF8.GetString(stream.ToArray());</pre>
<p>Remember, the MemoryStream is just a stream of bytes and doesn&#8217;t have to be text. So you create a StreamReader to read it back and have to tell the reader what encoding to use.</p>
<p>The idea of strings represented as bytes out in the wild, and various encodings, can be a little daunting for newer developers, but as long as you keep your encodings consistent, you should have no problems. And in the case that you need to convert to a different encoding, there are built-in libraries that do that for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://ashish.tonse.com/2008/04/serializing-xml-in-net-utf-8-and-utf-16/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>WPF Weekend, Part 1: Introducing CID</title>
		<link>http://ashish.tonse.com/2008/03/wpf-weekend-part-1-introducing-cid/</link>
		<comments>http://ashish.tonse.com/2008/03/wpf-weekend-part-1-introducing-cid/#comments</comments>
		<pubDate>Tue, 01 Apr 2008 01:02:13 +0000</pubDate>
		<dc:creator>Ashish</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://ashish.tonse.com/2008/03/31/wpf-weekend-part-1-introducing-cid/</guid>
		<description><![CDATA[Over lunch with my friends at OpenSource Connections last Friday, we had a discussion of how they could attract more people to their booth at the FOSE convention next week in Washington, DC. A recurring suggestion was to have something to dazzle people from a distance.One of the ideas we came up with is to [...]]]></description>
			<content:encoded><![CDATA[<p>Over lunch with my friends at <a title="OpenSource Connections" href="http://www.opensourceconnections.com/">OpenSource Connections</a> last Friday, we had a discussion of how they could attract more people to their booth at the FOSE convention next week in Washington, DC. A recurring suggestion was to have something to dazzle people from a distance.One of the ideas we came up with is to have an eye-catching display, but that only had limited value.</p>
<p>So we decided to show attendees information that is immediately useful to them, such as the conference event schedule.SO this weekend, Michael Herndon from OSC, and myself, started to build what would become CID.</p>
<p>We decided from the beginning to open source the project and host it on Google Code, so that others can benefit and learn from our experience, and also so that it could be extended easily in the future. This series of posts outlines some of the things we learned in the process.</p>
<p><span id="more-15"></span></p>
<h3 id="wpf">WPF</h3>
<p>Firstly, a short intro to WPF. WPF is short for Windows Presentation Foundation, is a set of Microsoft-based technologies (namely, XAML and a .NET 3.0 Presentation Framework) that allow developers to build rich media applications which take advantage of graphics hardware that’s common in today’s computers. For a better overview of WPF, go to <a title="Wikipedia Entry: WPF" href="http://en.wikipedia.org/wiki/WPF">WPF</a>.</p>
<h3 id="goals">Goals</h3>
<p>There were three goals to this project:</p>
<ul>
<li>Bring people to the OSC Booth and make them talk about it</li>
<li>Show off OSC’s skills in cutting edge technologies (like WPF)</li>
<li>And most importantly, it gave us an excuse to play with WPF. <img src='http://ashish.tonse.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </li>
</ul>
<h3 id="tools_we_used">Tools we used</h3>
<p>Not much of a surprise, but we used entirely Microsoft-based tools, since they were optimized for building WPF applications and writing XAML.- <a title="Visual Studio 2008" href="http://msdn.microsoft.com/vstudio/">Visual Studio 2008</a> (with <a title="Download details: .NET Framework 3.5" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=333325FD-AE52-4E35-B531-508D977D32A6">.NET 3.5</a>)- <a title="Expression Blend and Design : The WinFX Runtime Components February CTP has been published!" href="http://blogs.msdn.com/expression/archive/2006/02/22/537105.aspx">Expression Blend 2 February CTP</a></p>
<h3 id="the_app">The App</h3>
<p><a title="Cid Screenshot" href="http://ashish.tonse.com/wp-content/uploads/2008/03/cid-screenshot.jpg" target="_blank"><img src="http://ashish.tonse.com/wp-content/uploads/2008/03/cid-small.jpg" alt="cid-small.jpg" /></a><a title="Cid Screenshot" href="http://ashish.tonse.com/wp-content/uploads/2008/03/cid-screenshot.jpg" target="_blank"></a></p>
<p>Click above for a screenshot of the final app (final as of this weekend). In the coming days, I’m going to outline how we did various things with CID and WPF. I want to cover the following topics:</p>
<ul>
<li>Part 2: Layouts</li>
<li>Part 3: Databinding (Relative, Elements, DataContexts)</li>
<li>Part 4: Animations, Per-character Text Effects, Calling Storyboards from C#</li>
<li>Part 5: Code-behind events, programmatic animations and storyboards, and wrap-up </li>
</ul>
<p>So stick around! <img src='http://ashish.tonse.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://ashish.tonse.com/2008/03/wpf-weekend-part-1-introducing-cid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Executing Office Plugins Across Two Zones</title>
		<link>http://ashish.tonse.com/2007/11/executing-office-plugins-across-two-zones/</link>
		<comments>http://ashish.tonse.com/2007/11/executing-office-plugins-across-two-zones/#comments</comments>
		<pubDate>Wed, 14 Nov 2007 20:51:04 +0000</pubDate>
		<dc:creator>Ashish</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[office]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://ashish.tonse.com/2007/11/14/executing-office-plugins-across-two-zones/</guid>
		<description><![CDATA[When building Office plugins, you have to give the right permissions so that the plugins can execute. Depending on your situation, you will have to touch upon multiple security concepts.
One is a Zone. A zone is like the &#8220;area&#8221; of interest. There are two zones involved in doing this:

The location of your plugin (the dll [...]]]></description>
			<content:encoded><![CDATA[<p>When building Office plugins, you have to give the right permissions so that the plugins can execute. Depending on your situation, you will have to touch upon multiple security concepts.</p>
<p>One is a Zone. A zone is like the &#8220;area&#8221; of interest. There are two zones involved in doing this:</p>
<ul>
<li>The location of your plugin (the dll files, etc)</li>
<li>The location of the Word/Excel file being opened (*.doc, *.xls, etc)</li>
</ul>
<p>These zones usually match up (if your plugin is installed on your computer, and you&#8217;re accessing an Office document on your hard drive, both locations are the &#8220;My Computer&#8221; zone).</p>
<p>For my situation, I had the plugin installed in my computer, but the file being accessed was over an untrusted network share, hence the file was placed in the &#8220;Internet&#8221; zone.</p>
<p>I had my assemblies in C:\Program Files\InstalledAppDir\*<br />
My Word Doc was in: \\networkserver\sharename\something.doc</p>
<p>It triggered the following error:</p>
<p><code>The customization does not have the required permissions to execute.</code><br />
<code><br />
************** Exception Text **************<br />
System.Security.SecurityException: The customization does not have the required permissions to execute.<br />
at Microsoft.VisualStudio.Tools.Applications.Runtime.DomainFactory.CreateDomain(Uri evidenceUri, String domainName, String codeBase, String configFileName, IAddinSecurityManager secman)<br />
at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.CreateCustomizationDomainInternal(Uri uriFullDocumentDirectory, Uri uriFullDocFilePath, String documentName, IHostServiceProvider hostCallback, IAddinSecurityManager secman, AppManifest&amp; applicationManifest, Boolean&amp; manifestDirty, IAppInfo&amp; appInfo)<br />
at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.CreateCustomizationDomain(String applicationDomainPath, String documentName, IHostServiceProvider hostCallback, IExecuteCustomization&amp; executor)<br />
at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManager.CreateCustomizationDomain(String applicationDomainPath, String documentName, IHostServiceProvider hostCallback, IExecuteCustomization&amp; executor)<br />
The Zone of the assembly that failed was:<br />
MyComputer<br />
</code><br />
I followed <a href="http://msdn2.microsoft.com/en-us/library/9w6bd8f1(vs.80).aspx">this guide</a> and tweaked the following policies a little and it now works:</p>
<p>MyComputer zone:<br />
&#8220;FullTrust&#8221; permissions to the url: C:\Program Files\InstalledAppDir\*<br />
Internet zone:<br />
&#8220;Nothing&#8221; permission to the url: \\networkserver\sharename<br />
&#8220;FullTrust&#8221; permissions to the OfficeDocumentMembershipCondition</p>
<p>Make sure you add the membership collection to the internet zone, even if you are accessing a network share. The easiest way to know the zone (and how I found out) is to look at your status bar when you go to the network share. It&#8217;ll tell you what security zone that path is seen as.</p>
]]></content:encoded>
			<wfw:commentRss>http://ashish.tonse.com/2007/11/executing-office-plugins-across-two-zones/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
