<?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>Sharing The Point &#187; WebPart</title>
	<atom:link href="http://www.mattjimison.com/blog/category/webpart/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mattjimison.com/blog</link>
	<description>A SharePoint Developer's Blog</description>
	<lastBuildDate>Fri, 23 Oct 2009 20:03:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SharePoint 2010 WebPart Enhancements</title>
		<link>http://www.mattjimison.com/blog/2009/10/23/sharepoint-2010-webpart-enhancements/</link>
		<comments>http://www.mattjimison.com/blog/2009/10/23/sharepoint-2010-webpart-enhancements/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 19:54:44 +0000</pubDate>
		<dc:creator>mjimison</dc:creator>
				<category><![CDATA[2010]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[WebPart]]></category>

		<guid isPermaLink="false">http://www.mattjimison.com/blog/?p=85</guid>
		<description><![CDATA[It&#8217;s been too long since my last post. I struggle as a blogger because I feel my time is better spent reading bloggers like Andrew Connell, Waldek Mastykarz, Eric Shupps, and so on, rather than writing my own content. I never imagined this long of a gap between my last posts, but the recent SharePoint [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been too long since my last post. I struggle as a blogger because I feel my time is better spent reading bloggers like <a href="http://www.andrewconnell.com/blog/Default.aspx" target="_blank">Andrew Connell</a>, <a href="http://blog.mastykarz.nl/" target="_blank">Waldek Mastykarz</a>, <a href="http://www.binarywave.com/blogs/eshupps/default.aspx" target="_blank">Eric Shupps</a>, and so on, rather than writing my own content. I never imagined this long of a gap between my last posts, but the recent SharePoint conference has re-inspired me to begin writing again.</p>
<p>I was one of the lucky few who was registered and set to hit Vegas for the 2009 SharePoint conference. However, as luck would have it, the H1N1 virus had other plans for me, and I was forced to stay at home and watch all of the conference online. Although I missed out on a lot of the fun, I was able to soak in a lot of the information, and so I want to summarize some of the new features for anyone who wasn&#8217;t able to attend, or didn&#8217;t get to all of the sessions they had hope to watch.</p>
<p>Most of the content in this post came from a great session on Advanced WebPart development, which was done by Maurice Prather, from <a href="http://www.sharesquared.com/Pages/default.aspx" target="_blank">ShareSquared</a>. Here are the main points I&#8217;d like to highlight:</p>
<h2>Versioning</h2>
<p>Anyone who has had an author put a lot of content into a Content Editor WebPart, and ask the question &#8220;Why is my content not changing when I restore a version?&#8221; is going to be happy about this addition. WebParts are now versioned with pages, so you no longer are only left with the option of putting your content into the publishing content fields. There are a lot of  strong opinions out there saying the content editor WebPart shouldn&#8217;t even be used, but if you&#8217;re in an organization who has decided to continue using it, being able to version that data will be a big help. It will also be nice for keeping configuration setups for other WebParts such as the content query WebPart, where you&#8217;ve gone through revisions and want to roll back to earlier settings.</p>
<h2>Visual WebParts</h2>
<p>This is really not something new to SharePoint 2010. What&#8217;s new is Visual Studio&#8217;s excellent automation of a system many have been using for a long time. ASP.Net developers are often more comfortable when working within a designer GUI where controls can be dragged and dropped. While using CreateChildControls is perfectly valid, and still a good way to go, creating an experience where less code is written often leads to more productivity. The trick has always been the following:</p>
<ol>
<li>Create a User Control within Visual Studio</li>
<li>Push the User Control into the ControlTemplates directory inside the 12 Hive (located at: 12 Hive/Templates/ControlTemplates)</li>
<li>Create a WebPart class and use Page.LoadControl inside CreateChildControls to load in your User Control</li>
</ol>
<p>This same concept is exactly what Visual Studio is now doing for you, but its taking out many of the steps you would perform manually, and making it a much more complete experience.<br />
(Note: Visual WebParts will not work when part of a Sandboxed Solution, something i plan to recap in another post)</p>
<h2>Cross-Site Scripting Safeguards (XSS)</h2>
<p>This affects old and new WebParts, and it&#8217;s important to understand how your current solutions could be affected, even if they will still otherwise work in SharePoint 2010. Simple properties on a WebPart class are normally displayed in the Editor Toolbar (in the default Miscellaneous category if not specified). Many times a developer might take the value of a property entered in the editor, and directly output it to the screen (i.e. new LiteralControl(QuoteOfTheDay) ). The issue with this is that if any html, script, etc&#8230; were injected into this property, by outputting it to the screen, malicious code could be run that affects all users to the site. Properties now have a new RequiresDesignerPermission attribute to determine if a property needs designer permissions in order to display on the editor toolbar, and SafeControl entries now have a new SafeAgainstScript attribute to control whether a control is protected. The default behavior without specifying either is that only designers can edit the properties. When SafeAgainstScript is set to true, and RequiresDesignerPermission attribute is set to false, then and only then, can Contributors gain access to edit the property. Going forward this should help to ensure developers are properly encoding values, etc&#8230;, before they mark a control as SafeAgainstScript and set RequiresDesignerPermission to false, if they are going to be outputting properties onto the screen.</p>
<p>(Note: personalized properties will not be affected by this new addition, since they would only display for an individual user, and would not be a risk to other viewers)</p>
<h2>Miscellaneous</h2>
<p>Here are a few things to look forward that don&#8217;t necessarily warrant their own section, but are nonetheless interesting:</p>
<ul>
<li>The ASP.Net WebPart class is still the preferred class to inherit over the SharePoint WebPart class</li>
<li>More functionality is being added to the ASP.Net WebPart class</li>
<li>Developers are encouraged to deploy WebParts as features, and not directly through the solution manifest file or other means</li>
<li>Thew new enhanced WIKI allows WebParts to be dropped into anywhere inside the main content area, without having to put it into a WebPartZone (This is all happening behind-the-scenes through a dynamic zone that pushes WebParts into placeholders)</li>
</ul>
<h2>Summary</h2>
<p>I hope this has been informative to some of you as to what we have to look forward to in WebParts inside SharePoint 2010. I am sure as Beta is released in November, and the product gets to release, there will be even more  gems to discover inside this new and very promising effort from Microsoft.</p>
<p>Cheers,<br />
Matt</p>

<div class="sociable">
<div class="sociable_tagline">
<p><strong>Share this post:</strong></p>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow" id="email"  target="_blank" href="mailto:?subject=SharePoint%202010%20WebPart%20Enhancements&amp;body=http%3A%2F%2Fwww.mattjimison.com%2Fblog%2F2009%2F10%2F23%2Fsharepoint-2010-webpart-enhancements%2F" title="email"><img src="http://www.mattjimison.com/blog/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="twitter"  target="_blank" href="http://twitter.com/home?status=SharePoint%202010%20WebPart%20Enhancements%20-%20http%3A%2F%2Fwww.mattjimison.com%2Fblog%2F2009%2F10%2F23%2Fsharepoint-2010-webpart-enhancements%2F" title="Twitter"><img src="http://www.mattjimison.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="facebook"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.mattjimison.com%2Fblog%2F2009%2F10%2F23%2Fsharepoint-2010-webpart-enhancements%2F&amp;t=SharePoint%202010%20WebPart%20Enhancements" title="Facebook"><img src="http://www.mattjimison.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="del.icio.us"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.mattjimison.com%2Fblog%2F2009%2F10%2F23%2Fsharepoint-2010-webpart-enhancements%2F&amp;title=SharePoint%202010%20WebPart%20Enhancements&amp;notes=It%27s%20been%20too%20long%20since%20my%20last%20post.%20I%20struggle%20as%20a%20blogger%20because%20I%20feel%20my%20time%20is%20better%20spent%20reading%20bloggers%20like%20Andrew%20Connell%2C%20Waldek%20Mastykarz%2C%20Eric%20Shupps%2C%20and%20so%20on%2C%20rather%20than%20writing%20my%20own%20content.%20I%20never%20imagined%20this%20long%20of%20a%20" title="del.icio.us"><img src="http://www.mattjimison.com/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="digg"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.mattjimison.com%2Fblog%2F2009%2F10%2F23%2Fsharepoint-2010-webpart-enhancements%2F&amp;title=SharePoint%202010%20WebPart%20Enhancements&amp;bodytext=It%27s%20been%20too%20long%20since%20my%20last%20post.%20I%20struggle%20as%20a%20blogger%20because%20I%20feel%20my%20time%20is%20better%20spent%20reading%20bloggers%20like%20Andrew%20Connell%2C%20Waldek%20Mastykarz%2C%20Eric%20Shupps%2C%20and%20so%20on%2C%20rather%20than%20writing%20my%20own%20content.%20I%20never%20imagined%20this%20long%20of%20a%20" title="Digg"><img src="http://www.mattjimison.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="google"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.mattjimison.com%2Fblog%2F2009%2F10%2F23%2Fsharepoint-2010-webpart-enhancements%2F&amp;title=SharePoint%202010%20WebPart%20Enhancements&amp;annotation=It%27s%20been%20too%20long%20since%20my%20last%20post.%20I%20struggle%20as%20a%20blogger%20because%20I%20feel%20my%20time%20is%20better%20spent%20reading%20bloggers%20like%20Andrew%20Connell%2C%20Waldek%20Mastykarz%2C%20Eric%20Shupps%2C%20and%20so%20on%2C%20rather%20than%20writing%20my%20own%20content.%20I%20never%20imagined%20this%20long%20of%20a%20" title="Google Bookmarks"><img src="http://www.mattjimison.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow" id="stumbleupon"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.mattjimison.com%2Fblog%2F2009%2F10%2F23%2Fsharepoint-2010-webpart-enhancements%2F&amp;title=SharePoint%202010%20WebPart%20Enhancements" title="StumbleUpon"><img src="http://www.mattjimison.com/blog/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.mattjimison.com/blog/2009/10/23/sharepoint-2010-webpart-enhancements/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Twitter Search WebPart</title>
		<link>http://www.mattjimison.com/blog/2009/03/04/twitter-search-webpart/</link>
		<comments>http://www.mattjimison.com/blog/2009/03/04/twitter-search-webpart/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 05:47:05 +0000</pubDate>
		<dc:creator>mjimison</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Linq]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[WebPart]]></category>

		<guid isPermaLink="false">http://www.mattjimison.com/blog/?p=32</guid>
		<description><![CDATA[Download now: WSP Solution &#124; Source Code (zip)
I used to play in a punk rock band, and we often joked that with only so many bar chords to play, we often copied our own songs unintentionally. When you are writing a blog, it can be difficult to know when someone else has already written on [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Download now:</strong> <a href="http://www.mattjimison.com/downloads/MattJimison.Twitter.wsp">WSP Solution</a> | <a href="http://www.mattjimison.com/downloads/MattJimison.Twitter.zip">Source Code (zip)</a></p>
<p>I used to play in a punk rock band, and we often joked that with only so many bar chords to play, we often copied our own songs unintentionally. When you are writing a blog, it can be difficult to know when someone else has already written on the subject you&#8217;ve chosen, or if you&#8217;ve just coincidentally stumbled upon something already out there. I am positive there are other Twitter-related SharePoint posts written, but I haven&#8217;t seen any offer a configurable webpart like I&#8217;m about to do. If it&#8217;s been done before, I still consider the time I spent valuable, because this was a fun item to tackle.</p>
<p><strong>Finished Product Screenshots: </strong>(Click for larger images)</p>
<style type='text/css'>
			.gallery {
				margin: auto;
			}
			.gallery-item {
				float: left;
				margin-top: 10px;
				text-align: center;
				width: 50%;			}
			.gallery img {
				border: 2px solid #cfcfcf;
			}
			.gallery-caption {
				margin-left: 0;
			}
		</style>
<p>		<!-- see gallery_shortcode() in wp-includes/media.php --></p>
<div class='gallery'>
<dl class='gallery-item'>
<dt class='gallery-icon'>
				<a href='http://www.mattjimison.com/blog/wp-content/uploads/2009/03/twitter-toolpart.jpg' title='twitter-toolpart' target='_blank'><img src="http://www.mattjimison.com/blog/wp-content/uploads/2009/03/twitter-toolpart-150x150.jpg" width="150" height="150" class="attachment-thumbnail" alt="" /></a>
			</dt>
</dl>
<dl class='gallery-item'>
<dt class='gallery-icon'>
				<a href='http://www.mattjimison.com/blog/wp-content/uploads/2009/03/twitter-display.jpg' title='twitter-display' target='_blank'><img src="http://www.mattjimison.com/blog/wp-content/uploads/2009/03/twitter-display-150x150.jpg" width="150" height="150" class="attachment-thumbnail" alt="" /></a>
			</dt>
</dl>
<p><br style="clear: both" /><br />
			<br style='clear: both;' />
		</div>
<p><strong>Here are the inspirations for my post, including some of the source code for querying the Twitter Search API via Linq:</strong></p>
<ul>
<li><a href="http://weblogs.asp.net/jan/archive/2009/03/02/the-twitter-search-api-made-easy-with-linq-to-xml.aspx" target="_blank">Jan Tielens&#8217; The Twitter Search API made easy with Linq to XML</a></li>
<li><a href="http://blogs.msdn.com/roberthorvick/archive/2009/01/27/reading-twitter-data-with-c-and-linq.aspx" target="_blank">Robert Horvick&#8217;s Reading Twitter Data with C# and LINQ</a></li>
</ul>
<p><strong>Here is how I made this project my own:</strong></p>
<ol>
<li>Created a <a href="http://www.mattjimison.com/downloads/MattJimison.Twitter.wsp">solution</a> that contains a site-scoped feature for adding a Twitter Search WebPart to your site (<a href="http://www.mattjimison.com/downloads/MattJimison.Twitter.wsp">WSP available for Download</a>)</li>
<li>WebPart has the main <a href="http://apiwiki.twitter.com/Search+API+Documentation" target="_blank">Twitter search API</a> query abilities:
<ol>
<li>General search term</li>
<li>From user</li>
<li>To user</li>
<li>About user</li>
<li>Hashtag</li>
</ol>
</li>
<li>Added the ability to define a QueryString variable that overrides the webpart configuration and takes the search directly from the QueryString</li>
<li>Used caching in combination with Since_Id to cut back on amount of data being brought back with each request</li>
<li>Solution deploys a custom css file to the 12 hive, which is embedded into the head of pages that include the webpart (easy to customize for your style)</li>
<li>Enhanced the Linq query to bring back the profile images (or substitute Twitter&#8217;s default image when one is not present)</li>
<li>Added the ability to turn profile images on and off in results display</li>
<li>Used regular expressions to hyperlink usernames and urls embedded in status updates (text search returns has html stripped)</li>
<li>There are no SharePoint references in the webpart, and it inherits from the regular WebPart class, so it could easily be used in an ASP.Net 3.5 Application</li>
</ol>
<p>The <a href="http://www.mattjimison.com/downloads/MattJimison.Twitter.zip">source code</a> and <a href="http://www.mattjimison.com/downloads/MattJimison.Twitter.wsp">wsp file</a> are both available for download. You will need <a href="http://www.codeplex.com/wspbuilder" target="_blank">WSPBuilder</a> installed if you wish to work with the provided source code, as that is my choice of development tool, and since Linq, lambda expressions, etc&#8230; are used, you will also need the ASP.Net 3.5 Framework to run this webpart.</p>
<p><strong>Installation Instructions:</strong></p>
<ol>
<li>Download wsp to your server</li>
<li>Run the following stsadm commands on the solution file (Best to run in directory where you have copied the solution)
<ol>
<li>stsadm -o addsolution -filename MattJimison.Twitter.wsp</li>
<li>stsadm -o deploysolution -name MattJimison.Twitter.wsp -url <strong>http://yoursite.com</strong> -immediate -allowgacdeployment</li>
<li>stsadm -o execadmsvcjobs</li>
<li>stsadm -o activatefeature -filename TwitterSearchWebPart\feature.xml -url <strong>http://yoursite.com</strong></li>
</ol>
</li>
<li>The WebPart will be located under the group &#8216;mattjimison.com&#8217;</li>
</ol>
<hr /><strong>Closing Thoughts:</strong><br />
This was a fun project to create. There are already so many great Twitter applications out there, and I thought it would be fun to get a WebPart started. There was a lot more I wanted to do, but I might save that for a future post. Although you could derive a solution using the oob xml webpart, it would not be as configurable, utilize Since_Id that the Twitter API recommends, or be easy for a non-developer to work with. I see this webpart as a great way to keep tabs on what people are saying about something (your company for instance) or focus in on some key individual communications while remaining on your own site. Thanks for reading, and be sure to <a href="http://www.twitter.com/mjimison" target="_blank">look me up on Twitter</a>.</p>
<p>Cheers.</p>
<p>Matt</p>
<hr /><strong>Downloads</strong><br />
<a href="http://www.mattjimison.com/downloads/MattJimison.Twitter.wsp">WSP Solution</a><br />
<a href="http://www.mattjimison.com/downloads/MattJimison.Twitter.zip">Source Code (zip)</a></p>
<hr />
<strong> Source code for main webpart class:</strong></p>

<div class="wp_syntax"><table><tr><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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.ComponentModel</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Runtime.InteropServices</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text.RegularExpressions</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.Caching</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.UI</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.UI.HtmlControls</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.UI.WebControls</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.UI.WebControls.WebParts</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Xml.Linq</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> MattJimison.<span style="color: #0000FF;">Twitter</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #000000;">&#91;</span>Guid<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;d7bd616b-fa72-4299-a1c1-4c2d79f1970d&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> TwitterSearchWebPart <span style="color: #008000;">:</span> WebPart
    <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #008080;">#region Properties / Fields</span>
        <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">bool</span> m_DisplayImage <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#91;</span>Personalizable<span style="color: #000000;">&#40;</span>PersonalizationScope.<span style="color: #0000FF;">User</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebBrowsable<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>Category<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Twitter Search&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebDisplayName<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Display Profile Image&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebDescription<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Display Profile Image&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> DisplayImage
        <span style="color: #000000;">&#123;</span>
            get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> m_DisplayImage<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
            set <span style="color: #000000;">&#123;</span> m_DisplayImage <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>Personalizable<span style="color: #000000;">&#40;</span>PersonalizationScope.<span style="color: #0000FF;">User</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebBrowsable<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>Category<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Twitter Search&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebDisplayName<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Search Text&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebDescription<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Search Text&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> SearchText <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>Personalizable<span style="color: #000000;">&#40;</span>PersonalizationScope.<span style="color: #0000FF;">User</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebBrowsable<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>Category<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Twitter Search&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebDisplayName<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;From&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebDescription<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;From User&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> From <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>Personalizable<span style="color: #000000;">&#40;</span>PersonalizationScope.<span style="color: #0000FF;">User</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebBrowsable<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>Category<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Twitter Search&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebDisplayName<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;To&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebDescription<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;To User&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> To <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>Personalizable<span style="color: #000000;">&#40;</span>PersonalizationScope.<span style="color: #0000FF;">User</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebBrowsable<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>Category<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Twitter Search&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebDisplayName<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;About&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebDescription<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;About User&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> About <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>Personalizable<span style="color: #000000;">&#40;</span>PersonalizationScope.<span style="color: #0000FF;">User</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebBrowsable<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>Category<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Twitter Search&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebDisplayName<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Hashtag&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebDescription<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Hashtag&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> HashTag <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>Personalizable<span style="color: #000000;">&#40;</span>PersonalizationScope.<span style="color: #0000FF;">User</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebBrowsable<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>Category<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Twitter Search&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebDisplayName<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;QueryString Variable&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #000000;">&#91;</span>WebDescription<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;QueryString Variable&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> QueryStringVariable <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> List<span style="color: #008000;">&lt;</span>Tweet<span style="color: #008000;">&gt;</span> CachedTweets
        <span style="color: #000000;">&#123;</span>
            get
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Cache</span><span style="color: #000000;">&#91;</span>m_Query<span style="color: #000000;">&#93;</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span>List<span style="color: #008000;">&lt;</span>Tweet<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#41;</span>HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Cache</span><span style="color: #000000;">&#91;</span>m_Query<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0600FF;">else</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>Tweet<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            set
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Cache</span><span style="color: #000000;">&#91;</span>m_Query<span style="color: #000000;">&#93;</span> <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Cache</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>m_Query, value, <span style="color: #0600FF;">null</span>, DateTime.<span style="color: #0000FF;">Now</span>.<span style="color: #0000FF;">AddMinutes</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">5</span><span style="color: #000000;">&#41;</span>,
                        Cache.<span style="color: #0000FF;">NoSlidingExpiration</span>, CacheItemPriority.<span style="color: #0000FF;">Normal</span>, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0600FF;">else</span>
                <span style="color: #000000;">&#123;</span>
                    HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Cache</span><span style="color: #000000;">&#91;</span>m_Query<span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> CachedSinceId
        <span style="color: #000000;">&#123;</span>
            get
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Cache</span><span style="color: #000000;">&#91;</span>m_SinceIdPrefix <span style="color: #008000;">+</span> m_Query<span style="color: #000000;">&#93;</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Cache</span><span style="color: #000000;">&#91;</span>m_SinceIdPrefix <span style="color: #008000;">+</span> m_Query<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0600FF;">else</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">return</span> null<span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            set
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Cache</span><span style="color: #000000;">&#91;</span>m_SinceIdPrefix <span style="color: #008000;">+</span> m_Query<span style="color: #000000;">&#93;</span> <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Cache</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>m_SinceIdPrefix <span style="color: #008000;">+</span> m_Query, value, <span style="color: #0600FF;">null</span>, DateTime.<span style="color: #0000FF;">Now</span>.<span style="color: #0000FF;">AddMinutes</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">5</span><span style="color: #000000;">&#41;</span>,
                        Cache.<span style="color: #0000FF;">NoSlidingExpiration</span>, CacheItemPriority.<span style="color: #0000FF;">Normal</span>, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0600FF;">else</span>
                <span style="color: #000000;">&#123;</span>
                    HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Cache</span><span style="color: #000000;">&#91;</span>m_SinceIdPrefix <span style="color: #008000;">+</span> m_Query<span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span> m_Query <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">readonly</span> <span style="color: #FF0000;">string</span> m_DefaultProfileImage <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;http://static.twitter.com/images/default_profile_normal.png&quot;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">readonly</span> <span style="color: #FF0000;">string</span> m_SinceIdPrefix <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;SinceId::&quot;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">readonly</span> <span style="color: #FF0000;">string</span> m_UrlTemplate <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;http://search.twitter.com/search.atom?q={0}&amp;since_id={1}&quot;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> XNamespace <span style="color: #008080;">m_AtomNS </span><span style="color: #008000;">=</span> <span style="color: #666666;">&quot;http://www.w3.org/2005/Atom&quot;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> Regex m_TwitterName <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Regex<span style="color: #000000;">&#40;</span><span style="color: #666666;">@&quot;@([\w_]+)&quot;</span>, RegexOptions.<span style="color: #0000FF;">Compiled</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> Regex m_Url <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Regex<span style="color: #000000;">&#40;</span><span style="color: #666666;">@&quot;(https?://([\w-]+\.)+[\w-]+([^ ]*))&quot;</span>, RegexOptions.<span style="color: #0000FF;">Compiled</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080;">#endregion</span>
&nbsp;
        <span style="color: #008080;">#region CreateChildControls</span>
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> CreateChildControls<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">CreateChildControls</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">try</span>
            <span style="color: #000000;">&#123;</span>
                AddStylesheet<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                BuildQuery<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                DisplayResults<span style="color: #000000;">&#40;</span>GetTweets<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>Exception ex<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> LiteralControl<span style="color: #000000;">&#40;</span>ex.<span style="color: #0000FF;">Message</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;&lt;br /&gt;&quot;</span> <span style="color: #008000;">+</span>
                    ex.<span style="color: #0000FF;">StackTrace</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;&lt;br /&gt;&quot;</span> <span style="color: #008000;">+</span> ex.<span style="color: #0000FF;">Source</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #008080;">#endregion</span>
&nbsp;
        <span style="color: #008080;">#region AddStylesheet</span>
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Add stylesheet reference to page's head section</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> AddStylesheet<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">//Dynamically add css reference</span>
            HtmlLink cssLink <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlLink<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            cssLink.<span style="color: #0000FF;">Href</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;~/_layouts/MattJimison/css/twitter.css&quot;</span><span style="color: #008000;">;</span>
            cssLink.<span style="color: #0000FF;">Attributes</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;rel&quot;</span>, <span style="color: #666666;">&quot;Stylesheet&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            cssLink.<span style="color: #0000FF;">Attributes</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;type&quot;</span>, <span style="color: #666666;">&quot;text/css&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            cssLink.<span style="color: #0000FF;">Attributes</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;media&quot;</span>, <span style="color: #666666;">&quot;all&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Page.<span style="color: #0000FF;">Header</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>cssLink<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #008080;">#endregion</span>
&nbsp;
        <span style="color: #008080;">#region BuildQuery</span>
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Build dynamic query or read from querystring</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> BuildQuery<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">//If Querystring variable is set, read from QueryString</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>QueryStringVariable<span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span>
                <span style="color: #008000;">!</span><span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Request</span>.<span style="color: #0000FF;">QueryString</span><span style="color: #000000;">&#91;</span>QueryStringVariable<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                m_Query <span style="color: #008000;">=</span> HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Request</span>.<span style="color: #0000FF;">QueryString</span><span style="color: #000000;">&#91;</span>QueryStringVariable<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF;">else</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">//Dynamically Build Query</span>
                List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;</span> patterns <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>SearchText<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                    patterns.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>SearchText<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>From<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                    patterns.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;from:&quot;</span> <span style="color: #008000;">+</span> From<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>To<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                    patterns.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;to:&quot;</span> <span style="color: #008000;">+</span> To<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>About<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                    patterns.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;@&quot;</span> <span style="color: #008000;">+</span> About<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>HashTag<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                    patterns.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;#&quot;</span> <span style="color: #008000;">+</span> HashTag<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">//Join patterns with + delimiter</span>
                m_Query <span style="color: #008000;">=</span> <span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">Join</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;+&quot;</span>, patterns.<span style="color: #0000FF;">ToArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">//UrlEncode</span>
                m_Query <span style="color: #008000;">=</span> HttpUtility.<span style="color: #0000FF;">UrlEncode</span><span style="color: #000000;">&#40;</span>m_Query<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #008080;">#endregion</span>
&nbsp;
        <span style="color: #008080;">#region GetTweets</span>
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Obtain list of tweets from Twitter search API and merge with cached</span>
        <span style="color: #008080; font-style: italic;">/// items using the previous SinceId</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;returns&gt;Returns combined list of tweets&lt;/returns&gt;</span>
        <span style="color: #0600FF;">private</span> List<span style="color: #008000;">&lt;</span>Tweet<span style="color: #008000;">&gt;</span> GetTweets<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            List<span style="color: #008000;">&lt;</span>Tweet<span style="color: #008000;">&gt;</span> results <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>Tweet<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//Do not search on empty  query</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>m_Query<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #0600FF;">return</span> results<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//Retrieve cached results from same query</span>
            List<span style="color: #008000;">&lt;</span>Tweet<span style="color: #008000;">&gt;</span> oldResults <span style="color: #008000;">=</span> CachedTweets<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//Load in the search results</span>
            XDocument xDoc <span style="color: #008000;">=</span> XDocument.<span style="color: #0000FF;">Load</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span>m_UrlTemplate, m_Query, CachedSinceId<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//Populate the Tweet list</span>
            <span style="color: #008080; font-style: italic;">//Users that have default image won't have this image in search results so that is what</span>
            <span style="color: #008080; font-style: italic;">//DefaultIfEmtpy(m_DefaultProfileImage).First() is for, to point to static image</span>
            List<span style="color: #008000;">&lt;</span>Tweet<span style="color: #008000;">&gt;</span> newResults <span style="color: #008000;">=</span>
            <span style="color: #000000;">&#40;</span>from tweet <span style="color: #0600FF;">in</span> xDoc.<span style="color: #0000FF;">Descendants</span><span style="color: #000000;">&#40;</span>m_AtomNS <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;entry&quot;</span><span style="color: #000000;">&#41;</span>
             select <span style="color: #008000;">new</span> Tweet
             <span style="color: #000000;">&#123;</span>
                 Title <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>tweet.<span style="color: #0000FF;">Element</span><span style="color: #000000;">&#40;</span>m_AtomNS <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;title&quot;</span><span style="color: #000000;">&#41;</span>,
                 Published <span style="color: #008000;">=</span>
                    DateTime.<span style="color: #0000FF;">Parse</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>tweet.<span style="color: #0000FF;">Element</span><span style="color: #000000;">&#40;</span>m_AtomNS <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;published&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>,
                 Id <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>tweet.<span style="color: #0000FF;">Element</span><span style="color: #000000;">&#40;</span>m_AtomNS <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;id&quot;</span><span style="color: #000000;">&#41;</span>,
                 Link <span style="color: #008000;">=</span> tweet.<span style="color: #0000FF;">Elements</span><span style="color: #000000;">&#40;</span>m_AtomNS <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;link&quot;</span><span style="color: #000000;">&#41;</span>
                    .<span style="color: #0000FF;">Where</span><span style="color: #000000;">&#40;</span>link <span style="color: #008000;">=&gt;</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>link.<span style="color: #0000FF;">Attribute</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;rel&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;alternate&quot;</span><span style="color: #000000;">&#41;</span>
                    .<span style="color: #0000FF;">Select</span><span style="color: #000000;">&#40;</span>link <span style="color: #008000;">=&gt;</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>link.<span style="color: #0000FF;">Attribute</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;href&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                    .<span style="color: #0000FF;">First</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>,
                 ProfileImage <span style="color: #008000;">=</span> tweet.<span style="color: #0000FF;">Elements</span><span style="color: #000000;">&#40;</span>m_AtomNS <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;link&quot;</span><span style="color: #000000;">&#41;</span>
                    .<span style="color: #0000FF;">Where</span><span style="color: #000000;">&#40;</span>link <span style="color: #008000;">=&gt;</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>link.<span style="color: #0000FF;">Attribute</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;rel&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;image&quot;</span><span style="color: #000000;">&#41;</span>
                    .<span style="color: #0000FF;">Select</span><span style="color: #000000;">&#40;</span>link <span style="color: #008000;">=&gt;</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>link.<span style="color: #0000FF;">Attribute</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;href&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                    .<span style="color: #0000FF;">DefaultIfEmpty</span><span style="color: #000000;">&#40;</span>m_DefaultProfileImage<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">First</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>,
                 Author <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>from author <span style="color: #0600FF;">in</span> tweet.<span style="color: #0000FF;">Descendants</span><span style="color: #000000;">&#40;</span>m_AtomNS <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;author&quot;</span><span style="color: #000000;">&#41;</span>
                           select <span style="color: #008000;">new</span> Author
                           <span style="color: #000000;">&#123;</span>
                               Name <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>author.<span style="color: #0000FF;">Element</span><span style="color: #000000;">&#40;</span>m_AtomNS <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;name&quot;</span><span style="color: #000000;">&#41;</span>,
                               Uri <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>author.<span style="color: #0000FF;">Element</span><span style="color: #000000;">&#40;</span>m_AtomNS <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;uri&quot;</span><span style="color: #000000;">&#41;</span>,
                           <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">First</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
             <span style="color: #000000;">&#125;</span>
             <span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToList</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//Concat old and new values and sort by id descending</span>
            results <span style="color: #008000;">=</span> oldResults.<span style="color: #0000FF;">Concat</span><span style="color: #000000;">&#40;</span>newResults<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">OrderByDescending</span><span style="color: #000000;">&#40;</span>tweet <span style="color: #008000;">=&gt;</span> tweet.<span style="color: #0000FF;">Id</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToList</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//Cache results when present</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>results.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">//Split the id up to grab the numerical portion</span>
                <span style="color: #008080; font-style: italic;">//Example of how it comes through: tag:search.twitter.com,2005:1282047900</span>
                <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> idParts <span style="color: #008000;">=</span> results<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Id</span>.<span style="color: #0000FF;">Split</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">':'</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                CachedSinceId <span style="color: #008000;">=</span> idParts<span style="color: #000000;">&#91;</span>idParts.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
                CachedTweets <span style="color: #008000;">=</span> results<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> results<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #008080;">#endregion</span>
&nbsp;
        <span style="color: #008080;">#region DisplayResults</span>
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Creates dynamic controls containing data</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;results&quot;&gt;List of tweets to display&lt;/param&gt;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> DisplayResults<span style="color: #000000;">&#40;</span>List<span style="color: #008000;">&lt;</span>Tweet<span style="color: #008000;">&gt;</span> results<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">//Variable setup</span>
            Literal content <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Literal<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            StringBuilder txt <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringBuilder<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">string</span> profileImage <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
            <span style="color: #FF0000;">string</span> authorName <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
            <span style="color: #FF0000;">string</span> authorUri <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
            <span style="color: #FF0000;">string</span> publishDate <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
            <span style="color: #FF0000;">string</span> link <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
            <span style="color: #FF0000;">string</span> title <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
            <span style="color: #FF0000;">string</span> bodyClass <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//Parent Panel</span>
            Panel panel <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Panel<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            panel.<span style="color: #0000FF;">CssClass</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;tweet-searchheader&quot;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//Display Header</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>m_Query<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">//Decode since m_Query is url-encoded and htmlencode for protection</span>
                txt.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;div class='tweet-search'&gt;&lt;strong&gt;Search Terms:&lt;/strong&gt; &quot;</span> <span style="color: #008000;">+</span>
                    HttpUtility.<span style="color: #0000FF;">HtmlEncode</span><span style="color: #000000;">&#40;</span>HttpUtility.<span style="color: #0000FF;">UrlDecode</span><span style="color: #000000;">&#40;</span>m_Query<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;&lt;/div&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//Display no results found</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>results.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                txt.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;div class=<span style="color: #008080; font-weight: bold;">\&quot;</span>tweet-emptysearch<span style="color: #008080; font-weight: bold;">\&quot;</span>&gt;The search returned no results.&lt;/div&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//Display header</span>
            content.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> txt.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            panel.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>content<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>panel<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//Return on empty queries</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>results.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                return<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//start ol</span>
            txt <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringBuilder<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            txt.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;ol class=<span style="color: #008080; font-weight: bold;">\&quot;</span>tweet-statuses<span style="color: #008080; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//Iterate through results and add to controls</span>
            <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>Tweet result <span style="color: #0600FF;">in</span> results<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">//Set variables</span>
                authorName <span style="color: #008000;">=</span> result.<span style="color: #0000FF;">Author</span>.<span style="color: #0000FF;">Name</span>.<span style="color: #0000FF;">Replace</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;'&quot;</span>, <span style="color: #666666;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                authorUri <span style="color: #008000;">=</span> result.<span style="color: #0000FF;">Author</span>.<span style="color: #0000FF;">Uri</span><span style="color: #008000;">;</span>
                publishDate <span style="color: #008000;">=</span> result.<span style="color: #0000FF;">Published</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;G&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                link <span style="color: #008000;">=</span> result.<span style="color: #0000FF;">Link</span><span style="color: #008000;">;</span>
                title <span style="color: #008000;">=</span> AddHyperlinks<span style="color: #000000;">&#40;</span>result.<span style="color: #0000FF;">Title</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">//Start li</span>
                txt.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;li class=<span style="color: #008080; font-weight: bold;">\&quot;</span>tweet-status<span style="color: #008080; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">//Image handling only shows when images are to be displayed</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>DisplayImage<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    profileImage <span style="color: #008000;">=</span> result.<span style="color: #0000FF;">ProfileImage</span><span style="color: #008000;">;</span>
                    txt.<span style="color: #0000FF;">AppendFormat</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;span class=<span style="color: #008080; font-weight: bold;">\&quot;</span>tweet-thumb<span style="color: #008080; font-weight: bold;">\&quot;</span>&gt;&lt;a class=<span style="color: #008080; font-weight: bold;">\&quot;</span>tweet-url<span style="color: #008080; font-weight: bold;">\&quot;</span> href=<span style="color: #008080; font-weight: bold;">\&quot;</span>{0}<span style="color: #008080; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #008000;">+</span>
                        <span style="color: #666666;">&quot;target=<span style="color: #008080; font-weight: bold;">\&quot;</span>_blank<span style="color: #008080; font-weight: bold;">\&quot;</span>&gt;&lt;img class=<span style="color: #008080; font-weight: bold;">\&quot;</span>tweet-photo<span style="color: #008080; font-weight: bold;">\&quot;</span> src=<span style="color: #008080; font-weight: bold;">\&quot;</span>{1}<span style="color: #008080; font-weight: bold;">\&quot;</span> alt=<span style="color: #008080; font-weight: bold;">\&quot;</span>{2}<span style="color: #008080; font-weight: bold;">\&quot;</span> /&gt;&lt;/a&gt;&lt;/span&gt;&quot;</span>,
                        authorUri, profileImage, authorName<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">//Author Link</span>
                bodyClass <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>DisplayImage<span style="color: #000000;">&#41;</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;tweet-statusbody&quot;</span> <span style="color: #008000;">:</span> <span style="color: #666666;">&quot;tweet-statusbodyplain&quot;</span><span style="color: #008000;">;</span>
                txt.<span style="color: #0000FF;">AppendFormat</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;span class=<span style="color: #008080; font-weight: bold;">\&quot;</span>{0}<span style="color: #008080; font-weight: bold;">\&quot;</span>&gt;&lt;strong&gt;&lt;a class=<span style="color: #008080; font-weight: bold;">\&quot;</span>screenname<span style="color: #008080; font-weight: bold;">\&quot;</span> href=<span style="color: #008080; font-weight: bold;">\&quot;</span>{1}<span style="color: #008080; font-weight: bold;">\&quot;</span> target=<span style="color: #008080; font-weight: bold;">\&quot;</span>_blank<span style="color: #008080; font-weight: bold;">\&quot;</span>&gt;{2}&lt;/a&gt;&lt;/strong&gt; &quot;</span>,
                    bodyClass, authorUri, authorName<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">//Status Message</span>
                txt.<span style="color: #0000FF;">AppendFormat</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;span class=<span style="color: #008080; font-weight: bold;">\&quot;</span>tweet-entrycontent<span style="color: #008080; font-weight: bold;">\&quot;</span>&gt;{0}&lt;/span&gt; &quot;</span>, title<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">//Footer Message</span>
                txt.<span style="color: #0000FF;">AppendFormat</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;span class=<span style="color: #008080; font-weight: bold;">\&quot;</span>tweet-entrymeta<span style="color: #008080; font-weight: bold;">\&quot;</span>&gt;&lt;a href=<span style="color: #008080; font-weight: bold;">\&quot;</span>{0}<span style="color: #008080; font-weight: bold;">\&quot;</span> class=<span style="color: #008080; font-weight: bold;">\&quot;</span>tweet-entrydate<span style="color: #008080; font-weight: bold;">\&quot;</span> target=<span style="color: #008080; font-weight: bold;">\&quot;</span>_blank<span style="color: #008080; font-weight: bold;">\&quot;</span>&gt;Posted at {1}&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&quot;</span>,
                    link, publishDate<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">//Clear Element</span>
                txt.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;div class=<span style="color: #008080; font-weight: bold;">\&quot;</span>clear<span style="color: #008080; font-weight: bold;">\&quot;</span>&gt;&lt;/div&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">//End li</span>
                txt.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;/li&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//end ol</span>
            txt.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;/ol&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//Add Content</span>
            panel <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Panel<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            panel.<span style="color: #0000FF;">CssClass</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;tweet-container&quot;</span><span style="color: #008000;">;</span>
            content <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Literal<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            content.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> txt.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            panel.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>content<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>panel<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
        <span style="color: #008080;">#endregion</span>
&nbsp;
        <span style="color: #008080;">#region AddHyperlinks</span>
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Replace @username and hyperlink text with html anchor tags</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;text&quot;&gt;status text&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;returns&gt;status text with auto hyperlinks&lt;/returns&gt;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span> AddHyperlinks<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> text<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            text <span style="color: #008000;">=</span> m_Url.<span style="color: #0000FF;">Replace</span><span style="color: #000000;">&#40;</span>text, <span style="color: #666666;">&quot;&lt;a href=<span style="color: #008080; font-weight: bold;">\&quot;</span>$1<span style="color: #008080; font-weight: bold;">\&quot;</span> target=<span style="color: #008080; font-weight: bold;">\&quot;</span>_blank<span style="color: #008080; font-weight: bold;">\&quot;</span>&gt;$1&lt;/a&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            text <span style="color: #008000;">=</span> m_TwitterName.<span style="color: #0000FF;">Replace</span><span style="color: #000000;">&#40;</span>text, <span style="color: #666666;">&quot;&lt;a href=<span style="color: #008080; font-weight: bold;">\&quot;</span>http://www.twitter.com/$1<span style="color: #008080; font-weight: bold;">\&quot;</span> target=<span style="color: #008080; font-weight: bold;">\&quot;</span>_blank<span style="color: #008080; font-weight: bold;">\&quot;</span>&gt;@$1&lt;/a&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">return</span> text<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #008080;">#endregion</span>
&nbsp;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


<div class="sociable">
<div class="sociable_tagline">
<p><strong>Share this post:</strong></p>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow" id="email"  target="_blank" href="mailto:?subject=Twitter%20Search%20WebPart&amp;body=http%3A%2F%2Fwww.mattjimison.com%2Fblog%2F2009%2F03%2F04%2Ftwitter-search-webpart%2F" title="email"><img src="http://www.mattjimison.com/blog/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="twitter"  target="_blank" href="http://twitter.com/home?status=Twitter%20Search%20WebPart%20-%20http%3A%2F%2Fwww.mattjimison.com%2Fblog%2F2009%2F03%2F04%2Ftwitter-search-webpart%2F" title="Twitter"><img src="http://www.mattjimison.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="facebook"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.mattjimison.com%2Fblog%2F2009%2F03%2F04%2Ftwitter-search-webpart%2F&amp;t=Twitter%20Search%20WebPart" title="Facebook"><img src="http://www.mattjimison.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="del.icio.us"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.mattjimison.com%2Fblog%2F2009%2F03%2F04%2Ftwitter-search-webpart%2F&amp;title=Twitter%20Search%20WebPart&amp;notes=Download%20now%3A%20WSP%20Solution%20%7C%20Source%20Code%20%28zip%29%0D%0A%0D%0AI%20used%20to%20play%20in%20a%20punk%20rock%20band%2C%20and%20we%20often%20joked%20that%20with%20only%20so%20many%20bar%20chords%20to%20play%2C%20we%20often%20copied%20our%20own%20songs%20unintentionally.%20When%20you%20are%20writing%20a%20blog%2C%20it%20can%20be%20difficult%20to%20kno" title="del.icio.us"><img src="http://www.mattjimison.com/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="digg"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.mattjimison.com%2Fblog%2F2009%2F03%2F04%2Ftwitter-search-webpart%2F&amp;title=Twitter%20Search%20WebPart&amp;bodytext=Download%20now%3A%20WSP%20Solution%20%7C%20Source%20Code%20%28zip%29%0D%0A%0D%0AI%20used%20to%20play%20in%20a%20punk%20rock%20band%2C%20and%20we%20often%20joked%20that%20with%20only%20so%20many%20bar%20chords%20to%20play%2C%20we%20often%20copied%20our%20own%20songs%20unintentionally.%20When%20you%20are%20writing%20a%20blog%2C%20it%20can%20be%20difficult%20to%20kno" title="Digg"><img src="http://www.mattjimison.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="google"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.mattjimison.com%2Fblog%2F2009%2F03%2F04%2Ftwitter-search-webpart%2F&amp;title=Twitter%20Search%20WebPart&amp;annotation=Download%20now%3A%20WSP%20Solution%20%7C%20Source%20Code%20%28zip%29%0D%0A%0D%0AI%20used%20to%20play%20in%20a%20punk%20rock%20band%2C%20and%20we%20often%20joked%20that%20with%20only%20so%20many%20bar%20chords%20to%20play%2C%20we%20often%20copied%20our%20own%20songs%20unintentionally.%20When%20you%20are%20writing%20a%20blog%2C%20it%20can%20be%20difficult%20to%20kno" title="Google Bookmarks"><img src="http://www.mattjimison.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow" id="stumbleupon"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.mattjimison.com%2Fblog%2F2009%2F03%2F04%2Ftwitter-search-webpart%2F&amp;title=Twitter%20Search%20WebPart" title="StumbleUpon"><img src="http://www.mattjimison.com/blog/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.mattjimison.com/blog/2009/03/04/twitter-search-webpart/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>
