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

<channel>
	<title>Kit Menke&#039;s Blog</title>
	<atom:link href="http://kitmenke.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://kitmenke.com/blog</link>
	<description>Experiences with SharePoint, web development, and programming</description>
	<lastBuildDate>Fri, 19 Feb 2010 03:40:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Editing in SharePoint&#8217;s SPGridView</title>
		<link>http://kitmenke.com/blog/2010/02/18/editing-in-sharepoints-spgridview/</link>
		<comments>http://kitmenke.com/blog/2010/02/18/editing-in-sharepoints-spgridview/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 03:36:28 +0000</pubDate>
		<dc:creator>Kit</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Example]]></category>

		<guid isPermaLink="false">http://kitmenke.com/blog/?p=198</guid>
		<description><![CDATA[The goal of this post is to provide an easy to understand example of how to enable editing in an SPGridView. In this case, my datasource of choice is a SharePoint list.
The way that I chose to implement editing in an SPGridView involved two classes:

SimpleLogic &#8211; handles query and update operations
SimpleSPGrid &#8211; handles all of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://kitmenke.com/blog/wp-content/uploads/2010/02/2010-02-17-17-03-36.png"></a>The goal of this post is to provide an easy to understand example of how to enable editing in an SPGridView. In this case, my datasource of choice is a SharePoint list.</p>
<p>The way that I chose to implement editing in an SPGridView involved two classes:</p>
<ul>
<li><strong>SimpleLogic</strong> &#8211; handles query and update operations</li>
<li><strong>SimpleSPGrid</strong> &#8211; handles all of the setup for the ObjectDataSource and the SPGridView</li>
</ul>
<p>The main advantage for splitting the two classes is to separate all of the business logic into one class. Ideally, you should be able to completely change how the <strong>SimpleLogic </strong>class retrieves/updates data without changing the <strong>SimpleSPGrid</strong> code.</p>
<p><span id="more-198"></span></p>
<h2>The Setup</h2>
<p>In this example, our logic class is retrieving and updating data in a SharePoint list. My SharePoint list had three main columns: Title (text), Region (choice), and Total Sales (currency).</p>
<p><a href="http://kitmenke.com/blog/wp-content/uploads/2010/02/2010-02-17-17-03-36.png"><img title="SPGridView Editing - SharePoint list" src="http://kitmenke.com/blog/wp-content/uploads/2010/02/2010-02-17-17-03-36.png" alt="SharePoint list" width="545" height="265" /></a></p>
<p>Now that I had some data to read from and write to, I was ready to create my logic class.</p>
<h2>The SimpleLogic Class</h2>
<p>The goal for the logic class was to expose all of the operations the gridview would need in order to read or update data:</p>
<ol>
<li>public DataTable Select()<br />
How do I get the data?</li>
<li>public List&lt;BoundField&gt; GetColumns()<br />
How do I display the data?</li>
<li>public void Update(Dictionary&lt;string, string&gt; data)<br />
How do I update the data?</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> SimpleLogic
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">string</span> LIST_NAME <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Example Sales Data&quot;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF;">readonly</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> LIST_COLUMNS <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
    <span style="color: #0600FF;">readonly</span> <span style="color: #FF0000;">string</span> VIEW_FIELDS <span style="color: #008000;">=</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF;">readonly</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> DATA_KEY_NAMES <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
    <span style="color: #0600FF;">private</span> SPWeb _currentWeb<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> SimpleLogic<span style="color: #000000;">&#40;</span>SPWeb currentWeb<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        _currentWeb <span style="color: #008000;">=</span> currentWeb<span style="color: #008000;">;</span>
&nbsp;
        DATA_KEY_NAMES <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
        DATA_KEY_NAMES<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;ID&quot;</span><span style="color: #008000;">;</span>
        LIST_COLUMNS <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">4</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
        LIST_COLUMNS<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;ID&quot;</span><span style="color: #008000;">;</span>
        LIST_COLUMNS<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Title&quot;</span><span style="color: #008000;">;</span>
        LIST_COLUMNS<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Region&quot;</span><span style="color: #008000;">;</span>
        LIST_COLUMNS<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Total_x0020_Sales&quot;</span><span style="color: #008000;">;</span>
        VIEW_FIELDS <span style="color: #008000;">=</span> GetViewFields<span style="color: #000000;">&#40;</span>LIST_COLUMNS<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> GetDataKeyNames<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">return</span> DATA_KEY_NAMES<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> List<span style="color: #008000;">&lt;</span>BoundField<span style="color: #008000;">&gt;</span> GetColumns<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        List<span style="color: #008000;">&lt;</span>BoundField<span style="color: #008000;">&gt;</span> fields <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>BoundField<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        fields.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>GetBoundField<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;ID&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008080; font-style: italic;">// we don't want the ID field to be editable so we make it readonly</span>
        <span style="color: #008080; font-style: italic;">// readonly will mean a textbox to edit it will not be shown</span>
        fields<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span>.<span style="color: #0600FF;">ReadOnly</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
        fields.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>GetBoundField<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Title&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        fields.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>GetBoundField<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Region&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        fields.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>GetBoundField<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Total_x0020_Sales&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">return</span> fields<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">private</span> BoundField GetBoundField<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> name<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// do not use SPBoundField (will not work with editing)</span>
        BoundField bf <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> BoundField<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        bf.<span style="color: #0000FF;">HeaderText</span> <span style="color: #008000;">=</span> name<span style="color: #008000;">;</span>
        bf.<span style="color: #0000FF;">DataField</span> <span style="color: #008000;">=</span> name<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">return</span> bf<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> DataTable Select<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        SPQuery q <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SPQuery<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        q.<span style="color: #0000FF;">ViewFields</span> <span style="color: #008000;">=</span> VIEW_FIELDS<span style="color: #008000;">;</span>
        q.<span style="color: #0000FF;">Query</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&lt;Where&gt;&lt;IsNotNull&gt;&lt;FieldRef Name='Title'/&gt;&lt;/IsNotNull&gt;&lt;/Where&gt;&quot;</span><span style="color: #008000;">;</span>
        SPList list <span style="color: #008000;">=</span> _currentWeb.<span style="color: #0000FF;">Lists</span><span style="color: #000000;">&#91;</span>LIST_NAME<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
        SPListItemCollection items <span style="color: #008000;">=</span> list.<span style="color: #0000FF;">GetItems</span><span style="color: #000000;">&#40;</span>q<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">return</span> items.<span style="color: #0000FF;">GetDataTable</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span> GetViewFields<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> columns<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        StringBuilder sb <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringBuilder<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> field <span style="color: #0600FF;">in</span> columns<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            sb.<span style="color: #0000FF;">AppendFormat</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;FieldRef Name='{0}' /&gt;&quot;</span>, field<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">return</span> sb.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Update<span style="color: #000000;">&#40;</span>Dictionary<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span>, <span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;</span> data<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        SPList list <span style="color: #008000;">=</span> _currentWeb.<span style="color: #0000FF;">Lists</span><span style="color: #000000;">&#91;</span>LIST_NAME<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
        <span style="color: #FF0000;">int</span> id <span style="color: #008000;">=</span> Int32.<span style="color: #0000FF;">Parse</span><span style="color: #000000;">&#40;</span>data<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;ID&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        SPListItem item <span style="color: #008000;">=</span> list.<span style="color: #0000FF;">GetItemById</span><span style="color: #000000;">&#40;</span>id<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        item<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Title&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> data<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Title&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
        item<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Region&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> data<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Region&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
        item<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Total_x0020_Sales&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> data<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Total_x0020_Sales&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
        item.<span style="color: #0000FF;">Update</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>DISCLAIMER: When actually implementing the class above, you will probably need to add some sort of error handling. In order to provide a simpler example, the error handling has been omitted.</p>
<p>Once our logic class is functioning correctly, we can work on hooking it up to an SPGridView.</p>
<h2>The SimpleSPGrid Class</h2>
<p>The SimpleSPGrid class contains most of the guts that will probably be different to you. The first thing to notice is that it takes our SimpleLogic class as a parameter. This allows us to instantiate our logic class beforehand with any parameters that are needed, and then pass it into SimpleSPGrid to use.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> SimpleSPGrid <span style="color: #008000;">:</span> CompositeControl
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">private</span> SimpleLogic _logic<span style="color: #008000;">;</span>
    <span style="color: #0600FF;">private</span> ObjectDataSource _gridDS<span style="color: #008000;">;</span>
    <span style="color: #0600FF;">private</span> SPGridView _grid<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> SimpleSPGrid<span style="color: #000000;">&#40;</span>SimpleLogic logic<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        _logic <span style="color: #008000;">=</span> logic<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">sealed</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> CreateChildControls<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">string</span> GRIDID <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;grid&quot;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">string</span> DATASOURCEID <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;gridDS&quot;</span><span style="color: #008000;">;</span>
&nbsp;
        _gridDS <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ObjectDataSource<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        _gridDS.<span style="color: #0000FF;">ID</span> <span style="color: #008000;">=</span> DATASOURCEID<span style="color: #008000;">;</span>
        _gridDS.<span style="color: #0000FF;">TypeName</span> <span style="color: #008000;">=</span> <span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>SimpleLogic<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">AssemblyQualifiedName</span><span style="color: #008000;">;</span>
        _gridDS.<span style="color: #0000FF;">ObjectCreating</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> ObjectDataSourceObjectEventHandler<span style="color: #000000;">&#40;</span>gridDS_ObjectCreating<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        _gridDS.<span style="color: #0000FF;">SelectMethod</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Select&quot;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// to handle updates from the grid</span>
        _gridDS.<span style="color: #0000FF;">UpdateMethod</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Update&quot;</span><span style="color: #008000;">;</span>
        _gridDS.<span style="color: #0000FF;">Updating</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> ObjectDataSourceMethodEventHandler<span style="color: #000000;">&#40;</span>gridDS_Updating<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>_gridDS<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// create our grid</span>
        _grid <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SPGridView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        _grid.<span style="color: #0000FF;">ID</span> <span style="color: #008000;">=</span> GRIDID<span style="color: #008000;">;</span>
        _grid.<span style="color: #0000FF;">DataSourceID</span> <span style="color: #008000;">=</span> _gridDS.<span style="color: #0000FF;">ID</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// link the grid to the ObjectDataSource</span>
        _grid.<span style="color: #0000FF;">AutoGenerateColumns</span> <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// must be false</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// generally the primary key field(s)</span>
        <span style="color: #008080; font-style: italic;">// these will be passed as an input parameter</span>
        _grid.<span style="color: #0000FF;">DataKeyNames</span> <span style="color: #008000;">=</span> _logic.<span style="color: #0000FF;">GetDataKeyNames</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// add the column that will allow editing</span>
        CommandField command <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CommandField<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        command.<span style="color: #0000FF;">ShowEditButton</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
        _grid.<span style="color: #0000FF;">Columns</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>command<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// add all of the columns in the datatable to the grid</span>
        <span style="color: #008080; font-style: italic;">// any column that is not readonly will be passed as an input parameter</span>
        <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>BoundField column <span style="color: #0600FF;">in</span> _logic.<span style="color: #0000FF;">GetColumns</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            _grid.<span style="color: #0000FF;">Columns</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>column<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>_grid<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// Consolidates all of the InputParameters (values from the grid)</span>
    <span style="color: #008080; font-style: italic;">/// into one dictionary of values to send to the update method</span>
    <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF;">void</span> gridDS_Updating<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, ObjectDataSourceMethodEventArgs e<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        Dictionary<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span>, <span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;</span> data <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span>, <span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>DictionaryEntry entry <span style="color: #0600FF;">in</span> e.<span style="color: #0000FF;">InputParameters</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #FF0000;">string</span> value <span style="color: #008000;">=</span> entry.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span> <span style="color: #008000;">?</span> <span style="color: #0600FF;">null</span> <span style="color: #008000;">:</span> entry.<span style="color: #0000FF;">Value</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            data.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>entry.<span style="color: #0000FF;">Key</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, value<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        e.<span style="color: #0000FF;">InputParameters</span>.<span style="color: #0000FF;">Clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        e.<span style="color: #0000FF;">InputParameters</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;data&quot;</span>, data<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// When the ObjectDataSource is created, hook it up to the Logic class</span>
    <span style="color: #008080; font-style: italic;">/// (so that it uses the Logic class to make the Select, Update... calls)</span>
    <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> gridDS_ObjectCreating<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, ObjectDataSourceEventArgs e<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        e.<span style="color: #0000FF;">ObjectInstance</span> <span style="color: #008000;">=</span> _logic<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<h2>Wrap up</h2>
<p>Now that all the hard work is done, we are ready to use the classes inside our web part. Inside the CreateChildControls of your webpart you would have the following code ( even though we have an SPWeb here, it should NOT be disposed):</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> CreateChildControls<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    SimpleLogic logic <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SimpleLogic<span style="color: #000000;">&#40;</span>SPControl.<span style="color: #0000FF;">GetContextWeb</span><span style="color: #000000;">&#40;</span>Context<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    SimpleSPGrid grid <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SimpleSPGrid<span style="color: #000000;">&#40;</span>logic<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>grid<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>This will produce the following grid!</p>
<p><a href="http://kitmenke.com/blog/wp-content/uploads/2010/02/2010-02-17-17-01-15.png"><img title="SPGridView Editing - List Data" src="http://kitmenke.com/blog/wp-content/uploads/2010/02/2010-02-17-17-01-15.png" alt="List Data" width="587" height="260" /></a></p>
<p>And clicking edit&#8230;</p>
<p><a href="http://kitmenke.com/blog/wp-content/uploads/2010/02/2010-02-17-17-02-00.png"><img title="SPGridView Editing - SPGridView Edit Mode" src="http://kitmenke.com/blog/wp-content/uploads/2010/02/2010-02-17-17-02-00.png" alt="SPGridView Edit Mode" width="485" height="217" /></a></p>
<img src="http://kitmenke.com/blog/?ak_action=api_record_view&id=198&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kitmenke.com/blog/2010/02/18/editing-in-sharepoints-spgridview/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Relative Dates in JavaScript</title>
		<link>http://kitmenke.com/blog/2010/01/23/relative-dates-in-javascript/</link>
		<comments>http://kitmenke.com/blog/2010/01/23/relative-dates-in-javascript/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 03:37:41 +0000</pubDate>
		<dc:creator>Kit</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[Search]]></category>

		<guid isPermaLink="false">http://kitmenke.com/blog/?p=183</guid>
		<description><![CDATA[I was developing an input form for a search when I came across the need to allow the user to filter items using a date range. I had two input boxes where the user could enter a start and an end date. For some of the most common date ranges, I decided to create links [...]]]></description>
			<content:encoded><![CDATA[<p>I was developing an input form for a search when I came across the need to allow the user to filter items using a date range. I had two input boxes where the user could enter a start and an end date. For some of the most common date ranges, I decided to create links that could be clicked to auto-populate the start/end date textboxes. For example, searching for items that were created last week or last month. Using JavaScript&#8217;s Date object, I was able to put together some nice examples.</p>
<p><span id="more-183"></span></p>
<p>First, the setup. I needed two text boxes to hold the start/end dates and then wanted the user to click links to auto-populate them with some relative dates:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript: void(0);&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;return setRelativeDate('today')&quot;</span>&gt;</span>Today<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;txtStartDate&quot;</span>&gt;</span>Start Date:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;txtStartDate&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;txtEndDate&quot;</span>&gt;</span>End Date:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;txtEndDate&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p>Then to figure out how to calculate the dates using JavaScript. Here are the examples.. starting out easy with <strong>Today</strong>&#8217;s date. When creating a new Date object, it is automatically initialized to the current day and time:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> today <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
txtStartDate.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> getShortDateString<span style="color: #009900;">&#40;</span>today<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
txtEndDate.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> txtStartDate.<span style="color: #660066;">value</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Yesterday </strong>is Today -1:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> yesterday <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
yesterday.<span style="color: #660066;">setDate</span><span style="color: #009900;">&#40;</span>yesterday.<span style="color: #660066;">getDate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
txtStartDate.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> getShortDateString<span style="color: #009900;">&#40;</span>yesterday<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
txtEndDate.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> txtStartDate.<span style="color: #660066;">value</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>This Week </strong>is a little more complicated. getDate() returns the day of the month (1-31) and getDay() returns the day of the week (0-6).</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> thisWeek <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// set the date to most recent Sunday</span>
thisWeek.<span style="color: #660066;">setDate</span><span style="color: #009900;">&#40;</span>thisWeek.<span style="color: #660066;">getDate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> thisWeek.<span style="color: #660066;">getDay</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
txtStartDate.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> getShortDateString<span style="color: #009900;">&#40;</span>thisWeek<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// set the date to last week's Saturday</span>
thisWeek.<span style="color: #660066;">setDate</span><span style="color: #009900;">&#40;</span>thisWeek.<span style="color: #660066;">getDate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
txtEndDate.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> getShortDateString<span style="color: #009900;">&#40;</span>thisWeek<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Last Week</strong> is pretty similar to this week. I think the hardest part for me is the function names getDate and getDay. I always was getting them confused and thought that they should have been more specific&#8230; like getWeekDay and getMonthDay or something.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> lastWeek <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// set the date to last week's Sunday</span>
lastWeek.<span style="color: #660066;">setDate</span><span style="color: #009900;">&#40;</span>lastWeek.<span style="color: #660066;">getDate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> lastWeek.<span style="color: #660066;">getDay</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">7</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
txtStartDate.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> getShortDateString<span style="color: #009900;">&#40;</span>lastWeek<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// set the date to last week's Saturday</span>
lastWeek.<span style="color: #660066;">setDate</span><span style="color: #009900;">&#40;</span>lastWeek.<span style="color: #660066;">getDate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
txtEndDate.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> getShortDateString<span style="color: #009900;">&#40;</span>lastWeek<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The main difficulty I had with <strong>This Month</strong> was how to figure out the last day of the month. Luckily, if you can figure it out by selecting the first of next month and then subtracting a day.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> lastDayOfThisMonth <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// go to the next month</span>
<span style="color: #003366; font-weight: bold;">var</span> nextMonth <span style="color: #339933;">=</span> lastDayOfThisMonth.<span style="color: #660066;">getMonth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
lastDayOfThisMonth.<span style="color: #660066;">setMonth</span><span style="color: #009900;">&#40;</span>nextMonth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// go to the last day of the previous month (this month)</span>
lastDayOfThisMonth.<span style="color: #660066;">setDate</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
txtEndDate.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> getShortDateString<span style="color: #009900;">&#40;</span>lastDayOfThisMonth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
lastDayOfThisMonth.<span style="color: #660066;">setDate</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
txtStartDate.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> getShortDateString<span style="color: #009900;">&#40;</span>lastDayOfThisMonth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Notice how <strong>Last Month</strong> is actually easier because you can simply move backwards a month.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> lastDayOfLastMonth <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// now</span>
lastDayOfLastMonth.<span style="color: #660066;">setDate</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// last day of last month            </span>
<span style="color: #006600; font-style: italic;">// set the end date first</span>
txtEndDate.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> getShortDateString<span style="color: #009900;">&#40;</span>lastDayOfLastMonth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
lastDayOfLastMonth.<span style="color: #660066;">setDate</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
txtStartDate.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> getShortDateString<span style="color: #009900;">&#40;</span>lastDayOfLastMonth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The only issue I had with <strong>This Year</strong> was I didn&#8217;t realize that  setMonth(int) took a zero based month: 0 = January &#8230; 11 = December.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> lastDayOfThisYear <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
lastDayOfThisYear.<span style="color: #660066;">setMonth</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">11</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// December</span>
lastDayOfThisYear.<span style="color: #660066;">setDate</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">31</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
txtEndDate.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> getShortDateString<span style="color: #009900;">&#40;</span>lastDayOfThisYear<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
lastDayOfThisYear.<span style="color: #660066;">setMonth</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// January</span>
lastDayOfThisYear.<span style="color: #660066;">setDate</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
txtStartDate.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> getShortDateString<span style="color: #009900;">&#40;</span>lastDayOfThisYear<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Finally, to figure out <strong>Last Year</strong> I took advantage of the setFullYear(year,month,day) function to subtract one year.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> lastDayOfLastYear <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// -1 means last year</span>
<span style="color: #006600; font-style: italic;">// 11 means December and there always is a 31st of december</span>
<span style="color: #003366; font-weight: bold;">var</span> thisYear <span style="color: #339933;">=</span> lastDayOfLastYear.<span style="color: #660066;">getFullYear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
lastDayOfLastYear.<span style="color: #660066;">setFullYear</span><span style="color: #009900;">&#40;</span>thisYear <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">11</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">31</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
txtEndDate.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> getShortDateString<span style="color: #009900;">&#40;</span>lastDayOfLastYear<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
lastDayOfLastYear.<span style="color: #660066;">setMonth</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// January</span>
lastDayOfLastYear.<span style="color: #660066;">setDate</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 1st</span>
txtStartDate.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> getShortDateString<span style="color: #009900;">&#40;</span>lastDayOfLastYear<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>See all of it together in the <a href="http://kitmenke.com/blog/wp-content/uploads/2010/01/javascript_relativedates.html">complete demo</a>.</p>
<p>References:</p>
<ul>
<li><a href="http://www.w3schools.com/jS/js_obj_date.asp">JavaScript Date Object </a></li>
<li><a href="http://www.w3schools.com/jsref/jsref_obj_date.asp">JavaScript Date Object Full Reference</a></li>
</ul>
<img src="http://kitmenke.com/blog/?ak_action=api_record_view&id=183&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kitmenke.com/blog/2010/01/23/relative-dates-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Turning SharePoint SPAuditEntry Update into Create</title>
		<link>http://kitmenke.com/blog/2010/01/22/turning-sharepoint-spauditentry-update-into-create/</link>
		<comments>http://kitmenke.com/blog/2010/01/22/turning-sharepoint-spauditentry-update-into-create/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 21:42:47 +0000</pubDate>
		<dc:creator>Kit</dc:creator>
				<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://kitmenke.com/blog/?p=178</guid>
		<description><![CDATA[If you&#8217;ve done any work with SharePoint and SPAuditEntry, you may have noticed the distinct lack of Create event. Instead, two Update events are created which means some extra processing is required.

For example, after uploading &#8220;NewTxtFile.txt&#8221; into a document library inside one of my sites, the following Audit Entries showed up.

&#60;AuditEntry&#62;
  &#60;SiteId&#62;9a70a244-1baa-4229-84ac-3f06bccecc7f&#60;/SiteId&#62;
  &#60;ItemId&#62;19ce9254-93bc-41ff-9da1-ba5e994bf1c1&#60;/ItemId&#62;
  &#60;ItemType&#62;Document&#60;/ItemType&#62;
  &#60;UserId&#62;2&#60;/UserId&#62;
  &#60;DocLocation&#62;sites/MySiteCollection/MySubsite/Documents/NewTxtFile.txt&#60;/DocLocation&#62;
  [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve done any work with SharePoint and SPAuditEntry, you may have noticed the distinct lack of Create event. Instead, two Update events are created which means some extra processing is required.</p>
<p><span id="more-178"></span></p>
<p>For example, after uploading &#8220;NewTxtFile.txt&#8221; into a document library inside one of my sites, the following Audit Entries showed up.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;AuditEntry<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SiteId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>9a70a244-1baa-4229-84ac-3f06bccecc7f<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SiteId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ItemId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>19ce9254-93bc-41ff-9da1-ba5e994bf1c1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ItemId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ItemType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Document<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ItemType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;UserId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/UserId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DocLocation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>sites/MySiteCollection/MySubsite/Documents/NewTxtFile.txt<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DocLocation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;LocationType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Url<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/LocationType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Occurred<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1/22/2010 9:17:06 PM<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Occurred<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Event<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Update<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Event<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;EventSource<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>SharePoint<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/EventSource<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/AuditEntry<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;AuditEntry<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SiteId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>9a70a244-1baa-4229-84ac-3f06bccecc7f<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SiteId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ItemId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>f332a82b-17d1-4c31-9726-5259769f2695<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ItemId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ItemType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>List<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ItemType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;UserId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/UserId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DocLocation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>sites/MySiteCollection/MySubsite/Documents<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DocLocation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;LocationType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Url<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/LocationType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Occurred<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1/22/2010 9:17:06 PM<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Occurred<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Event<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Update<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Event<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;EventSource<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>SharePoint<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/EventSource<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;EventData<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>NewTxtFile.txt<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/EventData<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/AuditEntry<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Notice the &#8220;Occurred&#8221; DateTime properties are the same as well the Event. Also, one is an Update for the List and one is an Update for the Document. Using this information, you can then simplify the duplicate Update events into one Create event!</p>
<img src="http://kitmenke.com/blog/?ak_action=api_record_view&id=178&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kitmenke.com/blog/2010/01/22/turning-sharepoint-spauditentry-update-into-create/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AllowUnsafeUpdates and ValidateFormDigest</title>
		<link>http://kitmenke.com/blog/2009/12/23/allowunsafeupdates-and-validateformdigest/</link>
		<comments>http://kitmenke.com/blog/2009/12/23/allowunsafeupdates-and-validateformdigest/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 16:34:41 +0000</pubDate>
		<dc:creator>Kit</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Links]]></category>

		<guid isPermaLink="false">http://kitmenke.com/blog/?p=175</guid>
		<description><![CDATA[Add this to the list of things every SharePoint developer should know (up there with disposing SPWebs and SPSites).
In general&#8230;

Don&#8217;t update SharePoint objects on a GET request
Call SPUtility.ValidateFormDigest() before anything on a POST request

Here are the two links to read:

What you need to know about AllowUnsafeUpdates (Part 1)
What you need to know about AllowUnsafeUpdates (Part 2)

]]></description>
			<content:encoded><![CDATA[<p>Add this to the list of things every SharePoint developer should know (up there with disposing SPWebs and SPSites).</p>
<p>In general&#8230;</p>
<ol>
<li>Don&#8217;t update SharePoint objects on a GET request</li>
<li>Call SPUtility.ValidateFormDigest() before anything on a POST request</li>
</ol>
<p>Here are the two links to read:</p>
<ul>
<li><a rel="bookmark" href="http://hristopavlov.wordpress.com/2008/05/16/what-you-need-to-know-about-allowunsafeupdates/">What you need to know about AllowUnsafeUpdates (Part 1)</a></li>
<li><a rel="bookmark" href="http://hristopavlov.wordpress.com/2008/05/21/what-you-need-to-know-about-allowunsafeupdates-part-2/">What you need to know about AllowUnsafeUpdates (Part 2)</a></li>
</ul>
<img src="http://kitmenke.com/blog/?ak_action=api_record_view&id=175&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kitmenke.com/blog/2009/12/23/allowunsafeupdates-and-validateformdigest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Internal column names: Site Columns vs List Columns</title>
		<link>http://kitmenke.com/blog/2009/12/02/internal-column-names-site-columns-vs-list-columns/</link>
		<comments>http://kitmenke.com/blog/2009/12/02/internal-column-names-site-columns-vs-list-columns/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 21:02:32 +0000</pubDate>
		<dc:creator>Kit</dc:creator>
				<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://kitmenke.com/blog/?p=166</guid>
		<description><![CDATA[Two identical custom lists with the same columns. The only difference is that one list has columns added using Site Columns and the other list had columns added directly to the list. The same? Not so much&#8230;

Steps to repro this issue:

Create a site column named &#8220;A,B-C/D&#8221; (single line of text or any other type)
Create a [...]]]></description>
			<content:encoded><![CDATA[<p>Two identical custom lists with the same columns. The only difference is that one list has columns added using Site Columns and the other list had columns added directly to the list. The same? Not so much&#8230;<br />
<span id="more-166"></span></p>
<p>Steps to repro this issue:</p>
<ol>
<li>Create a site column named &#8220;A,B-C/D&#8221; (single line of text or any other type)</li>
<li>Create a list named &#8220;Special Characters (Site)&#8221;</li>
<li>Add the Site Column &#8220;A,B-C/D&#8221; to your &#8220;Special Characters (Site)&#8221; list.</li>
<li>Create another list named &#8220;Special Characters (List)&#8221;</li>
<li>Create a column in &#8220;Special Characters (List)&#8221; named the same as your site column (&#8220;A,B-C/D&#8221;)</li>
</ol>
<p>Results:</p>
<table border="1">
<tbody>
<tr>
<td> </td>
<td>Column Added Using Site Column</td>
<td>Column Created Directly in the List</td>
</tr>
<tr>
<td><strong>Column Name</strong></td>
<td>A,B-C/D</td>
<td>A,B-C/D</td>
</tr>
<tr>
<td><strong>Internal Column Name</strong></td>
<td>A_x002C_B_x002d_C_x002F_D</td>
<td>A_x002c_B_x002d_C_x002f_D</td>
</tr>
</tbody>
</table>
<p>The internal column names are DIFFERENT.</p>
<p>&#8230; but only for some of the characters. Looks like the comma and the slash are different but not the dash.</p>
<img src="http://kitmenke.com/blog/?ak_action=api_record_view&id=166&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kitmenke.com/blog/2009/12/02/internal-column-names-site-columns-vs-list-columns/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Updating choice fields via SharePoint Web Services</title>
		<link>http://kitmenke.com/blog/2009/10/30/updating-choice-fields-via-sharepoint-web-services/</link>
		<comments>http://kitmenke.com/blog/2009/10/30/updating-choice-fields-via-sharepoint-web-services/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 16:06:40 +0000</pubDate>
		<dc:creator>Kit</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[WSS]]></category>

		<guid isPermaLink="false">http://kitmenke.com/blog/?p=148</guid>
		<description><![CDATA[My problem started with a simple change to a site column. I had originally created a Country field with the following values:

US
Canada

After a change in requirements, the new values for the field were:

Canada
Germany
Great Britain
Ireland
United States

After updating the site column, I then needed to update the hundreds of items in the list to use &#8220;United States&#8221; instead of &#8220;US&#8221;. Instead of updating [...]]]></description>
			<content:encoded><![CDATA[<p>My problem started with a simple change to a site column. I had originally created a Country field with the following values:</p>
<ul>
<li>US</li>
<li>Canada</li>
</ul>
<p>After a change in requirements, the new values for the field were:</p>
<ul>
<li>Canada</li>
<li>Germany</li>
<li>Great Britain</li>
<li>Ireland</li>
<li>United States</li>
</ul>
<p>After updating the site column, I then needed to update the hundreds of items in the list to use &#8220;United States&#8221; instead of &#8220;US&#8221;. Instead of updating hundreds of items manually, I decided to write a small web services console app. (I was also not able to update it in datasheet&#8230; due to content approval maybe???)</p>
<p>However, I quickly ran into problems when attempting to update the multi-select choice field.</p>
<p><span id="more-148"></span></p>
<h2>The Setup:</h2>
<p>My site column was defined with each choice for Country in alphabetical order:<br />
<a href="http://kitmenke.com/blog/wp-content/uploads/2009/10/2009-10-30-10-24-59.png"><img title="2009-10-30 10 24 59" src="http://kitmenke.com/blog/wp-content/uploads/2009/10/2009-10-30-10-24-59.png" alt="2009-10-30 10 24 59" width="281" height="366" /></a></p>
<h2>Symptoms:</h2>
<p>The symptoms of my problem were very strange. After running my app successfully, it seemed as if my updates were simply ignored by the server.</p>
<ol>
<li>The item is <strong>successfully</strong> updated using the Lists.asmx (it even creates a new version!)</li>
<li>The item does not show the updated value for your multi-select choice field in the UI.</li>
</ol>
<h2>The Code:</h2>
<p>Here is the very simple code that is creating the update message:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> AddCountryUpdate<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">ref</span> StringBuilder sb, <span style="color: #FF0000;">int</span> count, <span style="color: #FF0000;">string</span> id, <span style="color: #FF0000;">string</span> newCountry<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    sb.<span style="color: #0000FF;">AppendFormat</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;Method ID='{0}' Cmd='Update'&gt;&quot;</span>, count<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    sb.<span style="color: #0000FF;">AppendFormat</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;Field Name='ID'&gt;{0}&lt;/Field&gt;&quot;</span>, id<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    sb.<span style="color: #0000FF;">AppendFormat</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;Field Name='Country'&gt;{0}&lt;/Field&gt;&quot;</span>, newCountry<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    sb.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;/Method&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Calling the following code to update:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">XmlDocument xmlDoc <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Xml</span></span>.<span style="color: #0000FF;">XmlDocument</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">System.<span style="color: #0000FF;">Xml</span></span>.<span style="color: #0000FF;">XmlElement</span> elBatch <span style="color: #008000;">=</span> xmlDoc.<span style="color: #0000FF;">CreateElement</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Batch&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
elBatch.<span style="color: #0000FF;">InnerXml</span> <span style="color: #008000;">=</span> sb.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
XmlNode ndReturn <span style="color: #008000;">=</span> list.<span style="color: #0000FF;">ListWebSvc</span>.<span style="color: #0000FF;">UpdateListItems</span><span style="color: #000000;">&#40;</span>listName, elBatch<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<h2>The Results:</h2>
<p>Attempting to update Country to be &#8220;;#United States;#Canada;#&#8221; resulted in a &#8221;success&#8221; response (error code of 0&#215;00000000) even when the update was NOT successful:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Result</span> <span style="color: #000066;">ID</span>=<span style="color: #ff0000;">&quot;373,Update&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ErrorCode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0x00000000<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ErrorCode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;z:row</span> <span style="color: #000066;">ows_ID</span>=<span style="color: #ff0000;">&quot;1311&quot;</span> <span style="color: #000066;">ows_Country</span>=<span style="color: #ff0000;">&quot;;#United States;#Canada;#&quot;</span> <span style="color: #000066;">ows_Modified</span>=<span style="color: #ff0000;">&quot;2009-10-29 16:01:05&quot;</span> <span style="color: #000066;">ows__UIVersionString</span>=<span style="color: #ff0000;">&quot;6.0&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Result<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Viewing this in the UI still shows the old value:</p>
<p> <a href="http://kitmenke.com/blog/wp-content/uploads/2009/10/2009-10-30-09-03-47.png"><img class="alignnone size-full wp-image-152" title="Country - Old Value" src="http://kitmenke.com/blog/wp-content/uploads/2009/10/2009-10-30-09-03-47.png" alt="Country - Old Value" width="300" height="30" /></a></p>
<p>However, only after the values are in order, &#8220;;#Canada;#United States;#&#8221;, will the update actually happen.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Result</span> <span style="color: #000066;">ID</span>=<span style="color: #ff0000;">&quot;223,Update&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ErrorCode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0x00000000<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ErrorCode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;z:row</span> <span style="color: #000066;">ows_ID</span>=<span style="color: #ff0000;">&quot;1311&quot;</span> <span style="color: #000066;">ows_Country</span>=<span style="color: #ff0000;">&quot;;#Canada;#United States;#&quot;</span> <span style="color: #000066;">ows_Modified</span>=<span style="color: #ff0000;">&quot;2009-10-30 08:51:45&quot;</span> <span style="color: #000066;">ows__UIVersionString</span>=<span style="color: #ff0000;">&quot;7.0&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Result<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Viewing this in the UI shows the updated value:</p>
<p><a href="http://kitmenke.com/blog/wp-content/uploads/2009/10/2009-10-30-09-04-02.png"><img class="alignnone size-full wp-image-153" title="Country - Correct" src="http://kitmenke.com/blog/wp-content/uploads/2009/10/2009-10-30-09-04-02.png" alt="Country - Correct" width="350" height="30" /></a></p>
<p>Notice it still created a version 6.0 and 7.0:</p>
<p><a href="http://kitmenke.com/blog/wp-content/uploads/2009/10/2009-10-30-11-01-24.png"><img class="alignnone size-full wp-image-161" title="Version History" src="http://kitmenke.com/blog/wp-content/uploads/2009/10/2009-10-30-11-01-24.png" alt="Version History" width="295" height="201" /></a></p>
<h2>Conclusion:</h2>
<p>When updating a multi-select choice field using SharePoint&#8217;s Lists.asmx web service, <strong><span style="color: #ff0000;">the order of the choices in the update message are important</span></strong>. If they are out of order, it will not update.</p>
<img src="http://kitmenke.com/blog/?ak_action=api_record_view&id=148&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kitmenke.com/blog/2009/10/30/updating-choice-fields-via-sharepoint-web-services/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SharePoint&#8217;s SPGridView, filtering, and apostrophes</title>
		<link>http://kitmenke.com/blog/2009/09/05/sharepoints-spgridview-filtering-and-apostrophes/</link>
		<comments>http://kitmenke.com/blog/2009/09/05/sharepoints-spgridview-filtering-and-apostrophes/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 06:10:43 +0000</pubDate>
		<dc:creator>Kit</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Example]]></category>

		<guid isPermaLink="false">http://kitmenke.com/blog/?p=138</guid>
		<description><![CDATA[The SPGridView is one of the most useful SharePoint controls. You can use it to do sorting, grouping, and filtering just like the out of the box List View Web Part does for regular lists and libraries. This makes it relatively easy to create a custom grid with your own data. Unfortunately, filtering with the [...]]]></description>
			<content:encoded><![CDATA[<p>The SPGridView is one of the most useful SharePoint controls. You can use it to do sorting, grouping, and filtering just like the out of the box List View Web Part does for regular lists and libraries. This makes it relatively easy to create a custom grid with your own data. Unfortunately, filtering with the SPGridView is a little quirky, especially if your data could potentially contain apostrophes.</p>
<p><span id="more-138"></span>Essentially, all you need to do is set a few quick properties to enable filtering on the SPGridView. (<a href="http://www.reversealchemy.net/2009/05/24/building-a-spgridview-control-part-2-filtering/">see the great tutorial on Reverse Alchemy for more information</a>)</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Filtering</span>
grid.<span style="color: #0000FF;">AllowFiltering</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
grid.<span style="color: #0000FF;">FilterDataFields</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;,Name,Region,Total Sales&quot;</span><span style="color: #008000;">;</span>
grid.<span style="color: #0000FF;">FilteredDataSourcePropertyName</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;FilterExpression&quot;</span><span style="color: #008000;">;</span>
grid.<span style="color: #0000FF;">FilteredDataSourcePropertyFormat</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;{1} = '{0}'&quot;</span><span style="color: #008000;">;</span></pre></div></div>

<p><a href="http://kitmenke.com/blog/wp-content/uploads/2009/09/2009-09-03-14-04-35.png"><img class="alignnone size-full wp-image-144" title="2009-09-03 14 04 35" src="http://kitmenke.com/blog/wp-content/uploads/2009/09/2009-09-03-14-04-35.png" alt="2009-09-03 14 04 35" width="502" height="170" /></a></p>
<p>However, what happens if you have an apostrophe for the value in one of your filters (for example filtering on the name of O&#8217;Reilly). Eventually, you will end up with a filter of:</p>
<pre>Name = 'O'Reilly'</pre>
<p>If this is the case, when you attempt to filter using that value you will get the error:</p>
<pre>Syntax error: Missing operand after 'Reilly' operator</pre>
<p>(<a href="http://stackoverflow.com/questions/1351578/spgridview-data-and-correct-method-of-ensuring-data-is-safe">See the question asked by Moo on StackOverflow</a>)</p>
<p>So how do you prevent the apostrophes from messing up your filter?</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnPreRender<span style="color: #000000;">&#40;</span>EventArgs e<span style="color: #000000;">&#41;</span>
 <span style="color: #000000;">&#123;</span>
     <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>_gridDS.<span style="color: #0000FF;">FilterExpression</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
     <span style="color: #000000;">&#123;</span>
         _gridDS.<span style="color: #0000FF;">FilterExpression</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span>
             _grid.<span style="color: #0000FF;">FilteredDataSourcePropertyFormat</span>,
             _grid.<span style="color: #0000FF;">FilterFieldValue</span>.<span style="color: #0000FF;">Replace</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;'&quot;</span>, <span style="color: #666666;">&quot;''&quot;</span><span style="color: #000000;">&#41;</span>,
             _grid.<span style="color: #0000FF;">FilterFieldName</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
     <span style="color: #000000;">&#125;</span>
     <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">OnPreRender</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
 <span style="color: #000000;">&#125;</span></pre></div></div>

<p><a href="http://kitmenke.com/blog/wp-content/uploads/2009/09/2009-09-03-14-07-58.png"><img class="alignnone size-full wp-image-145" title="2009-09-03 14 07 58" src="http://kitmenke.com/blog/wp-content/uploads/2009/09/2009-09-03-14-07-58.png" alt="2009-09-03 14 07 58" width="372" height="86" /></a></p>
<p>Where _gridDS is an ObjectDataSource (you must use an ObjectDataSource as opposed to setting the DataSource SPGridView property) and _grid is your SPGridView.</p>
<p>The solution is relatively simple&#8230; but what is happening behind the scenes? Actually, pretty much the same thing but without the replace. The SPGridView looks up your ObjectDataSource using the <em>DataSourceID</em> property. Once it has your ObjectDataSource, it then sets the property specified in FilteredDataSourcePropertyName (FilterExpression) to be the filter. Once you understand that behind the scenes, all it really is doing is setting the FilterExpression on your datasource, it is pretty easy to override the incorrect filter with a correct one.</p>
<img src="http://kitmenke.com/blog/?ak_action=api_record_view&id=138&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kitmenke.com/blog/2009/09/05/sharepoints-spgridview-filtering-and-apostrophes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Filtering a list by Workflow Status</title>
		<link>http://kitmenke.com/blog/2009/08/25/filtering-a-list-by-workflow-status/</link>
		<comments>http://kitmenke.com/blog/2009/08/25/filtering-a-list-by-workflow-status/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 18:25:59 +0000</pubDate>
		<dc:creator>Kit</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://kitmenke.com/blog/?p=131</guid>
		<description><![CDATA[The most recent problem I ran into was when I tried to filter out items that had a  certain Workflow status in the list. More specifically, I was trying to filter on items that had errored out and had a status of &#8220;Error Occurred&#8221; in the list.

My first thought was to try to filter based [...]]]></description>
			<content:encoded><![CDATA[<p>The most recent problem I ran into was when I tried to filter out items that had a  certain Workflow status in the list. More specifically, I was trying to filter on items that had errored out and had a status of &#8220;Error Occurred&#8221; in the list.<br />
<span id="more-131"></span></p>
<p>My first thought was to try to filter based on the text. Using a contains didn&#8217;t work; I got a message about you can only use a contains on Single line of text, Multiple line of text, or Choice fields.</p>
<p>The solution is to filter based on the integer value:<br />
<a href="http://kitmenke.com/blog/wp-content/uploads/2009/08/2009-08-25-12-41-53.png"><img class="alignnone size-full wp-image-132" title="Workflow Status List Filter" src="http://kitmenke.com/blog/wp-content/uploads/2009/08/2009-08-25-12-41-53.png" alt="Workflow Status List Filter" width="370" height="128" /></a></p>
<p>Listed below are the other values in the enum that you can use for the various states.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">enum</span> SPWorkflowStatus
<span style="color: #000000;">&#123;</span>
    NotStarted <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>,
    FailedOnStart <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>,
    InProgress <span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span>,
    ErrorOccurred <span style="color: #008000;">=</span> <span style="color: #FF0000;">3</span>,
    StoppedByUser <span style="color: #008000;">=</span> <span style="color: #FF0000;">4</span>,
    Completed <span style="color: #008000;">=</span> <span style="color: #FF0000;">5</span>,
    FailedOnStartRetrying <span style="color: #008000;">=</span> <span style="color: #FF0000;">6</span>,
    ErrorOccurredRetrying <span style="color: #008000;">=</span> <span style="color: #FF0000;">7</span>,
    ViewQueryOverflow <span style="color: #008000;">=</span> <span style="color: #FF0000;">8</span>,
    Max <span style="color: #008000;">=</span> <span style="color: #FF0000;">15</span>,
<span style="color: #000000;">&#125;</span></pre></div></div>

<img src="http://kitmenke.com/blog/?ak_action=api_record_view&id=131&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kitmenke.com/blog/2009/08/25/filtering-a-list-by-workflow-status/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a SharePoint Alert with different EventTypes</title>
		<link>http://kitmenke.com/blog/2009/08/18/creating-a-sharepoint-alert-with-different-eventtypes/</link>
		<comments>http://kitmenke.com/blog/2009/08/18/creating-a-sharepoint-alert-with-different-eventtypes/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 01:55:00 +0000</pubDate>
		<dc:creator>Kit</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Example]]></category>

		<guid isPermaLink="false">http://kitmenke.com/blog/?p=108</guid>
		<description><![CDATA[I recently ran into a problem creating alerts in a web part for the current user. After the alert was added,  no matter what I set the SPAlert&#8217;s EventType to, it always defaulted to All. I finally figured out a way around this problem thanks to a helpful post by erwin at sharepointology.

The workaround [...]]]></description>
			<content:encoded><![CDATA[<p>I recently ran into a problem creating alerts in a web part for the current user. After the alert was added,  no matter what I set the SPAlert&#8217;s EventType to, it always defaulted to All. I finally figured out a way around this problem thanks to a helpful post by <a href="http://www.sharepointology.com/development/how-to-create-alerts-programmatically/">erwin at sharepointology</a>.</p>
<p><span id="more-108"></span></p>
<p>The workaround involves setting the eventtypeindex in the SPAlert Properties. Since I designed my web part to be configurable, an admin is able to specify the following web part properties</p>
<ul>
<li>SPEventType WPPAlertEventType<br />
(Add, All, Delete, Discussion, Modify)</li>
<li>SPAlertFrequency WPPAlertFrequency<br />
(Daily, Immediate, Weekly)</li>
<li>int WPPAlertTimeHour<br />
(the hour of the day 0 &#8211; 23, only applies to Daily and Weekly alerts)</li>
<li>int WPPAlertTimeDayOfWeek<br />
(the day of the week 0 &#8211; 6, only applies to Weekly alerts)</li>
<li>bool WPPSendConfirmationEmail<br />
(whether or not to send the email saying that they were signed up for the alert)</li>
</ul>
<p>Unfortunately, you can&#8217;t just convert WPPAlertEventType and put it in &#8220;eventtypeindex&#8221; because SPEventType&#8217;s enums were defined to have wacky binary values.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Create an Alert for this List</span>
SPAlert alert <span style="color: #008000;">=</span> currentUser.<span style="color: #0000FF;">Alerts</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
alert.<span style="color: #0000FF;">AlertType</span> <span style="color: #008000;">=</span> SPAlertType.<span style="color: #0000FF;">List</span><span style="color: #008000;">;</span>
alert.<span style="color: #0000FF;">AlertTemplate</span> <span style="color: #008000;">=</span> list.<span style="color: #0000FF;">AlertTemplate</span><span style="color: #008000;">;</span>
alert.<span style="color: #0000FF;">AlwaysNotify</span> <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// DOESN'T WORK SETTING THE EVENT TYPE</span>
<span style="color: #008080; font-style: italic;">//alert.EventType = (SPEventType)WPPAlertEventType;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// you must set the eventtypeindex property</span>
<span style="color: #0600FF;">switch</span> <span style="color: #000000;">&#40;</span>WPPAlertEventType<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
     <span style="color: #0600FF;">case</span> SPEventType.<span style="color: #0000FF;">All</span><span style="color: #008000;">:</span>
          alert.<span style="color: #0000FF;">Properties</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;eventtypeindex&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;0&quot;</span><span style="color: #008000;">;</span>
          break<span style="color: #008000;">;</span>
     <span style="color: #0600FF;">case</span> SPEventType.<span style="color: #0000FF;">Add</span><span style="color: #008000;">:</span>
          alert.<span style="color: #0000FF;">Properties</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;eventtypeindex&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;1&quot;</span><span style="color: #008000;">;</span>
          break<span style="color: #008000;">;</span>
     <span style="color: #0600FF;">case</span> SPEventType.<span style="color: #0000FF;">Modify</span><span style="color: #008000;">:</span>
          alert.<span style="color: #0000FF;">Properties</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;eventtypeindex&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;2&quot;</span><span style="color: #008000;">;</span>
          break<span style="color: #008000;">;</span>
     <span style="color: #0600FF;">case</span> SPEventType.<span style="color: #0000FF;">Delete</span><span style="color: #008000;">:</span>
          alert.<span style="color: #0000FF;">Properties</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;eventtypeindex&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;3&quot;</span><span style="color: #008000;">;</span>
          break<span style="color: #008000;">;</span>
     <span style="color: #0600FF;">case</span> SPEventType.<span style="color: #0000FF;">Discussion</span><span style="color: #008000;">:</span>
          alert.<span style="color: #0000FF;">Properties</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;eventtypeindex&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;4&quot;</span><span style="color: #008000;">;</span>
          break<span style="color: #008000;">;</span>
     <span style="color: #0600FF;">default</span><span style="color: #008000;">:</span>
          break<span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
alert.<span style="color: #0000FF;">AlertFrequency</span> <span style="color: #008000;">=</span> WPPAlertFrequency<span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// get the config for daily/weekly alerts</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// the hours can be anything from 0 to 23</span>
<span style="color: #FF0000;">bool</span> alertTimeHourIsValid <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>WPPAlertTimeHour <span style="color: #008000;">&gt;=</span> <span style="color: #FF0000;">0</span> <span style="color: #008000;">&amp;&amp;</span> WPPAlertTimeHour <span style="color: #008000;">&lt;=</span> <span style="color: #FF0000;">23</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">int</span> alertTimeHour <span style="color: #008000;">=</span> alertTimeHourIsValid <span style="color: #008000;">?</span> WPPAlertTimeHour <span style="color: #008000;">:</span> DEFAULT_WPPAlertTimeHour<span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// the day of the week can be anything 0 to 6 (Sunday = 0 - Saturday = 6)</span>
<span style="color: #FF0000;">bool</span> alertTimeDayOfWeekIsValid <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>WPPAlertTimeDayOfWeek <span style="color: #008000;">&gt;=</span> <span style="color: #FF0000;">0</span> <span style="color: #008000;">&amp;&amp;</span> WPPAlertTimeDayOfWeek <span style="color: #008000;">&lt;=</span> <span style="color: #FF0000;">6</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">int</span> alertTimeDayOfWeek <span style="color: #008000;">=</span> alertTimeDayOfWeekIsValid <span style="color: #008000;">?</span> WPPAlertTimeDayOfWeek <span style="color: #008000;">:</span> DEFAULT_WPPAlertTimeDayOfWeek<span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">switch</span> <span style="color: #000000;">&#40;</span>WPPAlertFrequency<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
     <span style="color: #0600FF;">case</span> SPAlertFrequency.<span style="color: #0000FF;">Daily</span><span style="color: #008000;">:</span>
          DateTime dailyAlertTime <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DateTime<span style="color: #000000;">&#40;</span>DateTime.<span style="color: #0000FF;">Today</span>.<span style="color: #0000FF;">Year</span>, DateTime.<span style="color: #0000FF;">Today</span>.<span style="color: #0000FF;">Month</span>, DateTime.<span style="color: #0000FF;">Today</span>.<span style="color: #0000FF;">Day</span>, alertTimeHour, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
          alert.<span style="color: #0000FF;">AlertTime</span> <span style="color: #008000;">=</span> dailyAlertTime<span style="color: #008000;">;</span>
          break<span style="color: #008000;">;</span>
     <span style="color: #0600FF;">case</span> SPAlertFrequency.<span style="color: #0000FF;">Immediate</span><span style="color: #008000;">:</span>
          break<span style="color: #008000;">;</span>
     <span style="color: #0600FF;">case</span> SPAlertFrequency.<span style="color: #0000FF;">Weekly</span><span style="color: #008000;">:</span>
          DateTime weeklyAlertTime <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DateTime<span style="color: #000000;">&#40;</span>DateTime.<span style="color: #0000FF;">Today</span>.<span style="color: #0000FF;">Year</span>, DateTime.<span style="color: #0000FF;">Today</span>.<span style="color: #0000FF;">Month</span>, DateTime.<span style="color: #0000FF;">Today</span>.<span style="color: #0000FF;">Day</span>, alertTimeHour, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">;</span>
          weeklyAlertTime <span style="color: #008000;">=</span> weeklyAlertTime.<span style="color: #0000FF;">AddDays</span><span style="color: #000000;">&#40;</span>alertTimeDayOfWeek <span style="color: #008000;">-</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">double</span><span style="color: #000000;">&#41;</span>weeklyAlertTime.<span style="color: #0000FF;">DayOfWeek</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
          alert.<span style="color: #0000FF;">AlertTime</span> <span style="color: #008000;">=</span> weeklyAlertTime<span style="color: #008000;">;</span>
          break<span style="color: #008000;">;</span>
     <span style="color: #0600FF;">default</span><span style="color: #008000;">:</span>
          break<span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
alert.<span style="color: #0000FF;">List</span> <span style="color: #008000;">=</span> list<span style="color: #008000;">;</span>
alert.<span style="color: #0000FF;">Title</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;{0} ({1} {2})&quot;</span>, list.<span style="color: #0000FF;">Title</span>, WPPAlertEventType, WPPAlertFrequency<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">bool</span> sendConfirmationEmail <span style="color: #008000;">=</span> WPPSendConfirmationEmail<span style="color: #008000;">;</span>
alert.<span style="color: #0000FF;">Update</span><span style="color: #000000;">&#40;</span>sendConfirmationEmail<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>References:</p>
<ul>
<li><a href="http://www.sharepointology.com/development/how-to-create-alerts-programmatically/">How To Create Alerts Programmatically</a></li>
</ul>
<img src="http://kitmenke.com/blog/?ak_action=api_record_view&id=108&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kitmenke.com/blog/2009/08/18/creating-a-sharepoint-alert-with-different-eventtypes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AutoIt3 script to auto resize windows</title>
		<link>http://kitmenke.com/blog/2009/07/31/autoit3-script-to-auto-resize-windows/</link>
		<comments>http://kitmenke.com/blog/2009/07/31/autoit3-script-to-auto-resize-windows/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 14:58:09 +0000</pubDate>
		<dc:creator>Kit</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AutoIt3]]></category>
		<category><![CDATA[Example]]></category>

		<guid isPermaLink="false">http://kitmenke.com/blog/?p=103</guid>
		<description><![CDATA[One thing that bugs me all the time is when a window doesn&#8217;t remember the position that it was resized or moved to. Although it is more of a nuisance than anything else, I decided to write a little AutoIt3 script to automatically resize my Remote Desktop windows to be the certain place and size that [...]]]></description>
			<content:encoded><![CDATA[<p>One thing that bugs me all the time is when a window doesn&#8217;t remember the position that it was resized or moved to. Although it is more of a nuisance than anything else, I decided to write a little AutoIt3 script to automatically resize my Remote Desktop windows to be the certain place and size that I prefer them to be in.</p>
<p><span id="more-103"></span></p>
<p>The following script will find any windows that have &#8220;Remote Desktop&#8221; in the title and resize them to be their maximum height and width. In fact, I tweaked it a little bit so that the window actually falls outside of the screen. This way I have more screen real estate for the desktop that I&#8217;m working in and I will also be able to quickly move between windows on my desktop.</p>

<div class="wp_syntax"><div class="code"><pre class="autoit" style="font-family:monospace;"><span style="font-style: italic; color: #009933;">;********************************************************************************</span>
<span style="font-style: italic; color: #009933;">; Filename: maximize_window.au3</span>
<span style="font-style: italic; color: #009933;">; Author: Kit Menke</span>
<span style="font-style: italic; color: #009933;">; Date: July 30, 2009</span>
<span style="font-style: italic; color: #009933;">; Description:</span>
<span style="font-style: italic; color: #009933;">;   Resizes any window matching a certain search string to the given dimensions.</span>
<span style="font-style: italic; color: #009933;">;   Useful for Windows you find you have to constantly resize.</span>
<span style="font-style: italic; color: #009933;">;********************************************************************************</span>
&nbsp;
<span style="font-style: italic; color: #009933;">; any window that contains the following string will be resized</span>
<span style="font-weight: bold; color: #AA0000;">$windowTitleContains</span> <span style="color: #FF0000; font-weight: bold;">=</span> <span style="font-weight: bold; color: #008080;">&quot;Remote Desktop&quot;</span>
&nbsp;
<span style="font-style: italic; color: #009933;">; only match exact title names in this script</span>
<span style="color: #000080; font-style: italic; font-weight: bold;">Opt</span><span style="color: #FF0000; font-weight: bold;">&#40;</span><span style="font-weight: bold; color: #008080;">&quot;WinTitleMatchMode&quot;</span><span style="color: #FF0000; font-weight: bold;">,</span> <span style="color: #AC00A9; font-style: italic; font-weight: bold;">3</span><span style="color: #FF0000; font-weight: bold;">&#41;</span>     <span style="font-style: italic; color: #009933;">;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase</span>
&nbsp;
<span style="font-style: italic; color: #009933;">; the new dimensions of the window to be resized to</span>
<span style="font-style: italic; color: #009933;">; top left corner (x,y) coordinates</span>
<span style="font-weight: bold; color: #AA0000;">$winX</span> <span style="color: #FF0000; font-weight: bold;">=</span> <span style="color: #FF0000; font-weight: bold;">-</span><span style="color: #AC00A9; font-style: italic; font-weight: bold;">4</span>
<span style="font-weight: bold; color: #AA0000;">$winY</span> <span style="color: #FF0000; font-weight: bold;">=</span> <span style="color: #FF0000; font-weight: bold;">-</span><span style="color: #AC00A9; font-style: italic; font-weight: bold;">29</span>
<span style="font-style: italic; color: #009933;">; the window's new width and height</span>
<span style="font-weight: bold; color: #AA0000;">$winWidth</span> <span style="color: #FF0000; font-weight: bold;">=</span> <span style="color: #AC00A9; font-style: italic; font-weight: bold;">1024</span> <span style="color: #FF0000; font-weight: bold;">-</span> <span style="font-weight: bold; color: #AA0000;">$winX</span><span style="color: #FF0000; font-weight: bold;">*</span><span style="color: #AC00A9; font-style: italic; font-weight: bold;">2</span>
<span style="font-weight: bold; color: #AA0000;">$winHeight</span> <span style="color: #FF0000; font-weight: bold;">=</span> <span style="color: #AC00A9; font-style: italic; font-weight: bold;">768</span> <span style="color: #FF0000; font-weight: bold;">-</span> <span style="font-weight: bold; color: #AA0000;">$winY</span>
&nbsp;
<span style="font-style: italic; color: #009933;">; get the list of windows and the string you want to check for</span>
<span style="font-weight: bold; color: #AA0000;">$var</span> <span style="color: #FF0000; font-weight: bold;">=</span> <span style="color: #000080; font-style: italic; font-weight: bold;">WinList</span><span style="color: #FF0000; font-weight: bold;">&#40;</span><span style="color: #FF0000; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #0000FF; font-weight: bold;">For</span> <span style="font-weight: bold; color: #AA0000;">$i</span> <span style="color: #FF0000; font-weight: bold;">=</span> <span style="color: #AC00A9; font-style: italic; font-weight: bold;">1</span> <span style="color: #0000FF; font-weight: bold;">to</span> <span style="font-weight: bold; color: #AA0000;">$var</span><span style="color: #FF0000; font-weight: bold;">&#91;</span><span style="color: #AC00A9; font-style: italic; font-weight: bold;">0</span><span style="color: #FF0000; font-weight: bold;">&#93;</span><span style="color: #FF0000; font-weight: bold;">&#91;</span><span style="color: #AC00A9; font-style: italic; font-weight: bold;">0</span><span style="color: #FF0000; font-weight: bold;">&#93;</span>
  <span style="font-style: italic; color: #009933;">; Only display visble windows that have a title matching our search string</span>
  <span style="font-weight: bold; color: #AA0000;">$windowTitle</span> <span style="color: #FF0000; font-weight: bold;">=</span> <span style="font-weight: bold; color: #AA0000;">$var</span><span style="color: #FF0000; font-weight: bold;">&#91;</span><span style="font-weight: bold; color: #AA0000;">$i</span><span style="color: #FF0000; font-weight: bold;">&#93;</span><span style="color: #FF0000; font-weight: bold;">&#91;</span><span style="color: #AC00A9; font-style: italic; font-weight: bold;">0</span><span style="color: #FF0000; font-weight: bold;">&#93;</span>
  <span style="font-weight: bold; color: #AA0000;">$containsTitle</span> <span style="color: #FF0000; font-weight: bold;">=</span> <span style="color: #000080; font-style: italic; font-weight: bold;">StringInStr</span><span style="color: #FF0000; font-weight: bold;">&#40;</span><span style="font-weight: bold; color: #AA0000;">$windowTitle</span><span style="color: #FF0000; font-weight: bold;">,</span><span style="font-weight: bold; color: #AA0000;">$windowTitleContains</span><span style="color: #FF0000; font-weight: bold;">&#41;</span>
  <span style="color: #0000FF; font-weight: bold;">If</span> <span style="font-weight: bold; color: #AA0000;">$windowTitle</span> <span style="color: #FF0000; font-weight: bold;">&lt;&gt;</span> <span style="font-weight: bold; color: #008080;">&quot;&quot;</span> <span style="color: #0000FF; font-weight: bold;">AND</span> IsVisible<span style="color: #FF0000; font-weight: bold;">&#40;</span><span style="font-weight: bold; color: #AA0000;">$windowTitle</span><span style="color: #FF0000; font-weight: bold;">&#41;</span> <span style="color: #0000FF; font-weight: bold;">AND</span> <span style="color: #AC00A9; font-style: italic; font-weight: bold;">0</span> <span style="color: #FF0000; font-weight: bold;">&lt;&gt;</span> <span style="font-weight: bold; color: #AA0000;">$containsTitle</span> <span style="color: #0000FF; font-weight: bold;">Then</span>
    ResizeWindowWithExactTitle<span style="color: #FF0000; font-weight: bold;">&#40;</span><span style="font-weight: bold; color: #AA0000;">$windowTitle</span><span style="color: #FF0000; font-weight: bold;">&#41;</span>
  <span style="color: #0000FF; font-weight: bold;">EndIf</span>
<span style="color: #0000FF; font-weight: bold;">Next</span>
&nbsp;
<span style="color: #0000FF; font-weight: bold;">Exit</span>
&nbsp;
<span style="color: #0000FF; font-weight: bold;">Func</span> IsVisible<span style="color: #FF0000; font-weight: bold;">&#40;</span><span style="font-weight: bold; color: #AA0000;">$handle</span><span style="color: #FF0000; font-weight: bold;">&#41;</span>
  <span style="color: #0000FF; font-weight: bold;">If</span> <span style="color: #000080; font-style: italic; font-weight: bold;">BitAnd</span><span style="color: #FF0000; font-weight: bold;">&#40;</span> <span style="color: #000080; font-style: italic; font-weight: bold;">WinGetState</span><span style="color: #FF0000; font-weight: bold;">&#40;</span><span style="font-weight: bold; color: #AA0000;">$handle</span><span style="color: #FF0000; font-weight: bold;">&#41;</span><span style="color: #FF0000; font-weight: bold;">,</span> <span style="color: #AC00A9; font-style: italic; font-weight: bold;">2</span> <span style="color: #FF0000; font-weight: bold;">&#41;</span> <span style="color: #0000FF; font-weight: bold;">Then</span>
    <span style="color: #0000FF; font-weight: bold;">Return</span> <span style="color: #AC00A9; font-style: italic; font-weight: bold;">1</span>
  <span style="color: #0000FF; font-weight: bold;">Else</span>
    <span style="color: #0000FF; font-weight: bold;">Return</span> <span style="color: #AC00A9; font-style: italic; font-weight: bold;">0</span>
  <span style="color: #0000FF; font-weight: bold;">EndIf</span>
<span style="color: #0000FF; font-weight: bold;">EndFunc</span>
&nbsp;
<span style="color: #0000FF; font-weight: bold;">Func</span> ResizeWindowWithExactTitle<span style="color: #FF0000; font-weight: bold;">&#40;</span><span style="font-weight: bold; color: #AA0000;">$winTitle</span><span style="color: #FF0000; font-weight: bold;">&#41;</span>
    <span style="color: #0000FF; font-weight: bold;">If</span> <span style="color: #000080; font-style: italic; font-weight: bold;">WinExists</span><span style="color: #FF0000; font-weight: bold;">&#40;</span><span style="font-weight: bold; color: #AA0000;">$winTitle</span><span style="color: #FF0000; font-weight: bold;">&#41;</span> <span style="color: #0000FF; font-weight: bold;">Then</span>
        <span style="color: #000080; font-style: italic; font-weight: bold;">WinMove</span><span style="color: #FF0000; font-weight: bold;">&#40;</span><span style="font-weight: bold; color: #AA0000;">$winTitle</span><span style="color: #FF0000; font-weight: bold;">,</span> <span style="font-weight: bold; color: #008080;">&quot;&quot;</span><span style="color: #FF0000; font-weight: bold;">,</span> <span style="font-weight: bold; color: #AA0000;">$winX</span><span style="color: #FF0000; font-weight: bold;">,</span> <span style="font-weight: bold; color: #AA0000;">$winY</span><span style="color: #FF0000; font-weight: bold;">,</span> <span style="font-weight: bold; color: #AA0000;">$winWidth</span><span style="color: #FF0000; font-weight: bold;">,</span> <span style="font-weight: bold; color: #AA0000;">$winHeight</span><span style="color: #FF0000; font-weight: bold;">&#41;</span>
    <span style="color: #0000FF; font-weight: bold;">EndIf</span>
<span style="color: #0000FF; font-weight: bold;">EndFunc</span></pre></div></div>

<p>I then set up a little CMD file to call my au3 file (assumes AutoIt3.exe is in the same directory as your script, but you can obviously make this be whatever you want):</p>
<blockquote><p>AutoIt3.exe maximize_window.au3</p></blockquote>
<p>And then I have a shortcut to that CMD file on my quicklaunch that I can call whenever I need to resize my windows.</p>
<img src="http://kitmenke.com/blog/?ak_action=api_record_view&id=103&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://kitmenke.com/blog/2009/07/31/autoit3-script-to-auto-resize-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
