<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2854483522136110136</id><updated>2011-07-28T14:44:28.117-07:00</updated><category term='SharePoint'/><category term='JQuery'/><category term='SharePoint 2010'/><category term='ASP.NET'/><category term='.NET'/><title type='text'>CipG Development Blog</title><subtitle type='html'>Only life is important</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://cipriangrosu.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://cipriangrosu.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>CipG</name><uri>http://www.blogger.com/profile/10220394959072227580</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://2.bp.blogspot.com/_MVYMuI2A4Qo/SV0PQ5_PljI/AAAAAAAAC0Y/dWuaB5mmfZs/S220/cipg_head_2005.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>18</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2854483522136110136.post-9059885030232445882</id><published>2010-10-21T13:32:00.001-07:00</published><updated>2010-10-21T14:25:35.280-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><title type='text'>Week range knowing week number</title><content type='html'>&lt;p&gt;In one of my applications I needed to display the range of a week knowing only the week number from a specific year. After I realize that a functionality like this is not provided out of the box I had to do some research.&lt;/p&gt;  &lt;p&gt;I started with a &lt;strong&gt;DateTime&lt;/strong&gt; extension that I founded at &lt;a title="http://stackoverflow.com/questions/38039/how-can-i-get-the-datetime-for-the-start-of-the-week" href="http://stackoverflow.com/questions/38039/how-can-i-get-the-datetime-for-the-start-of-the-week"&gt;http://stackoverflow.com/questions/38039/how-can-i-get-the-datetime-for-the-start-of-the-week&lt;/a&gt;&lt;/p&gt;  &lt;div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4; text-align: left"&gt;   &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; DateTimeExtensions&lt;/pre&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; DateTime StartOfWeek(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt; DateTime dt, DayOfWeek startOfWeek)&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; diff = dt.DayOfWeek - startOfWeek;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (diff &amp;lt; 0)&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;            diff += 7;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; dt.AddDays(-1 * diff).Date;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;} &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Ok. This will help me to find the first day of a week for a given date. Next only to test I created a console application where given a date I found the week number and after that I print the week range.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;At the beginning we have to establish the first day of the week. The reason is that in different cultures the week can start on Monday, Sunday or who knows what day.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; DayOfWeek firstDayOfWeek = DayOfWeek.Monday;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The rest of the code is simple. I added the data as string to simulate the reading from a config file. Here it is:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4; text-align: left"&gt;&lt;br /&gt;  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Linq;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Text;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Globalization;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; WeekRange&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; DateTimeExtensions&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; DateTime StartOfWeek(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt; DateTime dt, DayOfWeek startOfWeek)&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;        {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; diff = dt.DayOfWeek - startOfWeek;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (diff &amp;lt; 0)&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;                diff += 7;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; dt.AddDays(-1 * diff).Date;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;        }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    } &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Program&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; DayOfWeek firstDayOfWeek = DayOfWeek.Monday;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; GetNumberOfWeekByDate(DateTime theTime)&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;        {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            CultureInfo ciGetNumber = CultureInfo.CurrentCulture;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;            &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; returnNumber = ciGetNumber.Calendar.GetWeekOfYear(theTime, CalendarWeekRule.FirstDay, firstDayOfWeek);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; returnNumber;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;        }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; GetNumberOfWeeksInYear(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; theYear)&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;            DateTime lastMoment = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DateTime(theYear, 12, 31);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; GetNumberOfWeekByDate(lastMoment);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;        }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ShowShortPeriod(DateTime theDate, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; yearWeeksNumber)&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;            &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; fromNext = 0;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;            &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; weekNumber = GetNumberOfWeekByDate(theDate);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (yearWeeksNumber == weekNumber)&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;            {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;                DateTime firstDayOfNextYear = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DateTime(theDate.Year + 1, 1, 1);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (firstDayOfNextYear.ToShortDateString() != firstDayOfNextYear.StartOfWeek(firstDayOfWeek).ToShortDateString())&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;                {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;                    weekNumber = 1;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;                    fromNext = theDate.Year + 1;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;                }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;                &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;                {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;                    fromNext = theDate.Year;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;                }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;            &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;                fromNext = theDate.Year;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            DateTime fdt = theDate.StartOfWeek(firstDayOfWeek);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;            DateTime ldt = fdt.AddDays(6);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;            Console.Write(&lt;span style="color: #006080"&gt;&amp;quot;{2} is in week {0} from year {1}&amp;quot;&lt;/span&gt;, weekNumber, fromNext, theDate.ToString(&lt;span style="color: #006080"&gt;&amp;quot;dd-MMM-yyyy&amp;quot;&lt;/span&gt;));            &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        }        &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetWeekRange(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; yearNr, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; weekNr, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; yearWeeksNumber)&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;        {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            DateTime firstDayOfYear = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DateTime(yearNr, 1, 1);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;            DateTime firstWeekStart = firstDayOfYear.StartOfWeek(firstDayOfWeek);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;            DateTime desiredWeekStartDate = firstWeekStart.AddDays(weekNr * 7 - 7);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            DateTime desiredWeekEndDate = desiredWeekStartDate.AddDays(6);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; desiredWeekStartDate.ToString(&lt;span style="color: #006080"&gt;&amp;quot;dd-MMM-yyyy&amp;quot;&lt;/span&gt;) + &lt;span style="color: #006080"&gt;&amp;quot; to &amp;quot;&lt;/span&gt; + desiredWeekEndDate.ToString(&lt;span style="color: #006080"&gt;&amp;quot;dd-MMM-yyyy&amp;quot;&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;        {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; strCurrentDate = &lt;span style="color: #006080"&gt;&amp;quot;2010/10/21&amp;quot;&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[] strCurrentDateArray = strCurrentDate.Split(&lt;span style="color: #006080"&gt;'/'&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;            DateTime dt = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DateTime(Convert.ToInt32(strCurrentDateArray[0]), &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;                            Convert.ToInt32(strCurrentDateArray[1]), &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;                            Convert.ToInt32(strCurrentDateArray[2]));            &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;            &lt;span style="color: #008000"&gt;// print week number for a specified date&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            ShowShortPeriod(dt, GetNumberOfWeeksInYear(dt.Year));&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            &lt;span style="color: #008000"&gt;//display the week range&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;            &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; theYear = Convert.ToInt32(strCurrentDateArray[0]);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; theYearWeeksNumber = GetNumberOfWeeksInYear(theYear);            &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;            &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; weekNumber = GetNumberOfWeekByDate(dt);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;week range from {0}&amp;quot;&lt;/span&gt;, GetWeekRange(theYear, weekNumber, theYearWeeksNumber));&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            Console.ReadKey();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;        }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The output of this is:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://lh6.ggpht.com/_MVYMuI2A4Qo/TMCjU5meZXI/AAAAAAAAC54/7AvFHBq8NoI/s1600-h/result3.jpg"&gt;&lt;img title="result" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="109" alt="result" src="http://lh3.ggpht.com/_MVYMuI2A4Qo/TMCjVXMtHaI/AAAAAAAAC58/2LKc8yk9K68/result_thumb1.jpg?imgmax=800" width="635" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&amp;#160;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Hope this helps. &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2854483522136110136-9059885030232445882?l=cipriangrosu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cipriangrosu.blogspot.com/feeds/9059885030232445882/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cipriangrosu.blogspot.com/2010/10/week-range-knowing-week-number.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/9059885030232445882'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/9059885030232445882'/><link rel='alternate' type='text/html' href='http://cipriangrosu.blogspot.com/2010/10/week-range-knowing-week-number.html' title='Week range knowing week number'/><author><name>CipG</name><uri>http://www.blogger.com/profile/10220394959072227580</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://2.bp.blogspot.com/_MVYMuI2A4Qo/SV0PQ5_PljI/AAAAAAAAC0Y/dWuaB5mmfZs/S220/cipg_head_2005.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/_MVYMuI2A4Qo/TMCjVXMtHaI/AAAAAAAAC58/2LKc8yk9K68/s72-c/result_thumb1.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2854483522136110136.post-3393865350063336190</id><published>2010-10-21T13:26:00.001-07:00</published><updated>2010-10-21T13:29:31.268-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint 2010'/><title type='text'>CRUD sample for list items using WCF data services and SPLINQ</title><content type='html'>&lt;p&gt;The purpose of this post is to show how can we do CRUD operations on SharePoint 2010 lists using WCF data services. Actually SharePoint 2010 exposes list data trough REST (Representational State Transfer) service that you can consume in your projects. I will show now how can we use this in code. For this we will use also LINQ to SharePoint called SPLINQ. One advantage of this over CAML that is strong typed and an error can be discovered at compilation time for example.&lt;/p&gt;  &lt;p&gt;We have to be aware that the REST based access is not supported for external lists.&lt;/p&gt;  &lt;p&gt;For this example I created a custom list of towns that we will use. To this list I add some columns like Country, Population and Website. I also add some data.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_MVYMuI2A4Qo/TMCh6aVmjhI/AAAAAAAAC5g/IQdS6LuqVI8/s1600-h/listcolumns4.jpg"&gt;&lt;img title="listcolumns" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="265" alt="listcolumns" src="http://lh4.ggpht.com/_MVYMuI2A4Qo/TMCh7eZSMyI/AAAAAAAAC5k/X9xBYft6ELs/listcolumns_thumb2.jpg?imgmax=800" width="604" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_MVYMuI2A4Qo/TMCh8HdGK5I/AAAAAAAAC5o/z4S-pAKrqpI/s1600-h/listdefaultdata6.jpg"&gt;&lt;img title="listdefaultdata" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="169" alt="listdefaultdata" src="http://lh3.ggpht.com/_MVYMuI2A4Qo/TMCh8ux45vI/AAAAAAAAC5s/mVVLO-DLqE0/listdefaultdata_thumb4.jpg?imgmax=800" width="634" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now, knowing that the data services are located in the “&lt;strong&gt;_vti_bin&lt;/strong&gt;” directory and is called “&lt;strong&gt;ListData.svc&lt;/strong&gt;” we can start programming. First we can create a simple console application and add a service reference. Give a name to the namespace. I called this &lt;strong&gt;CFGService&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_MVYMuI2A4Qo/TMCh9xt40sI/AAAAAAAAC5w/eVkswLGoieo/s1600-h/service_reference5.jpg"&gt;&lt;img title="service_reference" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="357" alt="service_reference" src="http://lh5.ggpht.com/_MVYMuI2A4Qo/TMCh_On0lvI/AAAAAAAAC50/Z1oA1JeQ8h4/service_reference_thumb3.jpg?imgmax=800" width="438" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Next step is to add all required references to &lt;strong&gt;Microsoft.SharePoint.Linq&lt;/strong&gt; and &lt;strong&gt;System.Net&lt;/strong&gt;.     &lt;br /&gt;Now we can start writing the code and we will use the &lt;strong&gt;DataContext&lt;/strong&gt; class that was generated when we added the service reference.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;First, creating a new entry in the list. Because the &lt;strong&gt;DataContext&lt;/strong&gt; class is strongly typed it knows about our list. We also need to add the credentials. In my example I added the &lt;strong&gt;DefaultCredentials&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;We will create a new &lt;strong&gt;TownsItem&lt;/strong&gt; object and this to the context by using &lt;strong&gt;AddToTowns&lt;/strong&gt; method. At the end we have to save all the changes by calling &lt;strong&gt;SaveChanges&lt;/strong&gt;. I also added the &lt;strong&gt;url&lt;/strong&gt; as global variable.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; servUrl = &lt;span class="str"&gt;&amp;quot;http://myserver:111/sites/Test2/_vti_bin/ListData.svc&amp;quot;&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;style type="text/css"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt;	font-size: small;&lt;br /&gt;	color: black;&lt;br /&gt;	font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt;	background-color: #ffffff;&lt;br /&gt;	/*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt;	background-color: #f4f4f4;&lt;br /&gt;	width: 100%;&lt;br /&gt;	margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;br /&gt;&lt;br /&gt;&lt;div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4; text-align: left"&gt;&lt;br /&gt;  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; CreateData()&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;     CFGService.Test2DataContext ctx = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CFGService.Test2DataContext(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Uri(servUrl));&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     ctx.Credentials = CredentialCache.DefaultCredentials;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     CFGService.TownsItem town = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CFGService.TownsItem();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;     town.Name = &lt;span style="color: #006080"&gt;&amp;quot;London&amp;quot;&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     town.Country = &lt;span style="color: #006080"&gt;&amp;quot;United Kingdom&amp;quot;&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;     town.Population = 7600000;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     town.Website = &lt;span style="color: #006080"&gt;&amp;quot;http://www.london.gov.uk&amp;quot;&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     ctx.AddToTowns(town);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;     ctx.SaveChanges();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;style type="text/css"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt;	font-size: small;&lt;br /&gt;	color: black;&lt;br /&gt;	font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt;	background-color: #ffffff;&lt;br /&gt;	/*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt;	background-color: #f4f4f4;&lt;br /&gt;	width: 100%;&lt;br /&gt;	margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;To read the data existing in the list we have the function &lt;strong&gt;ReadAllData&lt;/strong&gt;. Here we have an &lt;strong&gt;IEnumerable&lt;/strong&gt; of &lt;strong&gt;TownsItem&lt;/strong&gt;. Now we iterate through the collection and display the values.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4; text-align: left"&gt;&lt;br /&gt;  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ReadAllData()&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;     CFGService.Test2DataContext ctx = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CFGService.Test2DataContext(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Uri(servUrl));&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     ctx.Credentials = CredentialCache.DefaultCredentials;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     IEnumerable&amp;lt;CFGService.TownsItem&amp;gt; towns = from t &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; ctx.Towns&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;                                               orderby t.Name&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;                                               select t;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;     &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (CFGService.TownsItem item &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; towns)&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;         Console.WriteLine(String.Format(&lt;span style="color: #006080"&gt;&amp;quot;{0} - {1} - {2} - {3}&amp;quot;&lt;/span&gt;, item.Name, item.Country, item.Population, item.Website));&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     Console.ReadKey();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;As alternative we can have this code to display only the name for example:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4; text-align: left"&gt;&lt;br /&gt;  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;var cities = from c &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; ctx.Towns&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;              select c;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt; &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (var city &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; cities)&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     Console.WriteLine(city.Name);                &lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Next, to update the Item we call the &lt;strong&gt;UpdateData&lt;/strong&gt; method. We get the item with the required name and update the population number. Need to call the &lt;strong&gt;UpdateObject&lt;/strong&gt; at the end in order to register the change on the server.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4; text-align: left"&gt;&lt;br /&gt;  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; UpdateData()&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    CFGService.Test2DataContext ctx = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CFGService.Test2DataContext(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Uri(servUrl));&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    ctx.Credentials = CredentialCache.DefaultCredentials;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    CFGService.TownsItem item = (from t &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; ctx.Towns&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;                                 &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; t.Name == &lt;span style="color: #006080"&gt;&amp;quot;London&amp;quot;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;                                 select t).Single();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    item.Population = 7700000;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    ctx.UpdateObject(item);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    ctx.SaveChanges();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;To delete we call the &lt;strong&gt;DeleteData&lt;/strong&gt; method.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4; text-align: left"&gt;&lt;br /&gt;  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; DeleteData()&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    CFGService.Test2DataContext ctx = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CFGService.Test2DataContext(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Uri(servUrl));&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    ctx.Credentials = CredentialCache.DefaultCredentials;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    CFGService.TownsItem item = (from t &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; ctx.Towns&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;                                 &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; t.Name == &lt;span style="color: #006080"&gt;&amp;quot;London&amp;quot;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;                                 select t).Single();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    ctx.DeleteObject(item);&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    ctx.SaveChanges();&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;And this is it , a simple example to implement the &lt;strong&gt;CRUD&lt;/strong&gt; operations.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2854483522136110136-3393865350063336190?l=cipriangrosu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cipriangrosu.blogspot.com/feeds/3393865350063336190/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cipriangrosu.blogspot.com/2010/10/crud-sample-for-list-items-using-wcf.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/3393865350063336190'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/3393865350063336190'/><link rel='alternate' type='text/html' href='http://cipriangrosu.blogspot.com/2010/10/crud-sample-for-list-items-using-wcf.html' title='CRUD sample for list items using WCF data services and SPLINQ'/><author><name>CipG</name><uri>http://www.blogger.com/profile/10220394959072227580</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://2.bp.blogspot.com/_MVYMuI2A4Qo/SV0PQ5_PljI/AAAAAAAAC0Y/dWuaB5mmfZs/S220/cipg_head_2005.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_MVYMuI2A4Qo/TMCh7eZSMyI/AAAAAAAAC5k/X9xBYft6ELs/s72-c/listcolumns_thumb2.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2854483522136110136.post-7217703194582571954</id><published>2010-02-16T11:00:00.001-08:00</published><updated>2010-02-16T11:02:53.203-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><title type='text'>Remove web part from web part gallery</title><content type='html'>&lt;p&gt;Sometimes you need to prevent users to add your web part to pages. You can do this simple when deactivate a feature. Removing the web part is based on assembly name.&lt;/p&gt;  &lt;div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4; text-align: left"&gt;   &lt;pre id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; FeatureDeactivating(SPFeatureReceiverProperties properties) &lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; assemblyName;        &lt;br /&gt;    assemblyName = System.Reflection.Assembly.GetExecutingAssembly().FullName;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (SPSite site = (SPSite)properties.Feature.Parent)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (SPWeb web = (SPWeb)site.OpenWeb())&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (web.CurrentUser.IsSiteAdmin)&lt;br /&gt;            {&lt;br /&gt;                List&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt; toDelete = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt;();&lt;br /&gt;                SPList list = site.GetCatalog(SPListTemplateType.WebPartCatalog);&lt;br /&gt;&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (SPListItem item &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; list.Items)&lt;br /&gt;                {                        &lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (item[&lt;span style="color: #006080"&gt;&amp;quot;WebPartAssembly&amp;quot;&lt;/span&gt;].ToString() == assemblyName)                        &lt;br /&gt;                    {&lt;br /&gt;                        toDelete.Add(item.ID);&lt;br /&gt;                        &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; toDelete)&lt;br /&gt;                {&lt;br /&gt;                    SPListItem item = list.GetItemById(i);&lt;br /&gt;                    item.Delete();&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                list.Update();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;} &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2854483522136110136-7217703194582571954?l=cipriangrosu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cipriangrosu.blogspot.com/feeds/7217703194582571954/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cipriangrosu.blogspot.com/2010/02/remove-web-part-from-web-part-gallery.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/7217703194582571954'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/7217703194582571954'/><link rel='alternate' type='text/html' href='http://cipriangrosu.blogspot.com/2010/02/remove-web-part-from-web-part-gallery.html' title='Remove web part from web part gallery'/><author><name>CipG</name><uri>http://www.blogger.com/profile/10220394959072227580</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://2.bp.blogspot.com/_MVYMuI2A4Qo/SV0PQ5_PljI/AAAAAAAAC0Y/dWuaB5mmfZs/S220/cipg_head_2005.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2854483522136110136.post-5739553966940824488</id><published>2010-02-08T12:27:00.001-08:00</published><updated>2010-02-16T11:02:53.203-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><title type='text'>Get or set User Profile property using web services</title><content type='html'>&lt;p&gt;A way of accessing User Profile properties is trough UserProfileManager. If you are an administrator you can read/update/create properties. If you are not admin then you are in trouble. You cannot read or update properties even running with elevated privileges. &lt;/p&gt;  &lt;p&gt;A solution is to give all authenticated users the right to edit their profiles: &lt;/p&gt;  &lt;li&gt;Navigate to &lt;strong&gt;Central Admin&lt;/strong&gt; &lt;/li&gt;  &lt;li&gt;Navigate to the &lt;strong&gt;Shared Service Provider&lt;/strong&gt; &lt;/li&gt;  &lt;li&gt;Under &lt;b&gt;User Profiles and My Sites&lt;/b&gt; navigate to Personalization services permissions . &lt;/li&gt;  &lt;li&gt;If the account doesn't already exist, add the account for which your sites App Domain is running under. &lt;/li&gt;  &lt;li&gt;Grant that user &lt;b&gt;Manage user profiles&lt;/b&gt; permission     &lt;p&gt;&lt;strong&gt;Another&lt;/strong&gt; way is to use web services as described below.&lt;/p&gt;    &lt;p&gt;The idea is to use the UserProfileService.asmx. (&lt;a title="http://localhost:111/_vti_bin/userprofileservice.asmx" href="http://localhost/_vti_bin/userprofileservice.asmx"&gt;http://localhost/_vti_bin/userprofileservice.asmx&lt;/a&gt;)&lt;/p&gt;    &lt;p&gt;For this as a first step you must create a web reference to this service and give a name to this reference.&lt;/p&gt;    &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_MVYMuI2A4Qo/S3rrD-RlDdI/AAAAAAAAC3w/-W-sl_IF8cg/s1600-h/image2.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="77" alt="image" src="http://lh4.ggpht.com/_MVYMuI2A4Qo/S3rrEjdzesI/AAAAAAAAC30/HG9u2T7fHq0/image_thumb.png?imgmax=800" width="244" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;    &lt;p&gt;In my case the property is a string. First instantiate your object:&lt;/p&gt;    &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; UPS.UserProfileService ups = &lt;span class="kwrd"&gt;new&lt;/span&gt; UPS.UserProfileService();&lt;/pre&gt;&lt;br /&gt;  &lt;style type="text/css"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt;	font-size: small;&lt;br /&gt;	color: black;&lt;br /&gt;	font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt;	background-color: #ffffff;&lt;br /&gt;	/*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt;	background-color: #f4f4f4;&lt;br /&gt;	width: 100%;&lt;br /&gt;	margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;br /&gt;&lt;br /&gt;  &lt;p&gt;The code is simple. Please remember that the user under the application pool is running must have the “Manage user profiles” permission.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;  &lt;div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4; text-align: left"&gt;&lt;br /&gt;    &lt;pre id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetTheCurrentUserPropertyFromWS()&lt;br /&gt;{&lt;br /&gt;    String theproperty = String.Empty;&lt;br /&gt;    ups.Url = GetServiceUrl(); &lt;br /&gt;    ups.Credentials = System.Net.CredentialCache.DefaultCredentials;&lt;br /&gt;&lt;br /&gt;    SPSecurity.RunWithElevatedPrivileges(&lt;span style="color: #0000ff"&gt;delegate&lt;/span&gt;()&lt;br /&gt;    {               &lt;br /&gt;        &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userName = System.Web.HttpContext.Current.User.Identity.Name;&lt;br /&gt;            UPS.PropertyData propertyData = GetPropertyFromUser(userName);                    &lt;br /&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (propertyData != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; propertyData.Values.Length != 0 &amp;amp;&amp;amp; !&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.IsNullOrEmpty(propertyData.Values[0].Value &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;))&lt;br /&gt;            {&lt;br /&gt;                theproperty = (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;)propertyData.Values[0].Value;                       &lt;br /&gt;            }                   &lt;br /&gt;        }&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; (Exception ex)&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; NullReferenceException(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format(&lt;span style="color: #006080"&gt;&amp;quot;Error: {0} ; User profile for user {1} not found.&amp;quot;&lt;/span&gt;&lt;br /&gt;                , ex.Message + ups.Url&lt;br /&gt;                , System.Web.HttpContext.Current.User.Identity.Name));&lt;br /&gt;        }             &lt;br /&gt;    });&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; theproperty;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; SetPropertyForCurrentUserFromWS(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; propertyAsString)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; allOK = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;br /&gt;    ups.Url = GetServiceUrl();             &lt;br /&gt;    ups.Credentials = System.Net.CredentialCache.DefaultCredentials;&lt;br /&gt;&lt;br /&gt;    SPSecurity.RunWithElevatedPrivileges(&lt;span style="color: #0000ff"&gt;delegate&lt;/span&gt;()&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;&lt;br /&gt;        {                    &lt;br /&gt;            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userName = System.Web.HttpContext.Current.User.Identity.Name;&lt;br /&gt;&lt;br /&gt;            UPS.PropertyData propertyData = GetPropertyFromUser(userName);                   &lt;br /&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (propertyData != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;br /&gt;            {                        &lt;br /&gt;                UpdatePropertyToUser(userName, propertyAsString);&lt;br /&gt;            }                    &lt;br /&gt;        }&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; (Exception ex)&lt;br /&gt;        {&lt;br /&gt;            allOK = &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; NullReferenceException(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format(&lt;span style="color: #006080"&gt;&amp;quot;User profile for user {0} not found.&amp;quot;&lt;/span&gt;&lt;br /&gt;                                            , System.Web.HttpContext.Current.User.Identity.Name + ups.Url));&lt;br /&gt;        }&lt;br /&gt;    });&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; allOK;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; UPS.PropertyData GetPropertyFromUser(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userName)&lt;br /&gt;{&lt;br /&gt;    UPS.PropertyData returnpropertyData = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;&lt;br /&gt;    UPS.PropertyData[] userpropertydata = ups.GetUserProfileByName(userName);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (UPS.PropertyData pd &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; userpropertydata)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (pd.Name == &lt;span style="color: #006080"&gt;&amp;quot;MyPropertyName&amp;quot;&lt;/span&gt;)&lt;br /&gt;        {&lt;br /&gt;            returnpropertyData = (UPS.PropertyData)pd;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; returnpropertyData;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; UpdatePropertyToUser(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userName, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; result)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #008000"&gt;// the property already exist - must only update &lt;/span&gt;&lt;br /&gt;    UPS.PropertyData[] newdata = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; UPS.PropertyData[1];&lt;br /&gt;    newdata[0] = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; UPS.PropertyData();&lt;br /&gt;    newdata[0].Name = &lt;span style="color: #006080"&gt;&amp;quot;MyPropertyName&amp;quot;&lt;/span&gt;;&lt;br /&gt;    newdata[0].Values = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; UPS.ValueData[1];&lt;br /&gt;    newdata[0].Values[0] = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; UPS.ValueData();&lt;br /&gt;    newdata[0].Values[0].Value = result;&lt;br /&gt;    newdata[0].IsValueChanged = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;br /&gt;    ups.ModifyUserPropertyByAccountName(userName, newdata);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetServiceUrl()&lt;br /&gt;{&lt;br /&gt;    StringBuilder sb = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; StringBuilder();&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; suffixUrl = &lt;span style="color: #006080"&gt;&amp;quot;_vti_bin/userprofileservice.asmx&amp;quot;&lt;/span&gt;;&lt;br /&gt;    Uri theUri = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Uri(SPContext.Current.Site.Url);           &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; prefixUrl = theUri.AbsoluteUri;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (theUri.AbsolutePath != &lt;span style="color: #006080"&gt;@&amp;quot;/&amp;quot;&lt;/span&gt;)&lt;br /&gt;    {&lt;br /&gt;        prefixUrl = prefixUrl.Replace(theUri.AbsolutePath, &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;);&lt;br /&gt;        sb.Append(prefixUrl).Append(&lt;span style="color: #006080"&gt;@&amp;quot;/&amp;quot;&lt;/span&gt;).Append(suffixUrl);&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;br /&gt;    {&lt;br /&gt;        sb.Append(prefixUrl).Append(suffixUrl);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; sb.ToString();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;  &lt;p&gt;Now you can get or set values for user properties. Remember that the property must be already created. You cannot create one using a web service.&amp;#160; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;  &lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;  &lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2854483522136110136-5739553966940824488?l=cipriangrosu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cipriangrosu.blogspot.com/feeds/5739553966940824488/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cipriangrosu.blogspot.com/2010/02/title-post-1.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/5739553966940824488'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/5739553966940824488'/><link rel='alternate' type='text/html' href='http://cipriangrosu.blogspot.com/2010/02/title-post-1.html' title='Get or set User Profile property using web services'/><author><name>CipG</name><uri>http://www.blogger.com/profile/10220394959072227580</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://2.bp.blogspot.com/_MVYMuI2A4Qo/SV0PQ5_PljI/AAAAAAAAC0Y/dWuaB5mmfZs/S220/cipg_head_2005.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_MVYMuI2A4Qo/S3rrEjdzesI/AAAAAAAAC30/HG9u2T7fHq0/s72-c/image_thumb.png?imgmax=800' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2854483522136110136.post-7941166516025215453</id><published>2009-06-25T10:04:00.001-07:00</published><updated>2009-06-25T10:05:54.255-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><title type='text'>Redirect to list item page knowing only item id, list id and web id</title><content type='html'>&lt;p&gt;Is never to late to learn something new and useful. &lt;/p&gt;  &lt;p&gt;My situation was that I had to open a list item page knowing only the ids of the item, the item container (list in my case) and web. Searching on the net I did not found what I needed. This was until a colleague told me about &lt;strong&gt;CopyUtil&lt;/strong&gt; page from SharePoint and indeed I found a very interesting article from &lt;strong&gt;Jan Tielen&lt;/strong&gt;. &lt;/p&gt;  &lt;p&gt;&lt;a title="http://weblogs.asp.net/jan/archive/2008/02/26/copyutil-aspx-a-little-sharepoint-gem.aspx" href="http://weblogs.asp.net/jan/archive/2008/02/26/copyutil-aspx-a-little-sharepoint-gem.aspx"&gt;http://weblogs.asp.net/jan/archive/2008/02/26/copyutil-aspx-a-little-sharepoint-gem.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Enjoy !&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2854483522136110136-7941166516025215453?l=cipriangrosu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cipriangrosu.blogspot.com/feeds/7941166516025215453/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cipriangrosu.blogspot.com/2009/06/redirect-to-list-item-page-knowing-only.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/7941166516025215453'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/7941166516025215453'/><link rel='alternate' type='text/html' href='http://cipriangrosu.blogspot.com/2009/06/redirect-to-list-item-page-knowing-only.html' title='Redirect to list item page knowing only item id, list id and web id'/><author><name>CipG</name><uri>http://www.blogger.com/profile/10220394959072227580</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://2.bp.blogspot.com/_MVYMuI2A4Qo/SV0PQ5_PljI/AAAAAAAAC0Y/dWuaB5mmfZs/S220/cipg_head_2005.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2854483522136110136.post-5821434760803921141</id><published>2009-06-17T11:27:00.001-07:00</published><updated>2009-06-17T11:28:40.677-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JQuery'/><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><title type='text'>Delete list items with Web Services and JQuery</title><content type='html'>&lt;p&gt;We can delete multiple list items calling &lt;strong&gt;UpdateListItems&lt;/strong&gt; web method from &lt;strong&gt;Lists.asmx&lt;/strong&gt; web service provided by SharePoint. This method can be called using JQuery &lt;strong&gt;ajax&lt;/strong&gt; method.&lt;/p&gt;  &lt;p&gt;In my example I want to delete more items from a list knowing the items id’s. In user interface I have a collection of checkboxes with “&lt;strong&gt;id&lt;/strong&gt;” attribute as id of the list item. Using a selector we obtain the collection of checkboxes, and build using the id attribute of checked one’s the batch that we will send to web method. “Tests” is the list name where I want to delete. For each item we have to add a &lt;strong&gt;Method&lt;/strong&gt; with a distinct &lt;strong&gt;id&lt;/strong&gt;.&lt;/p&gt;  &lt;div&gt;   &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;function DeleteSelected() {&lt;br /&gt;     var chkcoll = $(&lt;span style="color: #006080"&gt;&amp;quot;myselector&amp;quot;&lt;/span&gt;);&lt;br /&gt;     var fields = &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;&lt;br /&gt;     chkcoll.each(function(i){&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt;($(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;).attr(&lt;span style="color: #006080"&gt;'checked'&lt;/span&gt;) == &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;)&lt;br /&gt;        {&lt;br /&gt;            fields += &lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;Method ID=\&amp;quot;&amp;quot;&lt;/span&gt;+$(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;).attr(&lt;span style="color: #006080"&gt;'id'&lt;/span&gt;)+&lt;span style="color: #006080"&gt;&amp;quot;\&amp;quot; Cmd=\&amp;quot;Delete\&amp;quot;&amp;gt;&amp;lt;Field Name=\&amp;quot;ID\&amp;quot;&amp;gt;&amp;quot;&lt;/span&gt; + $(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;).attr(&lt;span style="color: #006080"&gt;'id'&lt;/span&gt;) + &lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;/Field&amp;gt;&amp;lt;/Method&amp;gt;&amp;quot;&lt;/span&gt;;        &lt;br /&gt;        }&lt;br /&gt;     });&lt;br /&gt;     &lt;br /&gt;     var batch = &lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;Batch OnError=\&amp;quot;Continue\&amp;quot;&amp;gt;&amp;quot;&lt;/span&gt; + fields + &lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;/Batch&amp;gt;&amp;quot;&lt;/span&gt;;&lt;br /&gt;     var soapEnv = BuildSoapEnv(batch, &lt;span style="color: #006080"&gt;'Tests'&lt;/span&gt;);             &lt;br /&gt;     theAjaxCallForUpdate(soapEnv, onSuccessDelete);    &lt;br /&gt; }  &lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;function BuildSoapEnv(batch, listname)&lt;br /&gt; {&lt;br /&gt;     var soapEnv =&lt;br /&gt;            &lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;?xml version=\&amp;quot;1.0\&amp;quot; encoding=\&amp;quot;utf-8\&amp;quot;?&amp;gt; \&lt;br /&gt;            &amp;lt;soap:Envelope xmlns:xsi=\&amp;quot;http://www.w3.org/2001/XMLSchema-instance\&amp;quot; \&lt;br /&gt;                xmlns:xsd=\&amp;quot;http://www.w3.org/2001/XMLSchema\&amp;quot; \&lt;br /&gt;                xmlns:soap=\&amp;quot;http://schemas.xmlsoap.org/soap/envelope/\&amp;quot;&amp;gt; \&lt;br /&gt;              &amp;lt;soap:Body&amp;gt; \&lt;br /&gt;                &amp;lt;UpdateListItems xmlns=\&amp;quot;http://schemas.microsoft.com/sharepoint/soap/\&amp;quot;&amp;gt; \&lt;br /&gt;                  &amp;lt;listName&amp;gt;&amp;quot;&lt;/span&gt; + listname + &lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;/listName&amp;gt; \&lt;br /&gt;                  &amp;lt;updates&amp;gt; \&lt;br /&gt;                    &amp;quot;&lt;/span&gt; + batch + &lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;/updates&amp;gt; \&lt;br /&gt;                &amp;lt;/UpdateListItems&amp;gt; \&lt;br /&gt;              &amp;lt;/soap:Body&amp;gt; \&lt;br /&gt;            &amp;lt;/soap:Envelope&amp;gt;&amp;quot;&lt;/span&gt;;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt;  soapEnv;       &lt;br /&gt; } &lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;To avoid the “The security validation” error thrown by the web service, the &lt;strong&gt;SOAPAction header&lt;/strong&gt; must be provided using &lt;strong&gt;beforeSend&lt;/strong&gt; option.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The &lt;strong&gt;functionToCall&lt;/strong&gt; is another function that you can call when the web method call is completed for some action that have to take place after. Also “&lt;strong&gt;success&lt;/strong&gt;” option can be used and perform actions only if the calling of the web method was successfully.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;function theAjaxCallForUpdate(soapEnv, functionToCall)&lt;br /&gt;{    &lt;br /&gt;    $.ajax({&lt;br /&gt;            url: textWebUrl + &lt;span style="color: #006080"&gt;&amp;quot;/_vti_bin/Lists.asmx&amp;quot;&lt;/span&gt;,&lt;br /&gt;            beforeSend: function(xhr) {&lt;br /&gt;                xhr.setRequestHeader(&lt;span style="color: #006080"&gt;&amp;quot;SOAPAction&amp;quot;&lt;/span&gt;,&lt;span style="color: #006080"&gt;&amp;quot;http://schemas.microsoft.com/sharepoint/soap/UpdateListItems&amp;quot;&lt;/span&gt;);},     &lt;br /&gt;            type: &lt;span style="color: #006080"&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;,&lt;br /&gt;            dataType: &lt;span style="color: #006080"&gt;&amp;quot;xml&amp;quot;&lt;/span&gt;,&lt;br /&gt;            data: soapEnv,&lt;br /&gt;            complete: functionToCall,&lt;br /&gt;            contentType: &lt;span style="color: #006080"&gt;&amp;quot;text/xml; charset=\&amp;quot;utf-8\&amp;quot;&amp;quot;&lt;/span&gt;&lt;br /&gt;        });   &lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;function onSuccessDelete()&lt;br /&gt; {    &lt;br /&gt;    &lt;span style="color: #008000"&gt;// do something&lt;/span&gt;&lt;br /&gt; } &lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The &lt;strong&gt;textWebUrl&lt;/strong&gt; is a variable that contain the web url. We set this from our .cs code. The scripts are stored in a separate folder in &lt;strong&gt;_layouts.&lt;/strong&gt; The entire Jquery script for calling the web service is in &lt;strong&gt;MyScript.js&lt;/strong&gt; file. This file must be copied into &lt;strong&gt;_layouts/JQuery&lt;/strong&gt; folder together with the last version of JQuery.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;StringBuilder sbJQ = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; StringBuilder();&lt;br /&gt;sbJQ.Append(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;script type=\&amp;quot;text/javascript\&amp;quot; src=\&amp;quot;_layouts/JQuery/jquery-1.3.2.min.js\&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&amp;quot;&lt;/span&gt;);                        &lt;br /&gt;sbJQ.Append(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;script type=\&amp;quot;text/javascript\&amp;quot;&amp;gt;&amp;quot;&lt;/span&gt;).Append(&lt;span style="color: #006080"&gt;&amp;quot;var textWebUrl='&amp;quot;&lt;/span&gt;+&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Web.Url+&lt;span style="color: #006080"&gt;&amp;quot;';&amp;quot;&lt;/span&gt;).Append(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;/script&amp;gt;&amp;quot;&lt;/span&gt;);            &lt;br /&gt;sbJQ.Append(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;script type=\&amp;quot;text/javascript\&amp;quot; src=\&amp;quot;_layouts/JQuery/MyScript.js\&amp;quot; &amp;gt;&amp;lt;/script&amp;gt;&amp;quot;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!Page.ClientScript.IsClientScriptBlockRegistered(&lt;span style="color: #006080"&gt;&amp;quot;scriptkey&amp;quot;&lt;/span&gt;))&lt;br /&gt;{&lt;br /&gt;    Page.ClientScript.RegisterClientScriptBlock(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.GetType(), &lt;span style="color: #006080"&gt;&amp;quot;scriptkey&amp;quot;&lt;/span&gt;, sbJQ.ToString());&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2854483522136110136-5821434760803921141?l=cipriangrosu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cipriangrosu.blogspot.com/feeds/5821434760803921141/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cipriangrosu.blogspot.com/2009/06/delete-list-items-with-web-services-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/5821434760803921141'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/5821434760803921141'/><link rel='alternate' type='text/html' href='http://cipriangrosu.blogspot.com/2009/06/delete-list-items-with-web-services-and.html' title='Delete list items with Web Services and JQuery'/><author><name>CipG</name><uri>http://www.blogger.com/profile/10220394959072227580</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://2.bp.blogspot.com/_MVYMuI2A4Qo/SV0PQ5_PljI/AAAAAAAAC0Y/dWuaB5mmfZs/S220/cipg_head_2005.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2854483522136110136.post-8658147292534095745</id><published>2009-05-20T08:10:00.001-07:00</published><updated>2009-05-20T08:30:43.347-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><title type='text'>Different behavior in New and Edit form for a custom field</title><content type='html'>&lt;p&gt;A request from a client was to create a custom field for a SharePoint list with different behavior in New form than in Edit. I was able to control this using JavaScript and the only thing left to do is to know in which form the field is rendered. &lt;/p&gt;  &lt;p&gt;For this I had to override the &lt;strong&gt;RenderFieldForInput&lt;/strong&gt; method provided by &lt;strong&gt;BaseFieldControl&lt;/strong&gt; class and check the &lt;strong&gt;SPControlMode&lt;/strong&gt;. &lt;/p&gt;  &lt;div&gt;   &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; MyCustomField : BaseFieldControl &lt;br /&gt;{&lt;br /&gt;....&lt;br /&gt;       &lt;br /&gt;&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; RenderFieldForInput(HtmlTextWriter output)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; pathToScript = String.Empty;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Field != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) pathToScript = (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ControlMode == SPControlMode.Edit) ? &lt;span style="color: #006080"&gt;&amp;quot;scriptforedit.js&amp;quot;&lt;/span&gt; : &lt;span style="color: #006080"&gt;&amp;quot;scriptforother.js&amp;quot;&lt;/span&gt;;&lt;br /&gt;    output.Write(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;script type=\&amp;quot;text/javascript\&amp;quot; src=\&amp;quot;&amp;quot;&lt;/span&gt;+ pathToScript +&lt;span style="color: #006080"&gt;&amp;quot;\&amp;quot; &amp;gt;&amp;lt;/script&amp;gt;&amp;quot;&lt;/span&gt;);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.RenderFieldForInput(output);&lt;br /&gt;}      &lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2854483522136110136-8658147292534095745?l=cipriangrosu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cipriangrosu.blogspot.com/feeds/8658147292534095745/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cipriangrosu.blogspot.com/2009/05/different-behavior-in-new-and-edit-form.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/8658147292534095745'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/8658147292534095745'/><link rel='alternate' type='text/html' href='http://cipriangrosu.blogspot.com/2009/05/different-behavior-in-new-and-edit-form.html' title='Different behavior in New and Edit form for a custom field'/><author><name>CipG</name><uri>http://www.blogger.com/profile/10220394959072227580</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://2.bp.blogspot.com/_MVYMuI2A4Qo/SV0PQ5_PljI/AAAAAAAAC0Y/dWuaB5mmfZs/S220/cipg_head_2005.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2854483522136110136.post-1166315232283856151</id><published>2009-05-12T11:06:00.001-07:00</published><updated>2009-05-12T11:07:00.771-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JQuery'/><title type='text'>Select parents in a TreeView using JQuery</title><content type='html'>&lt;p&gt;The requirement is to be able to select the parents of a node in a TreeView if a child is selected. Not only the first parent, all parents and to be able to unselect after if we want.&lt;/p&gt;  &lt;p&gt;If we look at generated source code we will notice that the parent node is in a div tag. Inside this div are the childrens inside a table/tr/td tags. So we must look for checkboxes inside a table data, table that is nested into a div. Is better to assign an attribute to the tree to be more easy to find. I added&amp;#160; the attribute “cipg” with the value “mpower”. The id of the tree is “theOne”.&lt;/p&gt;  &lt;p&gt;The code below solve this requirement. I’m sure this can be improved. &lt;/p&gt;  &lt;div&gt;   &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;lt;script type=&lt;span style="color: #006080"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt;&amp;gt; &lt;br /&gt;&lt;br /&gt;function applyToParent(parent, treeId) &lt;br /&gt;{&lt;br /&gt;    var actualId = treeId+&lt;span style="color: #006080"&gt;'theOne'&lt;/span&gt;; &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (parent.attr(&lt;span style="color: #006080"&gt;'id'&lt;/span&gt;)!= actualId) &lt;br /&gt;    { &lt;br /&gt;        var parentId = parent.attr(&lt;span style="color: #006080"&gt;'id'&lt;/span&gt;).replace(&lt;span style="color: #006080"&gt;'Nodes'&lt;/span&gt;, &lt;span style="color: #006080"&gt;''&lt;/span&gt;); &lt;br /&gt;        var theOne = $(&lt;span style="color: #006080"&gt;&amp;quot;div[cipg='mpower'] table tr td input[type='checkbox'][id^='&amp;quot;&lt;/span&gt;+parentId+&lt;span style="color: #006080"&gt;&amp;quot;']&amp;quot;&lt;/span&gt;); &lt;br /&gt;        theOne.attr(&lt;span style="color: #006080"&gt;'checked'&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;); &lt;br /&gt;        applyToParent(GetParent(theOne), treeId); &lt;br /&gt;    } &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function GetParent(theCurrent) &lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; theCurrent.parent().parent().parent().parent().parent(); &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function checkTheParent() &lt;br /&gt;{ &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt;($(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;).attr(&lt;span style="color: #006080"&gt;'checked'&lt;/span&gt;) == &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;) &lt;br /&gt;    { &lt;br /&gt;        var theParent = GetParent($(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;)); &lt;br /&gt;        var currentId = $(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;).attr(&lt;span style="color: #006080"&gt;'id'&lt;/span&gt;); &lt;br /&gt;        var treeId = currentId.substring(0,currentId.indexOf(&lt;span style="color: #006080"&gt;'theOne'&lt;/span&gt;)); &lt;br /&gt;        applyToParent(theParent, treeId); &lt;br /&gt;    } &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$(document).ready(function(){ &lt;br /&gt;    $(&lt;span style="color: #006080"&gt;&amp;quot;div[cipg='mpower'] table tr td input[type='checkbox']&amp;quot;&lt;/span&gt;).bind(&lt;span style="color: #006080"&gt;'click'&lt;/span&gt;, checkTheParent); &lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;&amp;lt;/script&amp;gt; &lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2854483522136110136-1166315232283856151?l=cipriangrosu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cipriangrosu.blogspot.com/feeds/1166315232283856151/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cipriangrosu.blogspot.com/2009/05/select-parents-in-treeview-using-jquery.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/1166315232283856151'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/1166315232283856151'/><link rel='alternate' type='text/html' href='http://cipriangrosu.blogspot.com/2009/05/select-parents-in-treeview-using-jquery.html' title='Select parents in a TreeView using JQuery'/><author><name>CipG</name><uri>http://www.blogger.com/profile/10220394959072227580</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://2.bp.blogspot.com/_MVYMuI2A4Qo/SV0PQ5_PljI/AAAAAAAAC0Y/dWuaB5mmfZs/S220/cipg_head_2005.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2854483522136110136.post-1804536560638580368</id><published>2009-05-08T10:59:00.001-07:00</published><updated>2009-05-08T11:00:51.946-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><title type='text'>Display item type icon in SPGridView after search</title><content type='html'>&lt;p&gt;I had a request to display, after a search, an icon to make a visual distinction between types of every item matching the criteria. So after creating the query I had to render the SPGridView that I fill with the results. &lt;/p&gt;  &lt;p&gt;First was the problem of obtaining the link to the icon describing the type for each search result and after that the display.&lt;/p&gt;  &lt;p&gt;For the display part I add a field to grid using TemplateField:&lt;/p&gt;  &lt;div&gt;   &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #008000"&gt;//add type image column for Type&lt;/span&gt;&lt;br /&gt;TemplateField typeCol = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; TemplateField();&lt;br /&gt;typeCol.HeaderText = “Type”;&lt;br /&gt;typeCol.ItemTemplate = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ItemType(&lt;span style="color: #006080"&gt;&amp;quot;TheId&amp;quot;&lt;/span&gt;, theList);&lt;br /&gt;grdMain.Columns.Add(typeCol); &lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Here the grdMain is the SPGridView object and “TheId” is a managed property mapped to ows_ID crawled property. If you use CAML query you have to get the ID of the object into the TheId column.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now I had to create the class that helped me to display properly the icon. This class inherit ITemplate. In the “InstantiateIn” method we have to write the following:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; InstantiateIn(Control container)&lt;br /&gt;{&lt;br /&gt;    Image img = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Image();&lt;br /&gt;    img.DataBinding += &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; EventHandler(img_DataBinding);&lt;br /&gt;    container.Controls.Add(img);&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;As parameters into the constructor of this class we receive the name of the displayed column and the list containing the searched object. Using this data we can get all needed information. Here is the code:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Text;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Web.UI;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Web.UI.WebControls;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; Microsoft.SharePoint.WebControls;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; Microsoft.SharePoint;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; Com.CFG.WebParts.SearchResultsDocs&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #008000"&gt;/// Implements a custom field which serves as a hyperlink&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; ItemType : ITemplate&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; String _ColumnDisplay;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; SPList _theList;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #cc6633"&gt;#region&lt;/span&gt; ITemplate Members&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; InstantiateIn(Control container)&lt;br /&gt;        {&lt;br /&gt;            Image img = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Image();&lt;br /&gt;            img.DataBinding += &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; EventHandler(img_DataBinding);&lt;br /&gt;            container.Controls.Add(img);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #008000"&gt;/// Initializes the hyperlink field&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;        &lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #008000"&gt;/// &amp;lt;param name=&amp;quot;ColumnDisplay&amp;quot;&amp;gt;The name of the column which contains the value to be displayed&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ItemType(String ColumnDisplay, SPList theList)&lt;br /&gt;        {     &lt;br /&gt;            _ColumnDisplay = ColumnDisplay;&lt;br /&gt;            _theList = theList; &lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; img_DataBinding(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;br /&gt;        {&lt;br /&gt;            Image img = (Image)sender;&lt;br /&gt;&lt;br /&gt;            SPGridViewRow container = (SPGridViewRow)img.NamingContainer;&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: #008000"&gt;//display name&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; itemId = (DataBinder.Eval(container.DataItem, _ColumnDisplay)).ToString();&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; imageurl = GetTypeIconLink(_theList, Int32.Parse(itemId));&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (imageurl.Length &amp;gt; 0)&lt;br /&gt;            {&lt;br /&gt;                img.ImageUrl = &lt;span style="color: #006080"&gt;&amp;quot;/_layouts/images/&amp;quot;&lt;/span&gt; + imageurl;                &lt;br /&gt;                img.Width = Unit.Pixel(16);&lt;br /&gt;                img.Visible = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;br /&gt;            }&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;br /&gt;            {&lt;br /&gt;                img.Visible = &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetTypeIconLink(SPList faqList, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; itemId)&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; returnStr = String.Empty;&lt;br /&gt;&lt;br /&gt;            SPFile afile = faqList.GetItemById(itemId).File;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (afile != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;br /&gt;            {&lt;br /&gt;                returnStr = afile.IconUrl;&lt;br /&gt;            }&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; returnStr;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #cc6633"&gt;#endregion&lt;/span&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If we do not use this class and simply want to add this column to the SPGridView using this code:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;SPBoundField acol = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SPBoundField();&lt;br /&gt;acol.HeaderText = &lt;span style="color: #006080"&gt;&amp;quot;Type&amp;quot;&lt;/span&gt;;&lt;br /&gt;acol.DataField = &lt;span style="color: #006080"&gt;&amp;quot;TheId&amp;quot;&lt;/span&gt;;&lt;br /&gt;acol.Visible = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;br /&gt;grdMain.Columns.Add(acol);   &lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;what we will see into the grid is something like &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&amp;lt;img src=”/_layouts/images/…” instead of the icon and this not what we want.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;As you noticed from the code, the way to get the path to icon is to use the IconUrl property of item attached file:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetTypeIconLink(SPList faqList, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; itemId)&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; returnStr = String.Empty;&lt;br /&gt;&lt;br /&gt;      SPFile afile = faqList.GetItemById(itemId).File;&lt;br /&gt;      &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (afile != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;br /&gt;      {&lt;br /&gt;          returnStr = afile.IconUrl;&lt;br /&gt;      }&lt;br /&gt;      &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; returnStr;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Problem solved.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2854483522136110136-1804536560638580368?l=cipriangrosu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cipriangrosu.blogspot.com/feeds/1804536560638580368/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cipriangrosu.blogspot.com/2009/05/display-item-type-icon-in-spgridview.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/1804536560638580368'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/1804536560638580368'/><link rel='alternate' type='text/html' href='http://cipriangrosu.blogspot.com/2009/05/display-item-type-icon-in-spgridview.html' title='Display item type icon in SPGridView after search'/><author><name>CipG</name><uri>http://www.blogger.com/profile/10220394959072227580</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://2.bp.blogspot.com/_MVYMuI2A4Qo/SV0PQ5_PljI/AAAAAAAAC0Y/dWuaB5mmfZs/S220/cipg_head_2005.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2854483522136110136.post-2557998954184360208</id><published>2009-05-08T10:47:00.001-07:00</published><updated>2009-05-08T11:00:51.946-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><title type='text'>Managed Property Creator tool</title><content type='html'>&lt;p&gt;In interface everybody knows to create Managed Properties used by MOSS search. Those can also be created programmatically very simple. This tool is created to be used by the admins on deployment time. Using this tool the admins save time and they are sure that all managed properties were created with no error.&lt;/p&gt;  &lt;p&gt;This tool use a configuration file describing the managed properties name, description mapped properties etc. This file must be updated before the tool is used. Here is an example of this file look like:&lt;/p&gt;  &lt;div&gt;   &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;lt;MappedProperty&amp;gt;&lt;br /&gt;  &amp;lt;Name&amp;gt;TheId&amp;lt;/Name&amp;gt;&lt;br /&gt;  &amp;lt;Description&amp;gt;My first test&amp;lt;/Description&amp;gt;&lt;br /&gt;  &amp;lt;UseInScopes&amp;gt;yes&amp;lt;/UseInScopes&amp;gt;&lt;br /&gt;  &amp;lt;DataType&amp;gt;integer&amp;lt;/DataType&amp;gt;&lt;br /&gt;  &amp;lt;CrawledProperties&amp;gt;&lt;br /&gt;    &amp;lt;CrawledProperty&amp;gt;&lt;br /&gt;      &amp;lt;Name&amp;gt;ows_ID&amp;lt;/Name&amp;gt;&lt;br /&gt;    &amp;lt;/CrawledProperty&amp;gt;&lt;br /&gt;  &amp;lt;/CrawledProperties&amp;gt;&lt;br /&gt;&amp;lt;/MappedProperty&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This will create a managed property called “TheId” that will be used in scope search and mapped to the “ows_ID” crawled property. Can be zero, one or more crawled property mapped depending on how much are specified inside the &lt;strong&gt;CrawledProperties&lt;/strong&gt; tag. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Do not forget that a property will be crawled only if contain any data.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;For using this tool you have to specify two parameters. First is “-c” or “-d” if you want to create or delete. Second is the name of the configuration file. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Having the code bellow you only have to compile and use.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Text;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; Microsoft.SharePoint;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; Microsoft.Office.Server;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; Microsoft.Office.Server.Search;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; Microsoft.Office.Server.Search.Administration;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Xml;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; ManagedPropertyCreator&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Program&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; ManagedDataType GetManagedDataType(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; strDataType)&lt;br /&gt;        {&lt;br /&gt;            ManagedDataType returnValue = ManagedDataType.Text;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;switch&lt;/span&gt; (strDataType)&lt;br /&gt;            {&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; (&lt;span style="color: #006080"&gt;&amp;quot;binary&amp;quot;&lt;/span&gt;): &lt;br /&gt;                    returnValue = ManagedDataType.Binary;&lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; (&lt;span style="color: #006080"&gt;&amp;quot;datetime&amp;quot;&lt;/span&gt;):&lt;br /&gt;                    returnValue = ManagedDataType.DateTime;&lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; (&lt;span style="color: #006080"&gt;&amp;quot;decimal&amp;quot;&lt;/span&gt;):&lt;br /&gt;                    returnValue = ManagedDataType.Decimal;&lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; (&lt;span style="color: #006080"&gt;&amp;quot;integer&amp;quot;&lt;/span&gt;):&lt;br /&gt;                    returnValue = ManagedDataType.Integer;&lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;                &lt;br /&gt;                &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; (&lt;span style="color: #006080"&gt;&amp;quot;yesno&amp;quot;&lt;/span&gt;):&lt;br /&gt;                    returnValue = ManagedDataType.YesNo;&lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;default&lt;/span&gt;:&lt;br /&gt;                    returnValue = ManagedDataType.Text;&lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;br /&gt;            }&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; returnValue;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; GetUsedInScopes(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; isused)&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (isused.CompareTo(&lt;span style="color: #006080"&gt;&amp;quot;no&amp;quot;&lt;/span&gt;) == 0) &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; Category GetSharePointCategory(Schema sspSchema)&lt;br /&gt;        {&lt;br /&gt;            CategoryCollection categories = sspSchema.AllCategories;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (Category category &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; categories)&lt;br /&gt;            {&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (category.Name.Contains(&lt;span style="color: #006080"&gt;&amp;quot;SharePoint&amp;quot;&lt;/span&gt;))&lt;br /&gt;                {&lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; category;&lt;br /&gt;                }                    &lt;br /&gt;            }&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; GetUsageMode(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; usageMode)&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (usageMode == &lt;span style="color: #006080"&gt;&amp;quot;-c&amp;quot;&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[] args)&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;&lt;br /&gt;            {&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (args.Length != 2)&lt;br /&gt;                {&lt;br /&gt;                    Usage();&lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt;;&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; isCreating = GetUsageMode(args[0]);&lt;br /&gt;&lt;br /&gt;                XmlDocument config_file = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XmlDocument();&lt;br /&gt;                config_file.Load(args[1]);&lt;br /&gt;                Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;Parsing configuration file... &amp;quot;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;                &lt;span style="color: #008000"&gt;// get the site url&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; strURL = config_file.SelectSingleNode(&lt;span style="color: #006080"&gt;&amp;quot;/root/SiteName&amp;quot;&lt;/span&gt;).InnerXml.ToString().Trim();&lt;br /&gt;&lt;br /&gt;                SearchContext context;&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (SPSite site = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SPSite(strURL))&lt;br /&gt;                {&lt;br /&gt;                    context = SearchContext.GetContext(site);&lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (context != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) Console.WriteLine(String.Format(&lt;span style="color: #006080"&gt;&amp;quot;Connected to {0}...&amp;quot;&lt;/span&gt;, strURL));&lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;br /&gt;                    {&lt;br /&gt;                        Console.WriteLine(String.Format(&lt;span style="color: #006080"&gt;&amp;quot;Error : Cannot connect to {0} !&amp;quot;&lt;/span&gt;, strURL));&lt;br /&gt;                        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt;;&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;                Schema sspSchema = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Schema(context);&lt;br /&gt;                ManagedPropertyCollection properties = sspSchema.AllManagedProperties;                &lt;br /&gt;&lt;br /&gt;                &lt;span style="color: #008000"&gt;// get mapped properties nodes&lt;/span&gt;&lt;br /&gt;                XmlNode nodeMappedProperties = config_file.SelectSingleNode(&lt;span style="color: #006080"&gt;&amp;quot;/root/MappedProperties&amp;quot;&lt;/span&gt;);&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (XmlNode mpNode &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; nodeMappedProperties.ChildNodes)&lt;br /&gt;                {&lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; mpName = mpNode.SelectSingleNode(&lt;span style="color: #006080"&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;).InnerXml.ToString().Trim();&lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; mpDesc = mpNode.SelectSingleNode(&lt;span style="color: #006080"&gt;&amp;quot;Description&amp;quot;&lt;/span&gt;).InnerXml.ToString().Trim();&lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; mpUseInScopes = mpNode.SelectSingleNode(&lt;span style="color: #006080"&gt;&amp;quot;UseInScopes&amp;quot;&lt;/span&gt;).InnerXml.ToString().Trim();&lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; mpDataType = mpNode.SelectSingleNode(&lt;span style="color: #006080"&gt;&amp;quot;DataType&amp;quot;&lt;/span&gt;).InnerXml.ToString().Trim();&lt;br /&gt;&lt;br /&gt;                    &lt;span style="color: #008000"&gt;// here code for create Managed Property&lt;/span&gt;&lt;br /&gt;                    Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;);&lt;br /&gt;                    Console.Write(String.Format(&lt;span style="color: #006080"&gt;&amp;quot;{0} &amp;lt;{1}&amp;gt; metadata property&amp;quot;&lt;/span&gt;, (isCreating)?&lt;span style="color: #006080"&gt;&amp;quot;Create&amp;quot;&lt;/span&gt;:&lt;span style="color: #006080"&gt;&amp;quot;Delete&amp;quot;&lt;/span&gt;, mpName));&lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (properties.Contains(mpName))&lt;br /&gt;                    {&lt;br /&gt;                        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (isCreating)&lt;br /&gt;                        {&lt;br /&gt;                            Console.WriteLine(String.Format(&lt;span style="color: #006080"&gt;&amp;quot;\nINFO: Managed Property with name &amp;lt;{0}&amp;gt; already exists. Will be skipped...&amp;quot;&lt;/span&gt;, mpName));&lt;br /&gt;                            &lt;span style="color: #0000ff"&gt;continue&lt;/span&gt;; &lt;span style="color: #008000"&gt;// already exist - skip this one &lt;/span&gt;&lt;br /&gt;                        }&lt;br /&gt;                    }&lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;br /&gt;                    {&lt;br /&gt;                        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!isCreating)&lt;br /&gt;                        {&lt;br /&gt;                            Console.WriteLine(String.Format(&lt;span style="color: #006080"&gt;&amp;quot;\nINFO: Managed Property with name &amp;lt;{0}&amp;gt; do not exists. Will be skipped...&amp;quot;&lt;/span&gt;, mpName));&lt;br /&gt;                            &lt;span style="color: #0000ff"&gt;continue&lt;/span&gt;; &lt;span style="color: #008000"&gt;// do not exist - skip this one &lt;/span&gt;&lt;br /&gt;                        }&lt;br /&gt;                    }&lt;br /&gt;&lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (isCreating)&lt;br /&gt;                    {&lt;br /&gt;                        ManagedProperty newMP = properties.Create(mpName, GetManagedDataType(mpDataType));&lt;br /&gt;                        newMP.Description = mpDesc;&lt;br /&gt;                        newMP.EnabledForScoping = GetUsedInScopes(mpUseInScopes);&lt;br /&gt;&lt;br /&gt;                        MappingCollection mappings = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MappingCollection();&lt;br /&gt;                        XmlNode mpCrawledProperties = mpNode.SelectSingleNode(&lt;span style="color: #006080"&gt;&amp;quot;CrawledProperties&amp;quot;&lt;/span&gt;);&lt;br /&gt;                        &lt;span style="color: #008000"&gt;// code for map with crawled properties                    &lt;/span&gt;&lt;br /&gt;                        &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (XmlNode mpCrawledProperty &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; mpCrawledProperties.ChildNodes)&lt;br /&gt;                        {&lt;br /&gt;                            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; nameCrawledProperty = mpCrawledProperty.SelectSingleNode(&lt;span style="color: #006080"&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;).InnerXml.ToString().Trim();&lt;br /&gt;&lt;br /&gt;                            &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (CrawledProperty property &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; GetSharePointCategory(sspSchema).GetAllCrawledProperties())&lt;br /&gt;                            {&lt;br /&gt;                                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (property.Name.CompareTo(nameCrawledProperty) == 0)&lt;br /&gt;                                {&lt;br /&gt;                                    mappings.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Mapping(property.Propset, property.Name, property.VariantType, newMP.PID));&lt;br /&gt;                                }&lt;br /&gt;                            }&lt;br /&gt;                        }&lt;br /&gt;                        newMP.SetMappings(mappings);&lt;br /&gt;&lt;br /&gt;                        &lt;span style="color: #008000"&gt;// do not forget to update the new created mapped property&lt;/span&gt;&lt;br /&gt;                        newMP.Update();&lt;br /&gt;                    }&lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;br /&gt;                    {&lt;br /&gt;                        &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (ManagedProperty oldMP &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; properties)&lt;br /&gt;                        {&lt;br /&gt;                            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (oldMP.Name == mpName)&lt;br /&gt;                            {&lt;br /&gt;                                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (oldMP.DeleteDisallowed)&lt;br /&gt;                                {&lt;br /&gt;                                    Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;\n DeleteDisallowed enabled for &amp;quot;&lt;/span&gt; + mpName + &lt;span style="color: #006080"&gt;&amp;quot;.  Delete failed.&amp;quot;&lt;/span&gt;);&lt;br /&gt;                                    &lt;span style="color: #0000ff"&gt;continue&lt;/span&gt;;&lt;br /&gt;                                }                                   &lt;br /&gt;                                oldMP.DeleteAllMappings();&lt;br /&gt;                                oldMP.Delete();&lt;br /&gt;                                Console.Write(&lt;span style="color: #006080"&gt;&amp;quot;\n&amp;quot;&lt;/span&gt;+mpName + &lt;span style="color: #006080"&gt;&amp;quot; deleted.&amp;quot;&lt;/span&gt;);&lt;br /&gt;                                &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;br /&gt;                            }&lt;br /&gt;                        }&lt;br /&gt;                    }&lt;br /&gt;                    Console.Write(&lt;span style="color: #006080"&gt;&amp;quot;...OK&amp;quot;&lt;/span&gt;); Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;);&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; (Exception ex)&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine(ex.ToString());&lt;br /&gt;            }&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;finally&lt;/span&gt;&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;\n All done...press any key&amp;quot;&lt;/span&gt;);Console.ReadKey();&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Usage()&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;Managed Property Creator&amp;quot;&lt;/span&gt;);&lt;br /&gt;            Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;Usage: ManagedPropertyCreator.exe &amp;lt;usage_mod&amp;gt; &amp;lt;conf_file&amp;gt;&amp;quot;&lt;/span&gt;);&lt;br /&gt;            Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;usage_mod&amp;gt; - Specify if the tool is used to create or delete metadata properties. Acceptev values: -c and -d&amp;quot;&lt;/span&gt;);&lt;br /&gt;            Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;conf_file&amp;gt; - The file that contain the configuration data.&amp;quot;&lt;/span&gt;);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;And yes, the configuration file:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;lt;?xml version=&lt;span style="color: #006080"&gt;&amp;quot;1.0&amp;quot;&lt;/span&gt; encoding=&lt;span style="color: #006080"&gt;&amp;quot;utf-8&amp;quot;&lt;/span&gt;?&amp;gt;&lt;br /&gt;&amp;lt;!-- SiteName &lt;span style="color: #0000ff"&gt;is&lt;/span&gt; the name of the site &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; the SharedServiceProvider --&amp;gt;&lt;br /&gt;&amp;lt;!-- DataType can be : binary, datetime, &lt;span style="color: #0000ff"&gt;decimal&lt;/span&gt;, integer, text, yesno --&amp;gt;&lt;br /&gt;&amp;lt;!-- UseInScopes can be : yes or no --&amp;gt;&lt;br /&gt;&amp;lt;root&amp;gt;&lt;br /&gt;  &amp;lt;SiteName&amp;gt;http:&lt;span style="color: #008000"&gt;//CF316431:555/ssp/admin&amp;lt;/SiteName&amp;gt;  &lt;/span&gt;&lt;br /&gt;  &amp;lt;MappedProperties&amp;gt;&lt;br /&gt;    &amp;lt;MappedProperty&amp;gt;&lt;br /&gt;      &amp;lt;Name&amp;gt;ManagedProperty1&amp;lt;/Name&amp;gt;&lt;br /&gt;      &amp;lt;Description&amp;gt;My first test&amp;lt;/Description&amp;gt;&lt;br /&gt;      &amp;lt;UseInScopes&amp;gt;yes&amp;lt;/UseInScopes&amp;gt;&lt;br /&gt;      &amp;lt;DataType&amp;gt;text&amp;lt;/DataType&amp;gt;&lt;br /&gt;      &amp;lt;CrawledProperties&amp;gt;&lt;br /&gt;        &amp;lt;CrawledProperty&amp;gt;&lt;br /&gt;          &amp;lt;Name&amp;gt;ows_FileLeafRef&amp;lt;/Name&amp;gt;&lt;br /&gt;        &amp;lt;/CrawledProperty&amp;gt;&lt;br /&gt;        &amp;lt;CrawledProperty&amp;gt;&lt;br /&gt;          &amp;lt;Name&amp;gt;ows_LinkedDocumentField&amp;lt;/Name&amp;gt; &lt;br /&gt;        &amp;lt;/CrawledProperty&amp;gt;&lt;br /&gt;      &amp;lt;/CrawledProperties&amp;gt;&lt;br /&gt;    &amp;lt;/MappedProperty&amp;gt;&lt;br /&gt;    &amp;lt;MappedProperty&amp;gt;&lt;br /&gt;      &amp;lt;Name&amp;gt;ManagedProperty2&amp;lt;/Name&amp;gt;&lt;br /&gt;      &amp;lt;Description&amp;gt;My first test 2&amp;lt;/Description&amp;gt;&lt;br /&gt;      &amp;lt;UseInScopes&amp;gt;yes&amp;lt;/UseInScopes&amp;gt;&lt;br /&gt;      &amp;lt;DataType&amp;gt;text&amp;lt;/DataType&amp;gt;&lt;br /&gt;      &amp;lt;CrawledProperties&amp;gt;&lt;br /&gt;        &amp;lt;CrawledProperty&amp;gt;&lt;br /&gt;          &amp;lt;Name&amp;gt;ows_FormulaField&amp;lt;/Name&amp;gt;&lt;br /&gt;        &amp;lt;/CrawledProperty&amp;gt;&lt;br /&gt;      &amp;lt;/CrawledProperties&amp;gt;&lt;br /&gt;    &amp;lt;/MappedProperty&amp;gt;&lt;br /&gt;  &amp;lt;/MappedProperties&amp;gt;&lt;br /&gt;&amp;lt;/root&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;For using you only have to type &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;ManagedPropertyCreator.exe –c mpc_config.xml&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2854483522136110136-2557998954184360208?l=cipriangrosu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cipriangrosu.blogspot.com/feeds/2557998954184360208/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cipriangrosu.blogspot.com/2009/05/managed-property-creator-tool.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/2557998954184360208'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/2557998954184360208'/><link rel='alternate' type='text/html' href='http://cipriangrosu.blogspot.com/2009/05/managed-property-creator-tool.html' title='Managed Property Creator tool'/><author><name>CipG</name><uri>http://www.blogger.com/profile/10220394959072227580</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://2.bp.blogspot.com/_MVYMuI2A4Qo/SV0PQ5_PljI/AAAAAAAAC0Y/dWuaB5mmfZs/S220/cipg_head_2005.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2854483522136110136.post-3293004460438272133</id><published>2009-05-08T10:30:00.001-07:00</published><updated>2009-05-08T11:00:51.946-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><title type='text'>Modify the fields order into New and Edit form of a list</title><content type='html'>&lt;p&gt;If you have created a list and want for some reasons to change the order of the fields into the New or Edit form you can do this using the interface or at list creation time, using the schema.xml.&lt;/p&gt;  &lt;p&gt;Using the interface you have to go to “List Settings” -&amp;gt; “Columns” -&amp;gt; “Column ordering” if your list has not content type enabled or “Settings” -&amp;gt; “Content Types”-&amp;gt; click on used content types -&amp;gt; “Columns” -&amp;gt; “Column order” in the other case.&lt;/p&gt;  &lt;p&gt;If you want to do this using schema.xml you have to go in the &amp;lt;ContentTypes&amp;gt; tag and get the ID of the referenced content type. Using this ID go to the part that describe your contenttype and referenced fields. The fields order is decided by declaration order. For example if we have: &lt;/p&gt;  &lt;div&gt;   &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;lt;FieldRefs&amp;gt;&lt;br /&gt;      &amp;lt;FieldRef ID=&lt;span style="color: #006080"&gt;&amp;quot;{BAA1289C-E3B8-11DD-95C8-C09456D89593}&amp;quot;&lt;/span&gt; Name=&lt;span style="color: #006080"&gt;&amp;quot;Field1&amp;quot;&lt;/span&gt; DisplayName=&lt;span style="color: #006080"&gt;&amp;quot;Field1&amp;quot;&lt;/span&gt; /&amp;gt;&lt;br /&gt;      &amp;lt;FieldRef ID=&lt;span style="color: #006080"&gt;&amp;quot;{E7CD97AA-E3B8-12DD-861B-5F9656D89593}&amp;quot;&lt;/span&gt; Name=&lt;span style="color: #006080"&gt;&amp;quot;Field2&amp;quot;&lt;/span&gt; DisplayName=&lt;span style="color: #006080"&gt;&amp;quot;Field2&amp;quot;&lt;/span&gt; /&amp;gt;&lt;br /&gt;      &amp;lt;FieldRef ID=&lt;span style="color: #006080"&gt;&amp;quot;{B2AB2191-2376-4B2C-938A-74AA4D14FF36}&amp;quot;&lt;/span&gt; Name=&lt;span style="color: #006080"&gt;&amp;quot;Field3&amp;quot;&lt;/span&gt; DisplayName=&lt;span style="color: #006080"&gt;&amp;quot;Field3&amp;quot;&lt;/span&gt;  /&amp;gt;&lt;br /&gt; &amp;lt;/FieldRefs&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Then the fields order will be Field1, Field2, Field3. Now change the declaration order and you will see that the fields order will be changed also.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If we do not use content types and still want to customise the fields order seems that a default content type is used and the name for this is “Item”. Since this is a customisation I think you have to declare a new content type and do the steps from above. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Another way can be to create your own customized page for New and Display. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2854483522136110136-3293004460438272133?l=cipriangrosu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cipriangrosu.blogspot.com/feeds/3293004460438272133/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cipriangrosu.blogspot.com/2009/05/modify-fields-order-into-new-and-edit.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/3293004460438272133'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/3293004460438272133'/><link rel='alternate' type='text/html' href='http://cipriangrosu.blogspot.com/2009/05/modify-fields-order-into-new-and-edit.html' title='Modify the fields order into New and Edit form of a list'/><author><name>CipG</name><uri>http://www.blogger.com/profile/10220394959072227580</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://2.bp.blogspot.com/_MVYMuI2A4Qo/SV0PQ5_PljI/AAAAAAAAC0Y/dWuaB5mmfZs/S220/cipg_head_2005.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2854483522136110136.post-4639001434652552536</id><published>2009-05-08T10:27:00.001-07:00</published><updated>2009-05-08T11:00:51.946-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><title type='text'>MOSS Search DateTime comparation</title><content type='html'>&lt;p&gt;Using the MOSS search one of the criteria was to match some items to a DateTime criteria. I have to specify that I was using FullTextSqlQuery and I had to build the query into the code because some other custom property ware added as criteria for search.&lt;/p&gt;  &lt;p&gt;Now back to DateTime, all seems to work for dates greater (&amp;gt;) and less (&amp;lt;). My problem was matching on equal criteria. According to MSDN we must not use equal criteria because the way the date is stored into database. They stored with hour, minute, seconds, milliseconds etc. They say that using “=” you will get unpredictable search results.&lt;/p&gt;  &lt;p&gt;But since the client want this and we have to make the client happy I had to find a solution to this. Only way to solve the problem was instead of writing &lt;/p&gt;  &lt;p&gt;TimeStart = '2009-04-23' &lt;/p&gt;  &lt;p&gt;to write &lt;/p&gt;  &lt;p&gt;( TimeStart &amp;gt;= '2009-04-22' ) AND (TimeStart &amp;lt; '2009-04-23' )&lt;/p&gt;  &lt;p&gt;as matching criteria. &lt;/p&gt;  &lt;p&gt;It seems to work in my case.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2854483522136110136-4639001434652552536?l=cipriangrosu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cipriangrosu.blogspot.com/feeds/4639001434652552536/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cipriangrosu.blogspot.com/2009/05/moss-search-datetime-comparation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/4639001434652552536'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/4639001434652552536'/><link rel='alternate' type='text/html' href='http://cipriangrosu.blogspot.com/2009/05/moss-search-datetime-comparation.html' title='MOSS Search DateTime comparation'/><author><name>CipG</name><uri>http://www.blogger.com/profile/10220394959072227580</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://2.bp.blogspot.com/_MVYMuI2A4Qo/SV0PQ5_PljI/AAAAAAAAC0Y/dWuaB5mmfZs/S220/cipg_head_2005.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2854483522136110136.post-7057453684818854320</id><published>2009-04-06T11:34:00.001-07:00</published><updated>2009-04-06T11:34:31.562-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><title type='text'>AddFieldAsXml bug</title><content type='html'>&lt;p&gt;Yes, there is a bug on this function allowing that the field created using this function to have after creation as InternalName the DisplayName.&lt;/p&gt;  &lt;p&gt;This can cause problems when you ranslate your field name into other languages. In this case when you will try to access your field an error will occure.&lt;/p&gt;  &lt;p&gt;This bug can be fixed with a small workaround. For this, into our function that create the field we have to get the InternalName , create the field and after that replace the InternalName of the new created field with the one that we saved before. This solution can be used together with a solution presented into a &lt;a href="http://cipriangrosu.blogspot.com/2008/12/lookup-column-guid-of-list-created.html"&gt;previous post&lt;/a&gt;.&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SetTheProperGUID(SPList catList, SPField catField, SPList pageLibList) &lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; fieldXml = catField.SchemaXml; &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; strInternalName = catField.InternalName; &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; strDisplayName = catField.Title; &lt;br /&gt;    Regex regex = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Regex(&lt;span style="color: #006080"&gt;@&amp;quot;List=\&amp;quot;&amp;quot;&lt;/span&gt;(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}\&lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="color: #006080"&gt;&amp;quot;); &lt;br /&gt;    if (regex.IsMatch(fieldXml)) &lt;br /&gt;    {&lt;br /&gt;        fieldXml = regex.Replace(fieldXml, &amp;quot;&lt;/span&gt;List=\&lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt; + catList.ID.ToString(&lt;span style="color: #006080"&gt;&amp;quot;B&amp;quot;&lt;/span&gt;).ToLower() + &lt;span style="color: #006080"&gt;&amp;quot;\&amp;quot;&amp;quot;&lt;/span&gt;); &lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: #008000"&gt;// a SharePoint bug force us to make a workaround &lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #008000"&gt;// DisplayName must be the same as InternalName at creation &lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; oldValue = &lt;span style="color: #006080"&gt;&amp;quot;DisplayName=\&amp;quot;&amp;quot;&lt;/span&gt; + strDisplayName + &lt;span style="color: #006080"&gt;&amp;quot;\&amp;quot;&amp;quot;&lt;/span&gt;; &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; newValue = &lt;span style="color: #006080"&gt;&amp;quot;DisplayName=\&amp;quot;&amp;quot;&lt;/span&gt; + strInternalName + &lt;span style="color: #006080"&gt;&amp;quot;\&amp;quot;&amp;quot;&lt;/span&gt;; &lt;br /&gt;    fieldXml = fieldXml.Replace(oldValue, newValue);&lt;br /&gt;    catField.Delete(); &lt;br /&gt;    pageLibList.Fields.AddFieldAsXml(fieldXml);&lt;br /&gt;    &lt;span style="color: #008000"&gt;// now the DisplayName must be set with the proper value &lt;/span&gt;&lt;br /&gt;    SPField fixedField = pageLibList.Fields[strInternalName]; &lt;br /&gt;    fixedField.Title = strDisplayName;&lt;br /&gt;    fixedField.Update();&lt;br /&gt;    }&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2854483522136110136-7057453684818854320?l=cipriangrosu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cipriangrosu.blogspot.com/feeds/7057453684818854320/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cipriangrosu.blogspot.com/2009/04/addfieldasxml-bug.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/7057453684818854320'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/7057453684818854320'/><link rel='alternate' type='text/html' href='http://cipriangrosu.blogspot.com/2009/04/addfieldasxml-bug.html' title='AddFieldAsXml bug'/><author><name>CipG</name><uri>http://www.blogger.com/profile/10220394959072227580</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://2.bp.blogspot.com/_MVYMuI2A4Qo/SV0PQ5_PljI/AAAAAAAAC0Y/dWuaB5mmfZs/S220/cipg_head_2005.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2854483522136110136.post-881337853078175881</id><published>2009-04-06T11:06:00.001-07:00</published><updated>2009-04-06T11:09:21.475-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JQuery'/><title type='text'>Single check on a TreeView</title><content type='html'>&lt;p&gt;In the past I showed how to bind a TreeView control to a xml data source. Now the task is to allow selection of none or only one node from this control. &lt;/p&gt;  &lt;p&gt;An ideea is to implement this using &lt;a href="http://www.jquery.com/" target="_blank"&gt;JQuery&lt;/a&gt;. A &lt;a href="http://tudorolariu.blogspot.com/" target="_blank"&gt;friend&lt;/a&gt; introduced me to this scripting language and now the solution seems simple. I’m sure that it can be improved but is my first contact with JQuery so have mercy.&lt;/p&gt;  &lt;p&gt;The only thing that we have to do is to add some new code to the &lt;a href="http://cipriangrosu.blogspot.com/2009/02/binding-treeview-to-xml.html"&gt;existing TreeView solution&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;To display all checkboxes for the tree in order to be able to do the selection we have to set the ShowCheckBoxes property.&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;TreeView tv = (TreeView)Page.FindControl(&lt;span style="color: #006080"&gt;&amp;quot;ChapterTree&amp;quot;&lt;/span&gt;);&lt;br /&gt;tv.ShowCheckBoxes = TreeNodeTypes.All;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;And this are all modification that we must to into the .cs file. Now we must open the .aspx page and add some lines. Of course&amp;#160; the first that we have to add is the reference to the jquery.js file. You can download this file from the &lt;a href="http://www.jquery.com/" target="_blank"&gt;JQuery&lt;/a&gt; site and have the latest version.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;To be able to access our TreeView checkboxes we have first to take a look into the source code of the page. We will see that our controls have a generated ID. What we can do to access our control is to attach an attribute and search by this attribute. We must notice that our checkboxes are created into some cells of a html table. To access&amp;#160; them we have to create a selector that go from the TreeView control to our checkboxes.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;$(&lt;span style="color: #006080"&gt;&amp;quot;div[myAttribute='myValue'] table tr td input[type='checkbox']&amp;quot;&lt;/span&gt;)&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;After that we have to bind a function to each of our checkboxes. In this function we unselect all other and select the current node.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Below is all the code that must be added into the head tag:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;lt;script type=&lt;span style="color: #006080"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt; src=&lt;span style="color: #006080"&gt;&amp;quot;jquery.js&amp;quot;&lt;/span&gt; &amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;script type=&lt;span style="color: #006080"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt;&amp;gt;&lt;br /&gt;function aClick() { &lt;br /&gt;  var allNodes = $(&lt;span style="color: #006080"&gt;&amp;quot;div[myAttribute='myValue'] table tr td input[type='checkbox']&amp;quot;&lt;/span&gt;);   &lt;br /&gt;  allNodes.bind(&lt;span style="color: #006080"&gt;'click'&lt;/span&gt;, aClick);&lt;br /&gt;  allNodes.attr(&lt;span style="color: #006080"&gt;'checked'&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;);&lt;br /&gt;  $(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;).attr(&lt;span style="color: #006080"&gt;'checked'&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;); &lt;br /&gt;  $(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;).unbind(&lt;span style="color: #006080"&gt;'click'&lt;/span&gt;, aClick);&lt;br /&gt;}&lt;br /&gt;  &lt;br /&gt;$(document).ready(function(){       &lt;br /&gt;     $(&lt;span style="color: #006080"&gt;&amp;quot;div[myAttribute='myValue'] table tr td input[type='checkbox']&amp;quot;&lt;/span&gt;).bind(&lt;span style="color: #006080"&gt;'click'&lt;/span&gt;, aClick);          &lt;br /&gt; });&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now all seems to be simple. From today I start to apreciate JQuery. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Have a nice one !&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2854483522136110136-881337853078175881?l=cipriangrosu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cipriangrosu.blogspot.com/feeds/881337853078175881/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cipriangrosu.blogspot.com/2009/04/single-check-on-treeview.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/881337853078175881'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/881337853078175881'/><link rel='alternate' type='text/html' href='http://cipriangrosu.blogspot.com/2009/04/single-check-on-treeview.html' title='Single check on a TreeView'/><author><name>CipG</name><uri>http://www.blogger.com/profile/10220394959072227580</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://2.bp.blogspot.com/_MVYMuI2A4Qo/SV0PQ5_PljI/AAAAAAAAC0Y/dWuaB5mmfZs/S220/cipg_head_2005.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2854483522136110136.post-7615049252851467280</id><published>2009-02-04T12:55:00.001-08:00</published><updated>2009-02-05T11:32:49.700-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><title type='text'>Binding TreeView to Xml</title><content type='html'>&lt;blockquote&gt;   &lt;p&gt;If we want to display hierarchical data we have the possibility to use binding to an asp &lt;strong&gt;TreeView&lt;/strong&gt; control.&lt;/p&gt;    &lt;p&gt;To do this all we need to do is to set the &lt;strong&gt;DataSource&lt;/strong&gt; property of the &lt;strong&gt;TreeView&lt;/strong&gt; control to the data source, and then call the &lt;strong&gt;DataBind&lt;/strong&gt; method. In our case the data source is a xml file that can look like this:&lt;/p&gt;    &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_MVYMuI2A4Qo/SYoAoeAMk1I/AAAAAAAAC2A/1SnVY0uTEx0/s1600-h/treeviewxml%5B11%5D.png"&gt;&lt;img title="treeviewxml" style="border-top-width: 0px; display: block; border-left-width: 0px; float: none; border-bottom-width: 0px; margin-left: auto; margin-right: auto; border-right-width: 0px" height="234" alt="treeviewxml" src="http://lh4.ggpht.com/_MVYMuI2A4Qo/SYoAou_rqaI/AAAAAAAAC2E/lUp-mHeifBo/treeviewxml_thumb%5B11%5D.png?imgmax=800" width="356" border="0" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;    &lt;p&gt;The result that we want should look like this :&lt;/p&gt;    &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_MVYMuI2A4Qo/SYoApEx43qI/AAAAAAAAC2I/W_tElXY1FTc/s1600-h/treeviewxmlresult%5B3%5D.png"&gt;&lt;img title="treeviewxmlresult" style="border-top-width: 0px; display: block; border-left-width: 0px; float: none; border-bottom-width: 0px; margin-left: auto; margin-right: auto; border-right-width: 0px" height="168" alt="treeviewxmlresult" src="http://lh5.ggpht.com/_MVYMuI2A4Qo/SYoApZ0JNFI/AAAAAAAAC2M/aok3jB1FZDo/treeviewxmlresult_thumb%5B3%5D.png?imgmax=800" width="257" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;To obtain this result we first have to add the ASP control to page and after that to add the code for data binding. Here is the html part for adding the control. I added an label also to display messages:&lt;/p&gt;    &lt;div&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;form1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;div&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:Label&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ChapterLabel&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;A tree for car classification:&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:Label&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TreeView&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ChapterTree&amp;quot;&lt;/span&gt;  &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ShowLines&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TreeView&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;div&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;/div&gt;&lt;br /&gt;&lt;br /&gt;  &lt;p&gt;To obtain the desired result as you see we have to create &lt;strong&gt;TreeNodeBinding&lt;/strong&gt; objects that define the relation between data item and the node that it is binding to. Below is the code that do the job:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;  &lt;div&gt;&lt;br /&gt;    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Page_Load(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e) &lt;br /&gt;{           &lt;br /&gt;    TreeView tv = (TreeView)Page.FindControl(&lt;span style="color: #006080"&gt;&amp;quot;ChapterTree&amp;quot;&lt;/span&gt;);            &lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #008000"&gt;// build the data source for the tree &lt;/span&gt;&lt;br /&gt;    XmlDocument theBigTree = BuildXmlTree(); &lt;br /&gt;    XmlDataSource xmlds = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XmlDataSource(); &lt;br /&gt;    xmlds.Data = theBigTree.InnerXml; &lt;br /&gt;    xmlds.DataBind(); &lt;br /&gt;    TreeNodeBinding treeBinding = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; TreeNodeBinding(); &lt;br /&gt;    treeBinding.DataMember = &lt;span style="color: #006080"&gt;&amp;quot;tree&amp;quot;&lt;/span&gt;; &lt;br /&gt;    treeBinding.TextField = &lt;span style="color: #006080"&gt;&amp;quot;name&amp;quot;&lt;/span&gt;; &lt;br /&gt;    TreeNodeBinding nameBinding = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; TreeNodeBinding(); &lt;br /&gt;    nameBinding.DataMember = &lt;span style="color: #006080"&gt;&amp;quot;node&amp;quot;&lt;/span&gt;; &lt;br /&gt;    nameBinding.TextField = &lt;span style="color: #006080"&gt;&amp;quot;name&amp;quot;&lt;/span&gt;; &lt;br /&gt;    tv.DataBindings.Add(treeBinding); &lt;br /&gt;    tv.DataBindings.Add(nameBinding); &lt;br /&gt;    tv.DataSource = xmlds; &lt;br /&gt;    tv.DataBind(); &lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;  &lt;/div&gt;&lt;/blockquote&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2854483522136110136-7615049252851467280?l=cipriangrosu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cipriangrosu.blogspot.com/feeds/7615049252851467280/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cipriangrosu.blogspot.com/2009/02/binding-treeview-to-xml.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/7615049252851467280'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/7615049252851467280'/><link rel='alternate' type='text/html' href='http://cipriangrosu.blogspot.com/2009/02/binding-treeview-to-xml.html' title='Binding TreeView to Xml'/><author><name>CipG</name><uri>http://www.blogger.com/profile/10220394959072227580</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://2.bp.blogspot.com/_MVYMuI2A4Qo/SV0PQ5_PljI/AAAAAAAAC0Y/dWuaB5mmfZs/S220/cipg_head_2005.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_MVYMuI2A4Qo/SYoAou_rqaI/AAAAAAAAC2E/lUp-mHeifBo/s72-c/treeviewxml_thumb%5B11%5D.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2854483522136110136.post-8762297804238358272</id><published>2008-12-31T01:57:00.000-08:00</published><updated>2009-02-05T11:24:35.280-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><title type='text'>Lookup column - get data from parent list</title><content type='html'>&lt;div align="justify"&gt;In my previous post I shared a solution to replace in the CAML schema of a lookup field the GUID of the list from which the field get his data.&lt;br&gt;Now the situation is that we want to get data from the parent list. Of cource that we can use the previous way but for this case there is a more easy way.&lt;br&gt;The only thing we have to do is to specify the value of the List attribute to Self.&lt;br&gt;In this case we have a list with categories and each category can have subcategories from the same list.&lt;/div&gt; &lt;div align="justify"&gt;&lt;br&gt;&amp;nbsp;&lt;/div&gt; &lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Field&lt;/span&gt;        &lt;br /&gt;    &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="{D2C297A5-1D6C-480d-9203-F54169A3FB18}"&lt;/span&gt;        &lt;br /&gt;    &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Category"&lt;/span&gt;        &lt;br /&gt;    &lt;span style="color: #ff0000"&gt;DisplayName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Category"&lt;/span&gt;        &lt;br /&gt;    &lt;span style="color: #ff0000"&gt;StaticName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Category"&lt;/span&gt;        &lt;br /&gt;    &lt;span style="color: #ff0000"&gt;SourceID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="http://schemas.microsoft.com/sharepoint"&lt;/span&gt;        &lt;br /&gt;    &lt;span style="color: #ff0000"&gt;Group&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="MyGroup"&lt;/span&gt;        &lt;br /&gt;    &lt;span style="color: #ff0000"&gt;Type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Lookup"&lt;/span&gt;        &lt;br /&gt;    &lt;span style="color: #ff0000"&gt;ShowField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Title"&lt;/span&gt;        &lt;br /&gt;    &lt;span style="color: #ff0000"&gt;List&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Self"&lt;/span&gt;    &lt;br /&gt;   &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2854483522136110136-8762297804238358272?l=cipriangrosu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cipriangrosu.blogspot.com/feeds/8762297804238358272/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cipriangrosu.blogspot.com/2008/12/lookup-column-get-data-from-parent-list.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/8762297804238358272'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/8762297804238358272'/><link rel='alternate' type='text/html' href='http://cipriangrosu.blogspot.com/2008/12/lookup-column-get-data-from-parent-list.html' title='Lookup column - get data from parent list'/><author><name>CipG</name><uri>http://www.blogger.com/profile/10220394959072227580</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://2.bp.blogspot.com/_MVYMuI2A4Qo/SV0PQ5_PljI/AAAAAAAAC0Y/dWuaB5mmfZs/S220/cipg_head_2005.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2854483522136110136.post-3586281868728202783</id><published>2008-12-31T01:24:00.000-08:00</published><updated>2009-02-05T11:11:17.934-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><title type='text'>Lookup column - replace GUID of referenced list</title><content type='html'>&lt;div align="justify"&gt;When we create a lookup field using CAML we need to specify the name or GUID of the list from which this field gets data. Is possible that this list to be created using a feature so we will not know his GUID.&lt;/div&gt;  &lt;div align="justify"&gt;&amp;#160;&lt;/div&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Field&lt;/span&gt;        &lt;br /&gt;    &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{DFFDD227-CC2C-4a6f-930C-44BD65CDA80F}&amp;quot;&lt;/span&gt;        &lt;br /&gt;    &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Location&amp;quot;&lt;/span&gt;        &lt;br /&gt;    &lt;span style="color: #ff0000"&gt;DisplayName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Location&amp;quot;&lt;/span&gt;        &lt;br /&gt;    &lt;span style="color: #ff0000"&gt;StaticName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Location&amp;quot;&lt;/span&gt;        &lt;br /&gt;    &lt;span style="color: #ff0000"&gt;SourceID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://schemas.microsoft.com/sharepoint&amp;quot;&lt;/span&gt;        &lt;br /&gt;    &lt;span style="color: #ff0000"&gt;Group&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;MyGroup&amp;quot;&lt;/span&gt;        &lt;br /&gt;    &lt;span style="color: #ff0000"&gt;Type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Lookup&amp;quot;&lt;/span&gt;        &lt;br /&gt;    &lt;span style="color: #ff0000"&gt;ShowField&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Title&amp;quot;&lt;/span&gt;        &lt;br /&gt;    &lt;span style="color: #ff0000"&gt;List&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Locations&amp;quot;&lt;/span&gt;    &lt;br /&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="justify"&gt;&lt;br /&gt;  &lt;br /&gt;I try to specify the name of the list in field CAML definition but I do not know why after creation the field point to a strange object with a different GUID that I expected to. &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;The solution I found is to have a feature who can modify this GUID after the required list is created. I created a function that get the SchemaXml of the field and in this xml replace the GUID of the list. The required list and the field are send as parameters. After we have the proper SchemaXml we delete the old field and create a new one using this new schema. In the feature activation we can call this function. &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Here is the code:&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="justify"&gt;&amp;#160;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SetTheProperGUID(SPList catList, SPField catField)    &lt;br /&gt;{       &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; fieldXml = catField.SchemaXml;       &lt;br /&gt;    Regex regex = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Regex(&lt;span style="color: #006080"&gt;@&amp;quot;List=\&amp;quot;&amp;quot;&lt;/span&gt;(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}\&lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="color: #006080"&gt;&amp;quot;);       &lt;br /&gt;    if (regex.IsMatch(fieldXml))       &lt;br /&gt;    {         &lt;br /&gt;        fieldXml = regex.Replace(fieldXml, &amp;quot;&lt;/span&gt;List=\&lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt; + catList.ID.ToString(&lt;span style="color: #006080"&gt;&amp;quot;B&amp;quot;&lt;/span&gt;).ToLower() + &lt;span style="color: #006080"&gt;&amp;quot;\&amp;quot;&amp;quot;&lt;/span&gt;);       &lt;br /&gt;    }       &lt;br /&gt;    catField.Delete();       &lt;br /&gt;    catList.Fields.AddFieldAsXml(fieldXml);       &lt;br /&gt;    catList.Update();    &lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2854483522136110136-3586281868728202783?l=cipriangrosu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cipriangrosu.blogspot.com/feeds/3586281868728202783/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cipriangrosu.blogspot.com/2008/12/lookup-column-guid-of-list-created.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/3586281868728202783'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/3586281868728202783'/><link rel='alternate' type='text/html' href='http://cipriangrosu.blogspot.com/2008/12/lookup-column-guid-of-list-created.html' title='Lookup column - replace GUID of referenced list'/><author><name>CipG</name><uri>http://www.blogger.com/profile/10220394959072227580</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://2.bp.blogspot.com/_MVYMuI2A4Qo/SV0PQ5_PljI/AAAAAAAAC0Y/dWuaB5mmfZs/S220/cipg_head_2005.JPG'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2854483522136110136.post-1224505761904819982</id><published>2008-12-18T10:16:00.000-08:00</published><updated>2009-02-05T10:59:45.317-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><title type='text'>Delete items from large Lists</title><content type='html'>&lt;p&gt;Situation:    &lt;br /&gt;    &lt;br /&gt;We have a large list (more than 100.000 items). The request is to delete all the items.     &lt;br /&gt;    &lt;br /&gt;Solution:     &lt;br /&gt;    &lt;br /&gt;We can try to iterate through all items and delete. Of course this approach will generate performance problems. The best solution I found is to use a batch:&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ClearList(SPList taskList)        &lt;br /&gt;{                      &lt;br /&gt;    StringBuilder sbDelete = BuildBatchDeleteCommand(taskList);            &lt;br /&gt;    taskList.ParentWeb.ProcessBatchData(sbDelete.ToString());                  &lt;br /&gt;}        &lt;br /&gt;&lt;br /&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #008000"&gt;/// Builds a batch string with a list of all the items that are to be deleted.        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;param name=&amp;quot;spList&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; StringBuilder BuildBatchDeleteCommand(SPList spList)        &lt;br /&gt;{            &lt;br /&gt;    StringBuilder sbDelete = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; StringBuilder();            &lt;br /&gt;    sbDelete.Append(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;?xml version=\&amp;quot;1.0\&amp;quot; encoding=\&amp;quot;UTF-8\&amp;quot;?&amp;gt;&amp;lt;Batch&amp;gt;&amp;quot;&lt;/span&gt;);            &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; command = &lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;Method&amp;gt;&amp;lt;SetList Scope=\&amp;quot;Request\&amp;quot;&amp;gt;&amp;quot;&lt;/span&gt; + spList.ID + &lt;br /&gt;                &lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;/SetList&amp;gt;&amp;lt;SetVar Name=\&amp;quot;ID\&amp;quot;&amp;gt;{0}&amp;lt;/SetVar&amp;gt;&amp;lt;SetVar Name=\&amp;quot;Cmd\&amp;quot;&amp;gt;Delete&amp;lt;/SetVar&amp;gt;&amp;lt;/Method&amp;gt;&amp;quot;&lt;/span&gt;;            &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (SPListItem item &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; spList.Items)            &lt;br /&gt;    {                &lt;br /&gt;        sbDelete.Append(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format(command, item.ID.ToString()));            &lt;br /&gt;    }            &lt;br /&gt;    sbDelete.Append(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;/Batch&amp;gt;&amp;quot;&lt;/span&gt;);           &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; sbDelete;        &lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&amp;#160; &lt;br /&gt;More details on how to use batch : &lt;a href="http://msdn.microsoft.com/en-us/library/cc404818.aspx"&gt;http://msdn.microsoft.com/en-us/library/cc404818.aspx&lt;/a&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2854483522136110136-1224505761904819982?l=cipriangrosu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cipriangrosu.blogspot.com/feeds/1224505761904819982/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cipriangrosu.blogspot.com/2008/12/sharepoint-security-and-net.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/1224505761904819982'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2854483522136110136/posts/default/1224505761904819982'/><link rel='alternate' type='text/html' href='http://cipriangrosu.blogspot.com/2008/12/sharepoint-security-and-net.html' title='Delete items from large Lists'/><author><name>CipG</name><uri>http://www.blogger.com/profile/10220394959072227580</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='27' height='32' src='http://2.bp.blogspot.com/_MVYMuI2A4Qo/SV0PQ5_PljI/AAAAAAAAC0Y/dWuaB5mmfZs/S220/cipg_head_2005.JPG'/></author><thr:total>0</thr:total></entry></feed>
