<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6299626589601724719</id><updated>2024-08-30T19:30:45.724+10:00</updated><category term="Silverlight 4"/><category term="Binding"/><category term="C#"/><category term="Custom Property"/><category term="Dependency Property"/><category term="Makecert"/><category term="OOXML"/><category term="Open Office XML"/><category term="Properties"/><category term="Property"/><category term="RSA"/><category term="Value Converter"/><category term="X509 Certificates"/><title type='text'>Just Another C# Blog - The Blog of Nick Howard</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://nick-howard.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6299626589601724719/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://nick-howard.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>aus</name><uri>http://www.blogger.com/profile/16413691884245062146</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6299626589601724719.post-8296465018803866088</id><published>2011-06-09T14:31:00.003+10:00</published><updated>2011-06-09T14:34:27.517+10:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Properties"/><category scheme="http://www.blogger.com/atom/ns#" term="Silverlight 4"/><category scheme="http://www.blogger.com/atom/ns#" term="Value Converter"/><title type='text'>Silverlight 4 Value Converter Properties</title><content type='html'>An interesting problem I faced recently was how to give a Value Converter class access to &quot;data&quot; (strings, ints, bools, lists, collections, etc). I thought about this for a while, and I firstly figured I could probably give the Value Converter access to whatever data it needed through its own view model. I thought about this some more and decided wouldn&#39;t it be cool if I could just declare properties in my Value Converter class and bind those properties to data in my xaml&#39;s view model, thus keeping my Value Converter a fairly light object. At that time there wasn&#39;t much literature around suggesting that this was even possible, much less any examples, so I went about it my own way.&lt;br /&gt;
&lt;br /&gt;
I had also been recently looking at binding to dependency properties (&lt;a href=&quot;http://nick-howard.blogspot.com/2011/03/silverlight-4-custom-property-binding.html&quot; target=&quot;_blank&quot;&gt;Silverlight 4 Custom Property Binding&lt;/a&gt;), so it was something I had fresh in my mind. I knew that to register a &lt;span style=&quot;color: #2b91af;&quot;&gt;DependencyProperty&lt;/span&gt; the owner needed to inherit from the &lt;span style=&quot;color: #2b91af;&quot;&gt;DependencyProperty&lt;/span&gt; base class. So as well as implementing the usual &lt;span style=&quot;color: #2b91af;&quot;&gt;IValueConverter&lt;/span&gt;  interface, I made my class inherit from &lt;span style=&quot;color: #2b91af;&quot;&gt;DependencyObject&lt;/span&gt;  like so:&lt;br /&gt;
&lt;pre style=&quot;background: white; color: black; font-family: Courier New; font-size: 13;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;CustomValueConverter&lt;/span&gt;&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;DependencyObject&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;IValueConverter&lt;/span&gt; &lt;/pre&gt;&lt;br /&gt;
I then declared a couple of dependency properties in my class; firstly a &lt;span style=&quot;color: #2b91af;&quot;&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt;&amp;nbsp;LookupDictionary and secondly a&lt;span style=&quot;color: blue;&quot;&gt; bool&lt;/span&gt;&amp;nbsp;UpperCase , like so:&lt;br /&gt;
&lt;pre style=&quot;background: white; color: black; font-family: Courier New; font-size: 13;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;readonly&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Depende&lt;wbr&gt;&lt;/wbr&gt;ncyProperty&lt;/span&gt;&amp;nbsp;&lt;pre style=&quot;background: white; color: black; font-family: Courier New; font-size: 13;&quot;&gt;&lt;wbr&gt;&lt;/wbr&gt;LookupDictionaryProperty&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Dep&lt;wbr&gt;&lt;/wbr&gt;endencyProperty&lt;/span&gt;.Register
(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;LookupDictionary&quot;&lt;/span&gt;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;typeof&lt;/span&gt;(&lt;span style=&quot;color: #2b91af;&quot;&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;str&lt;wbr&gt;&lt;/wbr&gt;ing&lt;/span&gt;&amp;gt;),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;typeof&lt;/span&gt;(&lt;span style=&quot;color: #2b91af;&quot;&gt;CustomValueConverte&lt;wbr&gt;&lt;/wbr&gt;r&lt;/span&gt;),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;
);
 
&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt;&lt;wbr&gt;&lt;/wbr&gt;&amp;nbsp;LookupDictionary
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;&amp;nbsp;{&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&amp;nbsp;(&lt;span style=&quot;color: #2b91af;&quot;&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;i&lt;wbr&gt;&lt;/wbr&gt;nt&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt;)GetValue(&lt;wbr&gt;&lt;/wbr&gt;LookupDictionaryProperty);&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;&amp;nbsp;{&amp;nbsp;SetValue(&lt;wbr&gt;&lt;/wbr&gt;LookupDictionaryProperty,&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;valu&lt;wbr&gt;&lt;/wbr&gt;e&lt;/span&gt;);&amp;nbsp;}
}
 
&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;readonly&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Depende&lt;wbr&gt;&lt;/wbr&gt;ncyProperty&lt;/span&gt;&amp;nbsp;UpperCaseProperty&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;=&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;DependencyProperty&lt;/span&gt;.Register
(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;UpperCase&quot;&lt;/span&gt;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;typeof&lt;/span&gt;(&lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt;),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;typeof&lt;/span&gt;(&lt;span style=&quot;color: #2b91af;&quot;&gt;CustomValueConverte&lt;wbr&gt;&lt;/wbr&gt;r&lt;/span&gt;),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;
);
 
&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt;&amp;nbsp;UpperCase
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;&amp;nbsp;{&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&amp;nbsp;(&lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt;)&lt;wbr&gt;&lt;/wbr&gt;GetValue(UpperCaseProperty);&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;&amp;nbsp;{&amp;nbsp;SetValue(&lt;wbr&gt;&lt;/wbr&gt;UpperCaseProperty,&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;value&lt;/span&gt;);&amp;nbsp;}
}&lt;/pre&gt;&lt;/pre&gt;&lt;br /&gt;
The next thing I wanted to do was actually use the properties in my Convert method, so as an example I did something like this:&lt;br /&gt;
&lt;pre style=&quot;background: white; color: black; font-family: Courier New; font-size: 13;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt;&amp;nbsp;Convert(&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt;&amp;nbsp;&lt;pre style=&quot;background: white; color: black; font-family: Courier New; font-size: 13;&quot;&gt;&lt;wbr&gt;&lt;/wbr&gt;value,&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Type&lt;/span&gt;&amp;nbsp;targetType,&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt;&lt;wbr&gt;&lt;/wbr&gt;&amp;nbsp;parameter,&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;CultureInfo&lt;/span&gt;&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;culture)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;nbsp;lookup&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;.&lt;wbr&gt;&lt;/wbr&gt;Empty;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&amp;nbsp;(!(value&amp;nbsp;==&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;&amp;nbsp;||&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;LookupDictionary&amp;nbsp;==&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&amp;nbsp;(value&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;is&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&amp;nbsp;(UpperCase)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lookup&amp;nbsp;=&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;LookupDictionary[(&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;)value].&lt;wbr&gt;&lt;/wbr&gt;ToUpper();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lookup&amp;nbsp;=&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;LookupDictionary[(&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;)value];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&amp;nbsp;lookup;
}&lt;/pre&gt;&lt;/pre&gt;&lt;br /&gt;
That&#39;s basically all you need to be able use your converter in your xaml, and set values for the properties we have declared in it.&lt;br /&gt;
&lt;br /&gt;
Here is the entire example of the Value Converter class example:&lt;br /&gt;
&lt;pre style=&quot;background: white; color: black; font-family: Courier New; font-size: 13;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt;&amp;nbsp;System;
&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt;&amp;nbsp;System.Windows;
&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt;&amp;nbsp;System.Windows.Data;
&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt;&amp;nbsp;System.Globalization;
&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt;&amp;nbsp;System.Collections.&lt;pre style=&quot;background: white; color: black; font-family: Courier New; font-size: 13;&quot;&gt;&lt;wbr&gt;&lt;/wbr&gt;Generic;
 
&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;CustomValueConver&lt;wbr&gt;&lt;/wbr&gt;ter&lt;/span&gt;&amp;nbsp;:&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;DependencyObject&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;IValue&lt;wbr&gt;&lt;/wbr&gt;Converter&lt;/span&gt;
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;readonly&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Dep&lt;wbr&gt;&lt;/wbr&gt;endencyProperty&lt;/span&gt;&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;LookupDictionaryProperty&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Dep&lt;wbr&gt;&lt;/wbr&gt;endencyProperty&lt;/span&gt;.Register
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;LookupDictionary&quot;&lt;/span&gt;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;typeof&lt;/span&gt;(&lt;span style=&quot;color: #2b91af;&quot;&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;,&lt;wbr&gt;&lt;/wbr&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt;),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;typeof&lt;/span&gt;(&lt;span style=&quot;color: #2b91af;&quot;&gt;CustomValueConv&lt;wbr&gt;&lt;/wbr&gt;erter&lt;/span&gt;),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;str&lt;wbr&gt;&lt;/wbr&gt;ing&lt;/span&gt;&amp;gt;&amp;nbsp;LookupDictionary
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;&amp;nbsp;{&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&amp;nbsp;(&lt;span style=&quot;color: #2b91af;&quot;&gt;Dictiona&lt;wbr&gt;&lt;/wbr&gt;ry&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt;)GetValue(&lt;wbr&gt;&lt;/wbr&gt;LookupDictionaryProperty);&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;&amp;nbsp;{&amp;nbsp;SetValue(&lt;wbr&gt;&lt;/wbr&gt;LookupDictionaryProperty,&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;valu&lt;wbr&gt;&lt;/wbr&gt;e&lt;/span&gt;);&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;readonly&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Dep&lt;wbr&gt;&lt;/wbr&gt;endencyProperty&lt;/span&gt;&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;UpperCaseProperty&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Dependency&lt;wbr&gt;&lt;/wbr&gt;Property&lt;/span&gt;.Register
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;UpperCase&quot;&lt;/span&gt;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;typeof&lt;/span&gt;(&lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt;),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;typeof&lt;/span&gt;(&lt;span style=&quot;color: #2b91af;&quot;&gt;CustomValueConv&lt;wbr&gt;&lt;/wbr&gt;erter&lt;/span&gt;),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt;&amp;nbsp;UpperCase
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;&amp;nbsp;{&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&amp;nbsp;(&lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt;)&lt;wbr&gt;&lt;/wbr&gt;GetValue(UpperCaseProperty);&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;&amp;nbsp;{&amp;nbsp;SetValue(&lt;wbr&gt;&lt;/wbr&gt;UpperCaseProperty,&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;value&lt;/span&gt;);&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
 
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt;&amp;nbsp;Convert(&lt;span style=&quot;color: blue;&quot;&gt;obje&lt;wbr&gt;&lt;/wbr&gt;ct&lt;/span&gt;&amp;nbsp;value,&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Type&lt;/span&gt;&amp;nbsp;targetType,&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;obj&lt;wbr&gt;&lt;/wbr&gt;ect&lt;/span&gt;&amp;nbsp;parameter,&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;CultureInfo&lt;/span&gt;&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;culture)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;nbsp;lookup&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;wbr&gt;&lt;/wbr&gt;.Empty;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&amp;nbsp;(!(value&amp;nbsp;==&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;&amp;nbsp;||&lt;wbr&gt;&lt;/wbr&gt;&amp;nbsp;LookupDictionary&amp;nbsp;==&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&amp;nbsp;(value&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;is&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&amp;nbsp;(UpperCase)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lookup&amp;nbsp;=&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;LookupDictionary[(&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;)value].&lt;wbr&gt;&lt;/wbr&gt;ToUpper();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lookup&amp;nbsp;=&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;LookupDictionary[(&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;)value];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&amp;nbsp;lookup;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt;&amp;nbsp;ConvertBack(&lt;span style=&quot;color: blue;&quot;&gt;&lt;wbr&gt;&lt;/wbr&gt;object&lt;/span&gt;&amp;nbsp;value,&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Type&lt;/span&gt;&amp;nbsp;targetType,&lt;wbr&gt;&lt;/wbr&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt;&amp;nbsp;parameter,&amp;nbsp;System.&lt;wbr&gt;&lt;/wbr&gt;Globalization.&lt;span style=&quot;color: #2b91af;&quot;&gt;CultureInfo&lt;/span&gt;&amp;nbsp;&lt;wbr&gt;&lt;/wbr&gt;culture)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;throw&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;NotImplement&lt;wbr&gt;&lt;/wbr&gt;edException&lt;/span&gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
 
}}&lt;/pre&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://nick-howard.blogspot.com/feeds/8296465018803866088/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nick-howard.blogspot.com/2011/06/silverlight-4-value-converter.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6299626589601724719/posts/default/8296465018803866088'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6299626589601724719/posts/default/8296465018803866088'/><link rel='alternate' type='text/html' href='http://nick-howard.blogspot.com/2011/06/silverlight-4-value-converter.html' title='Silverlight 4 Value Converter Properties'/><author><name>aus</name><uri>http://www.blogger.com/profile/16413691884245062146</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6299626589601724719.post-8800213228531292980</id><published>2011-05-16T16:40:00.002+10:00</published><updated>2011-05-27T12:28:40.091+10:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="Makecert"/><category scheme="http://www.blogger.com/atom/ns#" term="RSA"/><category scheme="http://www.blogger.com/atom/ns#" term="X509 Certificates"/><title type='text'>Makecert, X509 Certificates and RSA</title><content type='html'>&lt;h1&gt;Makecert, X509 Certificates and RSA&lt;/h1&gt;&lt;div class=&quot;MsoNormal&quot;&gt;So there is a lot of articles out there about x.509 certificates, RSA and the makecert tool but nothing really that ties it altogether. Given these articles I am not going to focus on the individual parts, but rather focus on using all the bits together to do X509 certificate key based RSA provider encryption and decryption using C#.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;h2&gt;Generate Some Certificates&lt;/h2&gt;&lt;div class=&quot;MsoNormal&quot;&gt;Here is the combination of the makecert and pvk2pfx command lines I used to generate my certificates:&lt;/div&gt;&lt;div class=&quot;MsoListParagraphCxSpFirst&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18pt;&quot;&gt;&lt;span style=&quot;mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;1.&lt;span style=&quot;font-size-adjust: none; font-stretch: normal; font: 7pt/normal &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;makecert -n &quot;CN=Nicks Certificate Authority&quot; -cy authority -a sha1 -sv &quot;C:\temp\cert\nick_ca.pvk&quot; -r &quot;C:\temp\cert\nick_ca.cer&quot;&lt;/div&gt;&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18pt;&quot;&gt;&lt;span style=&quot;mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;2.&lt;span style=&quot;font-size-adjust: none; font-stretch: normal; font: 7pt/normal &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;makecert -pe -n &quot;CN=Nicks Dev&quot; -a sha1 -sky exchange -eku 1.3.6.1.5.5.7.3.1 -ic &quot;C:\temp\cert\nick_ca.cer&quot; -iv &quot;C:\temp\cert\nick_ca.pvk&quot; -sp &quot;Microsoft RSA SChannel Cryptographic Provider&quot; -sy 12 -sv &quot;C:\temp\cert\nick_dev.pvk&quot; &quot;C:\temp\cert\nick_dev.cer&quot;&lt;/div&gt;&lt;div class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;mso-list: l0 level1 lfo1; text-indent: -18pt;&quot;&gt;&lt;span style=&quot;mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;&quot;&gt;&lt;span style=&quot;mso-list: Ignore;&quot;&gt;3.&lt;span style=&quot;font-size-adjust: none; font-stretch: normal; font: 7pt/normal &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;pvk2pfx -pvk &quot;C:\temp\cert\nick_dev.pvk&quot; -spc &quot;C:\temp\cert\nick_dev.cer&quot; -pfx &quot;C:\temp\cert\nick_dev.pfx&quot;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;There are plenty of articles out there talking about the makecert and pvk2pfx tools so I wont go on too much about those. Suffice to say, step 1 creates a certificate authority with private key, step 2 creates a certificate for use based on the authority with private key, and step 3 takes the certificate and key from step 2 and wraps them into personal information exchange (pfx) file. You will also notice that I am generating my cer, pvk and pfx files into the &quot;C:\temp\cert\&quot; directory. I haven&#39;t bothered about importing these files into my certificate stores, if you are interested in that there are a number of other articles out there that you can refer to, along with the syntax for the makecert and pvk2pfx.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;h2&gt;Use the Certificates&lt;/h2&gt;&lt;div class=&quot;MsoNormal&quot;&gt;Now we&#39;re got the techy stuff out of the way, its now time to actually put these certificates to work. The following code shows how we get an instance of our certificate, and cast it to an RSA provider for further use in our C# code:&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span style=&quot;color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-AU;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-AU;&quot;&gt;&amp;nbsp;path&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #a31515; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-AU;&quot;&gt;&quot;C:\\temp\\cert\\nick_dev.pfx&quot;&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-AU;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span style=&quot;color: #2b91af; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-AU;&quot;&gt;X509Certificate2&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-AU;&quot;&gt;&amp;nbsp;certificate&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-AU;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-AU;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #2b91af; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-AU;&quot;&gt;X509Certificate2&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-AU;&quot;&gt;(path,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-AU;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-AU;&quot;&gt;.Empty);&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;&quot;&gt;&lt;span style=&quot;color: #2b91af; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-AU;&quot;&gt;RSACryptoServiceProvider&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-AU;&quot;&gt;&amp;nbsp;provider&amp;nbsp;=&amp;nbsp;(&lt;/span&gt;&lt;span style=&quot;color: #2b91af; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-AU;&quot;&gt;RSACryptoServiceProvider&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-AU;&quot;&gt;)certificate.PrivateKey;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;By the way, I am in no way advocating that my code is best practice I am just illustrating roughly how to get the job done. Notice that the X509Certificate2 constructor takes two parameters, the first is the path and the second is the password, with this particular overload signifying that we are loading a pfx file. No password is provided as we didn&#39;t specify one when we created our certificates, I would recommend you do use a strong password, but again you can look at the numerous articles out there for makecert and pvk2pfx to help you with this option.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;Encrypting and Decrypting&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;Ok we&#39;ve already got our RSA provider so you can probably work it out from here or even look at the again numerous articles on RSA encryption and decryption to help you, but since I promised I would tie all the technologies together I better fulfil my end of the bargin and give you a quick overview of how to do the encryption and decryption.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;So, here is the code for encryption:&lt;/div&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;RSAEnc(&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;RSACryptoServiceProvider&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;provider,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;plain)&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;StringBuilder&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;cipher&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;StringBuilder&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;();&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;cur&amp;nbsp;=&amp;nbsp;0;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;while&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;(cur&amp;nbsp;&amp;lt;&amp;nbsp;plain.Length)&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;ss&amp;nbsp;=&amp;nbsp;plain.Substring(cur);&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;(ss.Length&amp;nbsp;&amp;gt;&amp;nbsp;86)&amp;nbsp;ss&amp;nbsp;=&amp;nbsp;ss.Substring(0,&amp;nbsp;86);&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;List&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;byte&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;gt;&amp;nbsp;buffer&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;List&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;byte&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;gt;();&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;(&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;c&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;ss.ToCharArray())&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;buffer.Add((&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;byte&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)c);&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;byte&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;[]&amp;nbsp;result&amp;nbsp;=&amp;nbsp;provider.Encrypt(buffer.ToArray(),&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;(&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;byte&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;b&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;result)&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cipher.Append(b.ToString(&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;X2&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;));&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cur&amp;nbsp;+=&amp;nbsp;86;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;(cur&amp;nbsp;&amp;lt;&amp;nbsp;plain.Length)&amp;nbsp;cipher.Append(&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;+&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;cipher.ToString();&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;And for decryption:&lt;/div&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;RSADec(&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;RSACryptoServiceProvider&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;provider,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;cipher)&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;StringBuilder&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;plain&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;StringBuilder&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;();&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;(!&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;.IsNullOrEmpty(cipher))&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;(&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;ss&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;cipher.Split(&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;&#39;+&#39;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;))&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;byte&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;[]&amp;nbsp;buffer&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;byte&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;[ss.Length&amp;nbsp;/&amp;nbsp;2];&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;(&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;cnt&amp;nbsp;=&amp;nbsp;0;&amp;nbsp;cnt&amp;nbsp;&amp;lt;&amp;nbsp;ss.Length;&amp;nbsp;cnt&amp;nbsp;+=&amp;nbsp;2)&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;buffer[cnt&amp;nbsp;/&amp;nbsp;2]&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;Convert&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;.ToByte(ss.Substring(cnt,&amp;nbsp;2),&amp;nbsp;16);&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;byte&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;[]&amp;nbsp;result&amp;nbsp;=&amp;nbsp;provider.Decrypt(buffer,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;(&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;byte&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;b&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;result)&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;plain.Append((&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)b);&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;plain.ToString();&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background: white;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;There you go, simple as that.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nick-howard.blogspot.com/feeds/8800213228531292980/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nick-howard.blogspot.com/2011/05/makecert-x509-certificates-and-rsa.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6299626589601724719/posts/default/8800213228531292980'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6299626589601724719/posts/default/8800213228531292980'/><link rel='alternate' type='text/html' href='http://nick-howard.blogspot.com/2011/05/makecert-x509-certificates-and-rsa.html' title='Makecert, X509 Certificates and RSA'/><author><name>aus</name><uri>http://www.blogger.com/profile/16413691884245062146</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6299626589601724719.post-1295736309931315849</id><published>2011-03-30T13:02:00.003+11:00</published><updated>2011-06-09T15:38:37.197+10:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Binding"/><category scheme="http://www.blogger.com/atom/ns#" term="Custom Property"/><category scheme="http://www.blogger.com/atom/ns#" term="Dependency Property"/><category scheme="http://www.blogger.com/atom/ns#" term="Property"/><category scheme="http://www.blogger.com/atom/ns#" term="Silverlight 4"/><title type='text'>Silverlight 4 Custom Property Binding</title><content type='html'>A common scenario you might encounter is wanting to create a bindable property on a custom control. The way we do this is using a static &lt;span style=&quot;color: #2b91af;&quot;&gt;DependencyProperty&lt;/span&gt; member as our backing field. Below is an example of a &lt;span style=&quot;color: #2b91af;&quot;&gt;CustomTextBox&lt;/span&gt; with a string CustomString property:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: white; color: black; font-family: Courier New; font-size: 13;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt;&amp;nbsp;System.Windows;&amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Courier New; font-size: 13px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;CustomTextBox&lt;/span&gt;&amp;nbsp;:&amp;nbsp;System.Windows.Controls.&lt;span style=&quot;color: #2b91af;&quot;&gt;TextBox&lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Courier New; font-size: 13px;&quot;&gt;{&lt;/pre&gt;&lt;pre style=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Courier New; font-size: 13px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;readonly&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;DependencyProperty&lt;/span&gt;&amp;nbsp;CustomStringProperty&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;DependencyProperty&lt;/span&gt;.Register&lt;/pre&gt;&lt;pre style=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Courier New; font-size: 13px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(&lt;/pre&gt;&lt;pre style=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Courier New; font-size: 13px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;CustomString&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Courier New; font-size: 13px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;typeof&lt;/span&gt;(&lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt;),&lt;/pre&gt;&lt;pre style=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Courier New; font-size: 13px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;typeof&lt;/span&gt;(&lt;span style=&quot;color: #2b91af;&quot;&gt;CustomTextBox&lt;/span&gt;),&lt;/pre&gt;&lt;pre style=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Courier New; font-size: 13px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Courier New; font-size: 13px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;/pre&gt;&lt;pre style=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Courier New; font-size: 13px;&quot;&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Courier New; font-size: 13px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;nbsp;CustomString&lt;/pre&gt;&lt;pre style=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Courier New; font-size: 13px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;pre style=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Courier New; font-size: 13px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;&amp;nbsp;{&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&amp;nbsp;(&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;)GetValue(CustomStringProperty);&amp;nbsp;}&lt;/pre&gt;&lt;pre style=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Courier New; font-size: 13px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;&amp;nbsp;{&amp;nbsp;SetValue(CustomStringProperty,&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;value&lt;/span&gt;);&amp;nbsp;}&lt;/pre&gt;&lt;pre style=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Courier New; font-size: 13px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Courier New; font-size: 13px;&quot;&gt;}&lt;/pre&gt;&lt;pre style=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Courier New; font-size: 13px;&quot;&gt;&amp;nbsp;&lt;/pre&gt;You can now use the&lt;span style=&quot;color: #2b91af;&quot;&gt; CustomTextBox&lt;/span&gt; in your XAML, and bind directly to the CustomString property.&lt;br /&gt;
&lt;br /&gt;
Just a simple example to illustrate how its done. If you want more information on how it all works, check out the MSDN documentation.</content><link rel='replies' type='application/atom+xml' href='http://nick-howard.blogspot.com/feeds/1295736309931315849/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nick-howard.blogspot.com/2011/03/silverlight-4-custom-property-binding.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6299626589601724719/posts/default/1295736309931315849'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6299626589601724719/posts/default/1295736309931315849'/><link rel='alternate' type='text/html' href='http://nick-howard.blogspot.com/2011/03/silverlight-4-custom-property-binding.html' title='Silverlight 4 Custom Property Binding'/><author><name>aus</name><uri>http://www.blogger.com/profile/16413691884245062146</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6299626589601724719.post-8968224958577019807</id><published>2010-09-24T16:35:00.001+10:00</published><updated>2010-09-24T16:35:13.368+10:00</updated><title type='text'>Merging Word Documents using Office Open XML (OOXML)</title><content type='html'>&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;&lt;meta name=&quot;ProgId&quot; content=&quot;Word.Document&quot;&gt;&lt;meta name=&quot;Generator&quot; content=&quot;Microsoft Word 12&quot;&gt;&lt;meta name=&quot;Originator&quot; content=&quot;Microsoft Word 12&quot;&gt;&lt;link rel=&quot;File-List&quot; href=&quot;file:///C:%5CUsers%5Cnhoward%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_filelist.xml&quot;&gt;&lt;link rel=&quot;themeData&quot; href=&quot;file:///C:%5CUsers%5Cnhoward%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_themedata.thmx&quot;&gt;&lt;link rel=&quot;colorSchemeMapping&quot; href=&quot;file:///C:%5CUsers%5Cnhoward%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_colorschememapping.xml&quot;&gt;&lt;style&gt; &lt;!--  /* Font Definitions */  @font-face 	{font-family:&quot;Cambria Math&quot;; 	panose-1:2 4 5 3 5 4 6 3 2 4; 	mso-font-charset:0; 	mso-generic-font-family:roman; 	mso-font-pitch:variable; 	mso-font-signature:-1610611985 1107304683 0 0 415 0;} @font-face 	{font-family:Calibri; 	panose-1:2 15 5 2 2 2 4 3 2 4; 	mso-font-charset:0; 	mso-generic-font-family:swiss; 	mso-font-pitch:variable; 	mso-font-signature:-520092929 1073786111 9 0 415 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-unhide:no; 	mso-style-qformat:yes; 	mso-style-parent:&quot;&quot;; 	margin-top:0cm; 	margin-right:0cm; 	margin-bottom:10.0pt; 	margin-left:0cm; 	line-height:115%; 	mso-pagination:widow-orphan; 	font-size:11.0pt; 	font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; 	mso-ascii-font-family:Calibri; 	mso-ascii-theme-font:minor-latin; 	mso-fareast-font-family:Calibri; 	mso-fareast-theme-font:minor-latin; 	mso-hansi-font-family:Calibri; 	mso-hansi-theme-font:minor-latin; 	mso-bidi-font-family:&quot;Times New Roman&quot;; 	mso-bidi-theme-font:minor-bidi; 	mso-fareast-language:EN-US;} .MsoChpDefault 	{mso-style-type:export-only; 	mso-default-props:yes; 	mso-ascii-font-family:Calibri; 	mso-ascii-theme-font:minor-latin; 	mso-fareast-font-family:Calibri; 	mso-fareast-theme-font:minor-latin; 	mso-hansi-font-family:Calibri; 	mso-hansi-theme-font:minor-latin; 	mso-bidi-font-family:&quot;Times New Roman&quot;; 	mso-bidi-theme-font:minor-bidi; 	mso-fareast-language:EN-US;} .MsoPapDefault 	{mso-style-type:export-only; 	margin-bottom:10.0pt; 	line-height:115%;} @page WordSection1 	{size:595.3pt 841.9pt; 	margin:72.0pt 72.0pt 72.0pt 72.0pt; 	mso-header-margin:35.4pt; 	mso-footer-margin:35.4pt; 	mso-paper-source:0;} div.WordSection1 	{page:WordSection1;} --&gt; &lt;/style&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b style=&quot;&quot;&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;A common scenario when working with OOXML is the need to merge or append several word 2007 or 2010 documents. Using C#, in this article I illustrate how this is possible with relative ease. &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b style=&quot;&quot;&gt;Add a Reference&lt;/b&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;To start with you will need to add a reference to the WindowsBase.dll, which you may need to browse to at &quot;C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dll&quot;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;Next, you will need to add a using directive to your class for the System.IO.Packaging namespace, as follows:&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;; color: blue;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; System.IO.Packaging;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;b style=&quot;&quot;&gt;Document XML&lt;span style=&quot;&quot;&gt;         &lt;/span&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;Now we have a using directive for the Packaging namespace in our class, we can directly access the types within it. The Packaging namespace is actually provided for access to compressed files, and since word document docx files are compressed files, we can use the types to look at the OOXML files within the document file. To start with, we use the Package class and the Open method to open the file, like so:&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(43, 145, 175);&quot;&gt;Package&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; package = &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;Package&lt;/span&gt;.Open(fileName, &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;FileMode&lt;/span&gt;.Open, &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;FileAccess&lt;/span&gt;.ReadWrite)&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot;&gt;Since we are only interested in the actual body of the document, we want to now get access to the Document XML file within the package. If you were to open the word document yourself with a file compression utility, you would be able to see that the xml files that make up the document are organised into several files. The Document XML file we are interested in is called document.xml and is located within the word folder. To access a file within the document we use the Package method GetPart which will return a PackagePart type object as follows:&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(43, 145, 175);&quot;&gt;PackagePart&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; docPart = package.GetPart(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;Uri&lt;/span&gt;(&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;&amp;quot;/word/document.xml&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;UriKind&lt;/span&gt;.Relative));&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;Now we have access to the Document XML part, we want to then load the XML into an XmlDocument, and here is how we do that:&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(43, 145, 175);&quot;&gt;XmlDocument&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; document = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;XmlDocument&lt;/span&gt;();&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;document.Load(docPart.GetStream());&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;Because we have now loaded the Document XML file into an XmlDocument type object we can use all the methods available in the XmlDocument class to navigate through the XML. Because we are only interested in the actual body of the document, we want to select the body node of the document for later use, like so:&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(43, 145, 175);&quot;&gt;XmlNamespaceManager&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; nsm = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;XmlNamespaceManager&lt;/span&gt;(document.NameTable);&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;nsm.AddNamespace(&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;&amp;quot;w&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;&amp;quot;&lt;a href=&quot;http://schemas.openxmlformats.org/wordprocessingml/2006/main&quot;&gt;http://schemas.openxmlformats.org/wordprocessingml/2006/main&lt;/a&gt;&amp;quot;&lt;/span&gt;);&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(43, 145, 175);&quot;&gt;XmlNode&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; body = document.SelectSingleNode(&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;&amp;quot;/w:document/w:body&amp;quot;&lt;/span&gt;, nsm);&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b style=&quot;&quot;&gt;Appending/Merging Other Documents&lt;/b&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;Because we now have a reference to the body node of the document, we can simply add more children to the end of that node to append or merge other documents into it. What we basically do is repeat the process above for the second or subsequent documents, and then loop through the children nodes of the other documents appending them to the end of the first documents body node. Here is the snipped illustrating the looping through and appending of the children nodes:&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(43, 145, 175);&quot;&gt;XmlNode&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; last = body.LastChild;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: blue;&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; (&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;XmlNode&lt;/span&gt; childNode &lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt; lastPage.SelectSingleNode(&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;&amp;quot;/w:document/w:body&amp;quot;&lt;/span&gt;, nsm).ChildNodes)&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-indent: 36pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;{&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0.0001pt 36pt; text-indent: 36pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(43, 145, 175);&quot;&gt;XmlNode&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; docChildNode = document.ImportNode(childNode, &lt;span style=&quot;color: blue;&quot;&gt;true&lt;/span&gt;);&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0.0001pt 36pt; text-indent: 36pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;body.InsertAfter(docChildNode, last);&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 0.0001pt 36pt; text-indent: 36pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;last = docChildNode;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;text-indent: 36pt;&quot;&gt;&lt;span style=&quot;font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;}&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;It is worth noting the use of the XmlDocument ImportNode method. The reason we use that method, is because we are appending nodes to one document which are from another document, and therefore the namespaces differ. &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b style=&quot;&quot;&gt;Finally&lt;/b&gt;&lt;br&gt; The final thing we need to do is save the updated Document Xml back into its PackagePart. We simply call the Save method on the XmlDocument class as follows:&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;document.Save(docPart.GetStream(&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;FileMode&lt;/span&gt;.Create, &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;FileAccess&lt;/span&gt;.Write));&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b style=&quot;&quot;&gt;The Complete Code&lt;/b&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;The following is a complete example of merging/appending two word documents:&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: blue;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; System;&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: blue;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; System.IO;&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: blue;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; System.IO.Packaging;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: blue;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; System.Xml;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; &lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: blue;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;OpenOfficeXmlExample&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;{&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; &lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; MergeFiles()&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; DOC_URL = &lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;&amp;quot;/word/document.xml&amp;quot;&lt;/span&gt;;&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; OUTPUT_FILE = &lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;&amp;quot;C:\\TEMP\\MergedFile_{0:ddMMyy}-{0:HHmmss}.docx&amp;quot;&lt;/span&gt;;&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; FIRST_PAGE = &lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;&amp;quot;C:\\TEMP\\DocOne.docx&amp;quot;&lt;/span&gt;;&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; LAST_PAGE = &lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;&amp;quot;C:\\TEMP\\DocTwo.docx&amp;quot;&lt;/span&gt;;&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; &lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; fileName = &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;.Format(OUTPUT_FILE, &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;DateTime&lt;/span&gt;.Now);&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;File&lt;/span&gt;.Copy(FIRST_PAGE, fileName);&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; &lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; (&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;Package&lt;/span&gt; package = &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;Package&lt;/span&gt;.Open(fileName, &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;FileMode&lt;/span&gt;.Open, &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;FileAccess&lt;/span&gt;.ReadWrite))&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;PackagePart&lt;/span&gt; docPart = package.GetPart(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;Uri&lt;/span&gt;(DOC_URL, &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;UriKind&lt;/span&gt;.Relative));&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; &lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;XmlDocument&lt;/span&gt; document = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;XmlDocument&lt;/span&gt;();&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;document.Load(docPart.GetStream());&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; &lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;XmlNamespaceManager&lt;/span&gt; nsm = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;XmlNamespaceManager&lt;/span&gt;(document.NameTable);&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;nsm.AddNamespace(&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;&amp;quot;w&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;&amp;quot;&lt;a href=&quot;http://schemas.openxmlformats.org/wordprocessingml/2006/main&quot;&gt;http://schemas.openxmlformats.org/wordprocessingml/2006/main&lt;/a&gt;&amp;quot;&lt;/span&gt;);&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; &lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;XmlNode&lt;/span&gt; body = document.SelectSingleNode(&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;&amp;quot;/w:document/w:body&amp;quot;&lt;/span&gt;, nsm);&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; &lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; (&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;Package&lt;/span&gt; lastPackage = &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;Package&lt;/span&gt;.Open(LAST_PAGE, &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;FileMode&lt;/span&gt;.Open, &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;FileAccess&lt;/span&gt;.Read))&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;XmlDocument&lt;/span&gt; lastPage = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;XmlDocument&lt;/span&gt;();&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;                &lt;/span&gt;lastPage.Load(lastPackage.GetPart(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;Uri&lt;/span&gt;(DOC_URL, &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;UriKind&lt;/span&gt;.Relative)).GetStream());&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; &lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;XmlNode&lt;/span&gt; last = body.LastChild;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;&lt;span style=&quot;&quot;&gt;             &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;foreach&lt;/span&gt; (&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;XmlNode&lt;/span&gt; childNode &lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt; lastPage.SelectSingleNode(&lt;span style=&quot;color: rgb(163, 21, 21);&quot;&gt;&amp;quot;/w:document/w:body&amp;quot;&lt;/span&gt;, nsm).ChildNodes)&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;                &lt;/span&gt;{&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;XmlNode&lt;/span&gt; docChildNode = document.ImportNode(childNode, &lt;span style=&quot;color: blue;&quot;&gt;true&lt;/span&gt;);&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;                    &lt;/span&gt;body.InsertAfter(docChildNode, last);&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;                    &lt;/span&gt;last = docChildNode;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;                &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; &lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;document.Save(docPart.GetStream(&lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;FileMode&lt;/span&gt;.Create, &lt;span style=&quot;color: rgb(43, 145, 175);&quot;&gt;FileAccess&lt;/span&gt;.Write));&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt; &lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-size: 10pt; line-height: 115%; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;}&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;In this example, firstly what we do is we take a copy of the DocOne file into a file called MergedFile which is also time stamped. We then open up the new files, and append the contents of the body of DocTwo into the body of the MergedFile.&lt;/p&gt;  </content><link rel='replies' type='application/atom+xml' href='http://nick-howard.blogspot.com/feeds/8968224958577019807/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nick-howard.blogspot.com/2010/09/merging-word-documents-using-office.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6299626589601724719/posts/default/8968224958577019807'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6299626589601724719/posts/default/8968224958577019807'/><link rel='alternate' type='text/html' href='http://nick-howard.blogspot.com/2010/09/merging-word-documents-using-office.html' title='Merging Word Documents using Office Open XML (OOXML)'/><author><name>aus</name><uri>http://www.blogger.com/profile/16413691884245062146</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6299626589601724719.post-4720344746069625197</id><published>2010-09-24T14:03:00.000+10:00</published><updated>2010-09-24T14:04:32.860+10:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="OOXML"/><category scheme="http://www.blogger.com/atom/ns#" term="Open Office XML"/><title type='text'>Office Open XML (OOXML)</title><content type='html'>&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;b&gt;What is Office Open XML?&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;Office Open XML or OOXML is an &lt;a href=&quot;http://www.ecma-international.org/&quot;&gt;Ecma&lt;/a&gt; standard which can be used to represent word processing documents, spreadsheets and presentations. It was originally developed by &lt;a href=&quot;http://www.microsoft.com/&quot;&gt;Microsoft&lt;/a&gt;, and was released in Office 2007 onwards. A Microsoft office open xml document is signified by the x on the end of the extension, for example docx for a word document (traditionally doc) or xlsx for an excel spreadsheet (traditionally xls).&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;These Microsoft office documents are actually a packaged compressed file containing all the OOXML files to represent the document. With your file compression utility you can open to view, or extract the files from the files. Or even more simply, you can rename the file to have a zip extension and then just double click to view its contents&lt;/div&gt;&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;b&gt;What can I use Office Open XML for?&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;Actually, OOXML is very useful. It can be used to create new, edit existing, or for extracting data from documents. You could setup a word document template and use it in a mail merge type scenario pragmatically, or you could extract data out of an excel spreadsheet to be then used for other purposes.&lt;/div&gt;&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;b&gt;But can&#39;t I already do all that in other ways?&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;There are of course many ways to solve a problem, but Office Open XML provides a simple approach to achieve all of these aims through a single technology. Automation is of course one other way, but you can suffer DLL hell when different clients have different versions of office, and as well as the fact that Microsoft does not advise to use Office automation in server applications. You can of course use Jet/Ace OLEDB to access excel spreadsheets, but this of course doesn&#39;t work with other document types.&lt;/div&gt;&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;By using Office Open XML you have a standard flexible and safe way in which to access and manipulate all aspects of Office documents. There is much more support for dealing with XML, and there are many ways in which you can use it.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nick-howard.blogspot.com/feeds/4720344746069625197/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nick-howard.blogspot.com/2010/09/office-open-xml-ooxml.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6299626589601724719/posts/default/4720344746069625197'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6299626589601724719/posts/default/4720344746069625197'/><link rel='alternate' type='text/html' href='http://nick-howard.blogspot.com/2010/09/office-open-xml-ooxml.html' title='Office Open XML (OOXML)'/><author><name>aus</name><uri>http://www.blogger.com/profile/16413691884245062146</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6299626589601724719.post-4032424646092183718</id><published>2010-09-24T11:50:00.000+10:00</published><updated>2010-09-24T11:50:26.280+10:00</updated><title type='text'>Just Another C# Blog - The Beginnings</title><content type='html'>&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;With thousands of C# blogs already out there, I am not going to pretend that mine offers anything new or exciting that hasn&#39;t already been blogged on in the past. My aim instead is to write about the particular technologies I use and how I use them, and over time I hope to build up a comprehensive catalogue of articles relating to these technologies.&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://nick-howard.blogspot.com/feeds/4032424646092183718/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nick-howard.blogspot.com/2010/09/just-another-c-blog-beginnings.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6299626589601724719/posts/default/4032424646092183718'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6299626589601724719/posts/default/4032424646092183718'/><link rel='alternate' type='text/html' href='http://nick-howard.blogspot.com/2010/09/just-another-c-blog-beginnings.html' title='Just Another C# Blog - The Beginnings'/><author><name>aus</name><uri>http://www.blogger.com/profile/16413691884245062146</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>