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

<channel>
	<title>JSEDLAK &#187; WPF</title>
	<atom:link href="http://jsedlak.org/tag/wpf/feed/" rel="self" type="application/rss+xml" />
	<link>http://jsedlak.org</link>
	<description></description>
	<lastBuildDate>Wed, 01 Sep 2010 00:44:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Korkboard 1.1.0.0</title>
		<link>http://jsedlak.org/2010/07/13/korkboard-1-1-0-0/</link>
		<comments>http://jsedlak.org/2010/07/13/korkboard-1-1-0-0/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 10:31:39 +0000</pubDate>
		<dc:creator>John Sedlak</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[Korkboard]]></category>

		<guid isPermaLink="false">http://jsedlak.org/?p=664</guid>
		<description><![CDATA[Korkboard has been updated to version 1.1.0.0 after a couple changes and fixes. If you have already installed Korkboard, it will check for the update next time you run it. It will install the update the next (next) time it is run. If you do not have Korkboard, you can download it for free! Here [...]]]></description>
			<content:encoded><![CDATA[<p>Korkboard has been updated to version 1.1.0.0 after a couple changes and fixes. If you have already installed Korkboard, it will check for the update next time you run it. It will install the update the next (next) time it is run. If you do not have Korkboard, you can download it for free!</p>
<a href="http://jsedlak.org/wp-content/plugins/download-monitor/download.php?id=25" title="Downloaded 177 times.">Korkboard v1.1.0.0 (177)</a>
<p>Here is a full list of the changes made since 1.0.0.4:</p>
<ul>
<li>Added drag and drop sorting.</li>
<li>Added item pinning (will stay at the top).</li>
<li>Added settings for turning off (and on) certain data formats.</li>
<li>Added a &#8220;Clear Korkboard&#8221; button to clear all non-pinned and unselected items from the list</li>
<li>Fixed current item selection for when items are selected outside the application</li>
<li>Fixed text alignment issues in the settings page</li>
</ul>
<p>I have also changed the download to point to the ClickOnce EXE file instead of the Application file. This should fix any issues with non-IE browsers. Thanks to <a href="http://www.istartedsomething.com/">Long Zheng</a> and <a href="http://www.metrotwit.com/">MetroTwit</a> for this idea.</p>
]]></content:encoded>
			<wfw:commentRss>http://jsedlak.org/2010/07/13/korkboard-1-1-0-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VS2010 is Looking Sexy</title>
		<link>http://jsedlak.org/2009/02/24/vs2010-is-looking-sexy/</link>
		<comments>http://jsedlak.org/2009/02/24/vs2010-is-looking-sexy/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 02:34:23 +0000</pubDate>
		<dc:creator>John Sedlak</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[VS2010]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://jsedlak.com/?p=167</guid>
		<description><![CDATA[As Jason Zander shows on his blog, Visual Studio 2010 is looking gorgeous in its WPF kit. The added capabilities of the IDE and the power extensions now have will put this software above and beyond the rest for many years. If Microsoft still does one thing brilliantly, it is write great IDE software.]]></description>
			<content:encoded><![CDATA[<p>As Jason Zander shows <a href="http://blogs.msdn.com/jasonz/archive/2009/02/20/a-new-look-for-visual-studio-2010.aspx">on his blog</a>, Visual Studio 2010 is looking gorgeous in its WPF kit. The added capabilities of the IDE and the power extensions now have  will put this software above and beyond the rest for many years. If Microsoft still does one thing brilliantly, it is write great IDE software.</p>
]]></content:encoded>
			<wfw:commentRss>http://jsedlak.org/2009/02/24/vs2010-is-looking-sexy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Spark of Genius?</title>
		<link>http://jsedlak.org/2008/12/09/a-spark-of-genius/</link>
		<comments>http://jsedlak.org/2008/12/09/a-spark-of-genius/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 01:44:26 +0000</pubDate>
		<dc:creator>John Sedlak</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Versionator]]></category>

		<guid isPermaLink="false">http://jsedlak.com/?p=150</guid>
		<description><![CDATA[Knowing how frameworks are designed and developed definately has its benefits. Awhile ago I spent some time looking into how DependencyObject and DependencyProperty work in WPF. Essentially, many of the properties are not simple properties but rather facades for method invocations. Fast forward to today when I was working on Versionator, an application I am [...]]]></description>
			<content:encoded><![CDATA[<p>Knowing how frameworks are designed and developed definately has its benefits. Awhile ago I spent some time looking into how DependencyObject and DependencyProperty work in WPF. Essentially, many of the properties are not simple properties but rather facades for method invocations.</p>
<p>Fast forward to today when I was working on Versionator, an application I am writing to help me manage my many projects&#8217; versions. The problem is that project information files (AssemblyInfo.cs) are not straight forward in terms of parsing. They are merely text files, awkward and malformed code files in fact. To be able to support many properties so easily, I came up with a scheme to parse, manage and save the projects&#8217; properties in the file.</p>
<p>What I do is parse the properties, extracting the data and storing it in a dictionary as &#8220;old values.&#8221; At the same time I create a copy of the values in a &#8220;current values&#8221; dictionary. As new values come in, I channel them through properties, then Get and Set methods which access the &#8220;current values&#8221; dictionary. When it comes time to save I have to do some management of the data based on whether or not the property was empty, non-existant or is being changed to empty. It is simple to say that it would have taken me a lot longer if I had not taken a look at WPF. So was it a spark of genius? Or just plain old learnedness?</p>
<p>The Code (Beware of its massive length):</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p150code2'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1502"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
</pre></td><td class="code" id="p150code2"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> FocusedGames<span style="color: #008000;">.</span><span style="color: #0000FF;">Versionator</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Data</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> ProjectInfo
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">enum</span> Properties <span style="color: #008000;">:</span> <span style="color: #6666cc; font-weight: bold;">ushort</span>
        <span style="color: #008000;">&#123;</span>
            Title <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>,
            Description <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>,
            Company <span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span>,
            Product <span style="color: #008000;">=</span> <span style="color: #FF0000;">3</span>,
            Copyright <span style="color: #008000;">=</span> <span style="color: #FF0000;">4</span>,
            Trademark <span style="color: #008000;">=</span> <span style="color: #FF0000;">5</span>,
            AssemblyVersion <span style="color: #008000;">=</span> <span style="color: #FF0000;">6</span>,
            FileVersion <span style="color: #008000;">=</span> <span style="color: #FF0000;">7</span>,
            Guid <span style="color: #008000;">=</span> <span style="color: #FF0000;">8</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> lookups <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span> <span style="color: #666666;">&quot;AssemblyTitle&quot;</span>, <span style="color: #666666;">&quot;AssemblyDescription&quot;</span>, <span style="color: #666666;">&quot;AssemblyCompany&quot;</span>, <span style="color: #666666;">&quot;AssemblyProduct&quot;</span>, <span style="color: #666666;">&quot;AssemblyCopyright&quot;</span>, <span style="color: #666666;">&quot;AssemblyTrademark&quot;</span>, <span style="color: #666666;">&quot;AssemblyVersion&quot;</span>, <span style="color: #666666;">&quot;AssemblyFileVersion&quot;</span>, <span style="color: #666666;">&quot;Guid&quot;</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">ushort</span>, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> propertyValues <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">ushort</span>, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">ushort</span>, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> oldValues <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">ushort</span>, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> ProjectInfo FromFile<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> filename<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> ProjectInfo<span style="color: #008000;">&#40;</span>filename<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> ProjectInfo<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            Array enumValues <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">Enum</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetValues</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">typeof</span> <span style="color: #008000;">&#40;</span>Properties<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">foreach</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">ushort</span> prop <span style="color: #0600FF; font-weight: bold;">in</span> enumValues<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                propertyValues<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>prop, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                oldValues<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>prop, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> ProjectInfo<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> filename<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">:</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            Load<span style="color: #008000;">&#40;</span>filename<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080;">#region Getting and Setting Project Properties</span>
        <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> SetProperty<span style="color: #008000;">&#40;</span>Properties prop, <span style="color: #6666cc; font-weight: bold;">string</span> value<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            propertyValues<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">ushort</span><span style="color: #008000;">&#41;</span> prop<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetProperty<span style="color: #008000;">&#40;</span>Properties prop<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #6666cc; font-weight: bold;">string</span> newValue <span style="color: #008000;">=</span> propertyValues<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">ushort</span><span style="color: #008000;">&#41;</span> prop<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #008000;">&#40;</span>newValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> oldValues<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">ushort</span><span style="color: #008000;">&#41;</span> prop<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">return</span> newValue<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #008080;">#endregion</span>
&nbsp;
        <span style="color: #008080;">#region Loading and Saving</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Load<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> filename<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            Filename <span style="color: #008000;">=</span> filename<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> lines <span style="color: #008000;">=</span> File<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadAllLines</span><span style="color: #008000;">&#40;</span>Filename<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            Array enumValues <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">Enum</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetValues</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">typeof</span> <span style="color: #008000;">&#40;</span>Properties<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">foreach</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">ushort</span> prop <span style="color: #0600FF; font-weight: bold;">in</span> enumValues<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                Load<span style="color: #008000;">&#40;</span>lines, prop<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Load<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> lines, <span style="color: #6666cc; font-weight: bold;">ushort</span> lookup<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">for</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> lines<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #6666cc; font-weight: bold;">string</span> currentLine <span style="color: #008000;">=</span> lines<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
                <span style="color: #6666cc; font-weight: bold;">string</span> searchTerm <span style="color: #008000;">=</span> lookups<span style="color: #008000;">&#91;</span>lookup<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// Get the first index of the search term</span>
                <span style="color: #6666cc; font-weight: bold;">int</span> firstIndex <span style="color: #008000;">=</span> currentLine<span style="color: #008000;">.</span><span style="color: #0000FF;">IndexOf</span><span style="color: #008000;">&#40;</span>searchTerm<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// The property wasn't found, continue</span>
                <span style="color: #008080; font-style: italic;">// through the file.</span>
                <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span>firstIndex <span style="color: #008000;">==</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #0600FF; font-weight: bold;">continue</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// Now we need to extract the data out of the string!</span>
                <span style="color: #6666cc; font-weight: bold;">string</span> data <span style="color: #008000;">=</span> currentLine<span style="color: #008000;">.</span><span style="color: #0000FF;">Substring</span><span style="color: #008000;">&#40;</span>firstIndex <span style="color: #008000;">+</span> searchTerm<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TrimFront</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TrimBack</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                oldValues<span style="color: #008000;">&#91;</span>lookup<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> data<span style="color: #008000;">;</span>
                propertyValues<span style="color: #008000;">&#91;</span>lookup<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> data<span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Save<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> lines <span style="color: #008000;">=</span> File<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadAllLines</span><span style="color: #008000;">&#40;</span>Filename<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            Array enumValues <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">Enum</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetValues</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>Properties<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">ushort</span> prop <span style="color: #0600FF; font-weight: bold;">in</span> enumValues<span style="color: #008000;">&#41;</span>
                Save<span style="color: #008000;">&#40;</span>lines, prop<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            StreamWriter sw <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StreamWriter<span style="color: #008000;">&#40;</span>Filename, <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">for</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> lines<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
                sw<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>lines<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            sw<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Save<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> lines, <span style="color: #6666cc; font-weight: bold;">ushort</span> prop<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> lines<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #6666cc; font-weight: bold;">string</span> currentLine <span style="color: #008000;">=</span> lines<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
                <span style="color: #6666cc; font-weight: bold;">string</span> searchTerm <span style="color: #008000;">=</span> lookups<span style="color: #008000;">&#91;</span>prop<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// Get the first index of the search term</span>
                <span style="color: #6666cc; font-weight: bold;">int</span> firstIndex <span style="color: #008000;">=</span> currentLine<span style="color: #008000;">.</span><span style="color: #0000FF;">IndexOf</span><span style="color: #008000;">&#40;</span>searchTerm<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// The property wasn't found, continue</span>
                <span style="color: #008080; font-style: italic;">// through the file.</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>firstIndex <span style="color: #008000;">==</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #0600FF; font-weight: bold;">continue</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #6666cc; font-weight: bold;">string</span> oldValueLocal <span style="color: #008000;">=</span> oldValues<span style="color: #008000;">&#91;</span>prop<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
                <span style="color: #6666cc; font-weight: bold;">string</span> newValueLocal <span style="color: #008000;">=</span> propertyValues<span style="color: #008000;">&#91;</span>prop<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// If the old value didn't exist, we can adjust the </span>
                <span style="color: #008080; font-style: italic;">// replacement mechanism to remove the &quot;&quot; and add</span>
                <span style="color: #008080; font-style: italic;">// them back in.</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #008000;">&#40;</span>oldValueLocal<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    oldValueLocal <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\&quot;</span><span style="color: #008080; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #008000;">;</span>
                    newValueLocal <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\&quot;</span>{0}<span style="color: #008080; font-weight: bold;">\&quot;</span>&quot;</span>, newValueLocal<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// We also need to catch people emptying strings out.</span>
                <span style="color: #008080; font-style: italic;">// To do this we adjust the saving mechanism the same way.</span>
                <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #008000;">&#40;</span>newValueLocal<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    oldValueLocal <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\&quot;</span>{0}<span style="color: #008080; font-weight: bold;">\&quot;</span>&quot;</span>, oldValueLocal<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    newValueLocal <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\&quot;</span><span style="color: #008080; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// Replace the old value with the new value</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #008000;">&#40;</span>newValueLocal<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                        lines<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> lines<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Replace</span><span style="color: #008000;">&#40;</span>oldValueLocal, newValueLocal<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #008080;">#endregion</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Filename <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">private</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> AssemblyVersion
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> GetProperty<span style="color: #008000;">&#40;</span>Properties<span style="color: #008000;">.</span><span style="color: #0000FF;">AssemblyVersion</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> SetProperty<span style="color: #008000;">&#40;</span>Properties<span style="color: #008000;">.</span><span style="color: #0000FF;">AssemblyVersion</span>, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> FileVersion
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> GetProperty<span style="color: #008000;">&#40;</span>Properties<span style="color: #008000;">.</span><span style="color: #0000FF;">FileVersion</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> SetProperty<span style="color: #008000;">&#40;</span>Properties<span style="color: #008000;">.</span><span style="color: #0000FF;">FileVersion</span>, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Title 
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> GetProperty<span style="color: #008000;">&#40;</span>Properties<span style="color: #008000;">.</span><span style="color: #0000FF;">Title</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> SetProperty<span style="color: #008000;">&#40;</span>Properties<span style="color: #008000;">.</span><span style="color: #0000FF;">Title</span>, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Description
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> GetProperty<span style="color: #008000;">&#40;</span>Properties<span style="color: #008000;">.</span><span style="color: #0000FF;">Description</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> SetProperty<span style="color: #008000;">&#40;</span>Properties<span style="color: #008000;">.</span><span style="color: #0000FF;">Description</span>, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Company
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> GetProperty<span style="color: #008000;">&#40;</span>Properties<span style="color: #008000;">.</span><span style="color: #0000FF;">Company</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> SetProperty<span style="color: #008000;">&#40;</span>Properties<span style="color: #008000;">.</span><span style="color: #0000FF;">Company</span>, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Product 
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> GetProperty<span style="color: #008000;">&#40;</span>Properties<span style="color: #008000;">.</span><span style="color: #0000FF;">Product</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> SetProperty<span style="color: #008000;">&#40;</span>Properties<span style="color: #008000;">.</span><span style="color: #0000FF;">Product</span>, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Copyright
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> GetProperty<span style="color: #008000;">&#40;</span>Properties<span style="color: #008000;">.</span><span style="color: #0000FF;">Copyright</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> SetProperty<span style="color: #008000;">&#40;</span>Properties<span style="color: #008000;">.</span><span style="color: #0000FF;">Copyright</span>, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Trademark
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> GetProperty<span style="color: #008000;">&#40;</span>Properties<span style="color: #008000;">.</span><span style="color: #0000FF;">Trademark</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> SetProperty<span style="color: #008000;">&#40;</span>Properties<span style="color: #008000;">.</span><span style="color: #0000FF;">Trademark</span>, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Guid
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> GetProperty<span style="color: #008000;">&#40;</span>Properties<span style="color: #008000;">.</span><span style="color: #0000FF;">Guid</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> SetProperty<span style="color: #008000;">&#40;</span>Properties<span style="color: #008000;">.</span><span style="color: #0000FF;">Guid</span>, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>P.S. The code is not done, is not even close to being efficient or functionally complete. But it works!</p>
]]></content:encoded>
			<wfw:commentRss>http://jsedlak.org/2008/12/09/a-spark-of-genius/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Restoring LocalUserAppDataPath in WPF</title>
		<link>http://jsedlak.org/2008/08/29/restoring-localuserappdatapath-in-wpf/</link>
		<comments>http://jsedlak.org/2008/08/29/restoring-localuserappdatapath-in-wpf/#comments</comments>
		<pubDate>Fri, 29 Aug 2008 21:54:16 +0000</pubDate>
		<dc:creator>John Sedlak</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[.NET Framework]]></category>

		<guid isPermaLink="false">http://jso.fg.com/?p=376</guid>
		<description><![CDATA[With the arrival of .NET 3.5 and consequently WPF applications, Microsoft has done away with the old Application WinForms class. No longer can you call Application.LocalUserAppDataPath to get where the user&#8217;s files are stored. To restore this functionality as well as add a bit more, I have tapped into an uncommon resource: extension methods. Let&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>With the arrival of .NET 3.5 and consequently WPF applications, Microsoft has done away with the old Application WinForms class. No longer can you call Application.LocalUserAppDataPath to get where the user&#8217;s files are stored. To restore this functionality as well as add a bit more, I have tapped into an uncommon resource: extension methods. Let&#8217;s dig a little deeper, shall we?</p>
<p><span id="more-376"></span></p>
<p><b>Note:</b> You should not rely on this for accessing local data stores. Microsoft has done away with this method for a reason and relying on it in the future can cause problems.</p>
<p>The first thing we need to do is be able to get the Company Name from the assembly. Inside of a blank static class, add the following functions. I have named my class <i>ApplicationExtensions</i>.</p>
<p>Fortunately the company name is kept in an attribute:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p376code6'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3766"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code" id="p376code6"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetCompanyName<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> Assembly assembly<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> name <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> attributes <span style="color: #008000;">=</span> assembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetCustomAttributes</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>AssemblyCompanyAttribute<span style="color: #008000;">&#41;</span>, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>attributes <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&amp;&amp;</span> attributes<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        AssemblyCompanyAttribute aca <span style="color: #008000;">=</span> attributes<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> AssemblyCompanyAttribute<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>aca <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            name <span style="color: #008000;">=</span> aca<span style="color: #008000;">.</span><span style="color: #0000FF;">Company</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">return</span> name<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Note my lack of any formal error handling. I will leave this up to you to handle. For now, returning an empty string will do. Next up, we need to be able to format the version number:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p376code7'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3767"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p376code7"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetFormattedVersion<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> Assembly assembly<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> version <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">try</span><span style="color: #008000;">&#123;</span>
        Version assemblyVersion <span style="color: #008000;">=</span> assembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetName</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Version</span><span style="color: #008000;">;</span>
&nbsp;
        version <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;{0}.{1}.{2}.{3}&quot;</span>,
            assemblyVersion<span style="color: #008000;">.</span><span style="color: #0000FF;">Major</span>,
            assemblyVersion<span style="color: #008000;">.</span><span style="color: #0000FF;">Minor</span>,
            assemblyVersion<span style="color: #008000;">.</span><span style="color: #0000FF;">Build</span>,
            assemblyVersion<span style="color: #008000;">.</span><span style="color: #0000FF;">Revision</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">catch</span><span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">return</span> version<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>And finally, the LocalUserDataPath:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p376code8'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3768"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code" id="p376code8"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetLocalUserAppDataPath<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> Application application<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> path <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
&nbsp;
    Assembly assembly <span style="color: #008000;">=</span> Assembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetEntryAssembly</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>assembly <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        path <span style="color: #008000;">=</span> Path<span style="color: #008000;">.</span><span style="color: #0000FF;">Combine</span><span style="color: #008000;">&#40;</span>
            Environment<span style="color: #008000;">.</span><span style="color: #0000FF;">GetFolderPath</span><span style="color: #008000;">&#40;</span>Environment<span style="color: #008000;">.</span><span style="color: #0000FF;">SpecialFolder</span><span style="color: #008000;">.</span><span style="color: #0000FF;">LocalApplicationData</span><span style="color: #008000;">&#41;</span>,
            Path<span style="color: #008000;">.</span><span style="color: #0000FF;">Combine</span><span style="color: #008000;">&#40;</span>
                Path<span style="color: #008000;">.</span><span style="color: #0000FF;">Combine</span><span style="color: #008000;">&#40;</span>
                    assembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetCompanyName</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>,
                    assembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetName</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span>,
                assembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetFormattedVersion</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">return</span> path<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://jsedlak.org/2008/08/29/restoring-localuserappdatapath-in-wpf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
