<?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>Sam Beauvois &#187; Sharepoint</title>
	<atom:link href="http://www.sambeauvois.be/blog/category/sharepoint/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sambeauvois.be/blog</link>
	<description>general dev, .net and other stuff</description>
	<lastBuildDate>Tue, 31 Jan 2012 13:38:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Use ASP.NET Validators with the SharePoint:DateTimeControl</title>
		<link>http://www.sambeauvois.be/blog/2010/03/use-asp-net-validators-with-the-sharepointdatetimecontrol/</link>
		<comments>http://www.sambeauvois.be/blog/2010/03/use-asp-net-validators-with-the-sharepointdatetimecontrol/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 09:54:21 +0000</pubDate>
		<dc:creator>Sam Beauvois</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Sharepoint]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=222</guid>
		<description><![CDATA[If you want to use asp.net validation system with the SharePoint’s DateTimeControl, the first thing you need to know is that this control is “just” a wrapper around simple ASP.NET controls (textbox, dropdownlist). If you want to set the ControlToValidate property of an ASP.NET validator to the DateTimeControl’s ID, it will throw an error! As [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to use asp.net validation system with the SharePoint’s DateTimeControl, the first thing you need to know is that this control is “just” a wrapper around simple ASP.NET controls (textbox, dropdownlist).</p>
<p>If you want to set the ControlToValidate property of an ASP.NET validator to the DateTimeControl’s ID, it will throw an error!<br />
As you can guess, you have to target the controls inside the DateTimeControl.</p>
<p>Since the DateTimeControl set the name of the controls programmatically, you can retrieve the id of the control:</p>
<ul>
<li>Textbox date: DateTimeControl.ID +”Date”</li>
<li>Dropdownlist hours: DateTimeControl.ID +”DateHours”</li>
<li>Dropdownlist minutes: DateTimeControl.ID +”DateMinutes”</li>
</ul>
<h3>Example:</h3>
<p>If you use the SharePoint:DateTimeControl with the TimeOnly property set to “true”</p>
<pre class="brush: xml; title: ;">

&lt;SharePoint:DateTimeControl runat=&quot;server&quot; ID=&quot;TheTime&quot; TimeOnly=&quot;true&quot;/&gt;
</pre>
<p>You’ll have two dropdownlists, one for the hours and one for the minutes<br />
The DateTimeControl set the name:</p>
<p>Dropdownlist hours: DateTimeControl.ID +”DateHours”</p>
<p>Html will be:</p>
<pre class="brush: xml; title: ;">
&lt;select name=&quot;ctl00$PlaceHolderMain$ctl07$ctl02$TheTime$TheTimeDateHours&quot; id=&quot;ctl00_PlaceHolderMain_ctl07_ctl02_TheTime_TheTimeDateHours&quot; dir=&quot;ltr&quot;&gt;
 &lt;option value=&quot;00:&quot;&gt;00:&lt;/option&gt;
 &lt;option value=&quot;01:&quot;&gt;01:&lt;/option&gt;
 &lt;option value=&quot;02:&quot;&gt;02:&lt;/option&gt;
 &lt;option value=&quot;03:&quot;&gt;03:&lt;/option&gt;
 &lt;option value=&quot;04:&quot;&gt;04:&lt;/option&gt;
 &lt;option value=&quot;05:&quot;&gt;05:&lt;/option&gt;
 &lt;option value=&quot;06:&quot;&gt;06:&lt;/option&gt;
 &lt;option value=&quot;07:&quot;&gt;07:&lt;/option&gt;
 &lt;option value=&quot;08:&quot;&gt;08:&lt;/option&gt;
 &lt;option value=&quot;09:&quot;&gt;09:&lt;/option&gt;
 &lt;option value=&quot;10:&quot;&gt;10:&lt;/option&gt;
 &lt;option value=&quot;11:&quot;&gt;11:&lt;/option&gt;
 &lt;option value=&quot;12:&quot;&gt;12:&lt;/option&gt;
 &lt;option value=&quot;13:&quot;&gt;13:&lt;/option&gt;
 &lt;option value=&quot;14:&quot;&gt;14:&lt;/option&gt;
 &lt;option value=&quot;15:&quot;&gt;15:&lt;/option&gt;
 &lt;option value=&quot;16:&quot;&gt;16:&lt;/option&gt;
 &lt;option value=&quot;17:&quot;&gt;17:&lt;/option&gt;
 &lt;option value=&quot;18:&quot;&gt;18:&lt;/option&gt;
 &lt;option value=&quot;19:&quot;&gt;19:&lt;/option&gt;
 &lt;option value=&quot;20:&quot;&gt;20:&lt;/option&gt;
 &lt;option value=&quot;21:&quot;&gt;21:&lt;/option&gt;
 &lt;option value=&quot;22:&quot;&gt;22:&lt;/option&gt;
 &lt;option value=&quot;23:&quot;&gt;23:&lt;/option&gt;
&lt;/select&gt;
</pre>
<p>Dropdownlist minutes: DateTimeControl.ID +”DateMinutes”<br />
Html will be:</p>
<pre class="brush: xml; title: ;">
&lt;select name=&quot;ctl00$PlaceHolderMain$ctl07$ctl02$TheTime$TheTimeDateMinutes&quot; id=&quot;ctl00_PlaceHolderMain_ctl07_ctl02_TheTime_TheTimeDateMinutes&quot; dir=&quot;ltr&quot;&gt;
 &lt;option value=&quot;00&quot;&gt;00&lt;/option&gt;
 &lt;option value=&quot;05&quot;&gt;05&lt;/option&gt;
 &lt;option value=&quot;10&quot;&gt;10&lt;/option&gt;
 &lt;option value=&quot;15&quot;&gt;15&lt;/option&gt;
 &lt;option value=&quot;20&quot;&gt;20&lt;/option&gt;
 &lt;option value=&quot;25&quot;&gt;25&lt;/option&gt;
 &lt;option value=&quot;30&quot;&gt;30&lt;/option&gt;
 &lt;option value=&quot;35&quot;&gt;35&lt;/option&gt;
 &lt;option value=&quot;40&quot;&gt;40&lt;/option&gt;
 &lt;option value=&quot;45&quot;&gt;45&lt;/option&gt;
 &lt;option value=&quot;50&quot;&gt;50&lt;/option&gt;
 &lt;option value=&quot;55&quot;&gt;55&lt;/option&gt;
&lt;/select&gt;
</pre>
<p><strong>So you can retrieve the ASP.NET controls by using :</strong></p>
<ul>
<li>For the date: TheTime$TheTimeDate</li>
<li>For the hours: TheTime$TheTimeDateHours</li>
<li>For the minutes: TheTime$TheTimeDateMinutes</li>
</ul>
<h3>Real case example:</h3>
<p>I have two DateTimeControl, one named TheStartTime and one other named TheEndTime,</p>
<p>I want to validate that the end time is not before the start time.</p>
<p>So I’ll use the ASP.NET comparevalidator validator to compare the hours:</p>
<pre class="brush: xml; title: ;">
&lt;asp:CompareValidator id=&quot;valDate&quot; runat=&quot;server&quot; ControlToValidate=&quot;TheEndTime$TheEndTimeDateHours&quot; ControlToCompare=&quot;TheStartTime$TheStartTimeDateHours&quot;
 Type=&quot;Integer&quot;
 Operator=&quot;GreaterThanEqual&quot;
 ErrorMessage=&quot;The end time must be greater than the start time&quot;&gt;
 &lt;/asp:CompareValidator &gt;
</pre>
<p>Now, if you want to validate both hours and minutes, one option is to add an “asp:CustomValidator” and check conditions server side :<br />
Markup:</p>
<pre class="brush: xml; title: ;">
&lt;asp:CustomValidator runat=&quot;server&quot; ID=&quot;EndTimeMustBeLaterThanStartTimeCustomValidator&quot;
EnableClientScript=&quot;false&quot; ErrorMessage=&quot;Start time must be before end time&quot;/&gt;
</pre>
<p>Before the action, validate:</p>
<pre class="brush: csharp; title: ;">
if (!IsEndTimeLaterThanStartTime())
{
 EndTimeMustBeLaterThanStartTimeCustomValidator.IsValid = false;
 return;
}
</pre>
<p>Validation method:</p>
<pre class="brush: csharp; title: ;">

private bool IsEndTimeLaterThanStartTime()
{
 // retrieve the DropDownList
 DropDownList startHours = TheStartTime.FindControl(&quot;TheStartTimeDateHours&quot;) as DropDownList;
 DropDownList endHours = TheEndTime.FindControl(&quot;TheEndTimeDateHours&quot;) as DropDownList;

 // prevent from errors
 if (startHours == null ||
 endHours == null ||
 string.IsNullOrEmpty(startHours.SelectedValue) ||
 string.IsNullOrEmpty(endHours.SelectedValue))
 {
 return; // dont' do anything
 }

// the hour value is &quot;00:&quot;
 int startHour = Convert.ToInt32(startHours.SelectedValue.Replace(&quot;:&quot;,&quot;&quot;));
 int endHour = Convert.ToInt32(endHours.SelectedValue.Replace(&quot;:&quot;, &quot;&quot;));
 if (endHour &lt; startHour)
 {
 args.IsValid = false;
 }
 else
 {

 if (endHour == startHour)
 {
 // check the minutes
 DropDownList startMinutes = TheStartTime.FindControl(&quot;TheStartTimeDateMinutes&quot;) as DropDownList;
 DropDownList endMinutes = TheEndTime.FindControl(&quot;TheEndTimeDateMinutes&quot;) as DropDownList;
 // prevent from errors
 if (startMinutes == null ||
 endMinutes == null ||
 string.IsNullOrEmpty(startMinutes.SelectedValue) ||
 string.IsNullOrEmpty(endMinutes.SelectedValue))
 {
 return; // dont' do anything
 }

 int startMinute = Convert.ToInt32(startMinutes.SelectedValue);
 int endMinute = Convert.ToInt32(endMinutes.SelectedValue);

 if (endHour &lt;= startMinute)
 args.IsValid = false;

 }
 }

 args.IsValid = true;

 }
</pre>
<p>You can also validate the Date himself if you choose to display it,<br />
you can make a client side validation if you know javascript,<br />
you can do everything like in “classic” ASP.NET.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2010/03/use-asp-net-validators-with-the-sharepointdatetimecontrol/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get the parent Folder for a SPListItem</title>
		<link>http://www.sambeauvois.be/blog/2010/02/get-the-parent-folder-for-a-splistitem/</link>
		<comments>http://www.sambeauvois.be/blog/2010/02/get-the-parent-folder-for-a-splistitem/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 18:23:08 +0000</pubDate>
		<dc:creator>Sam Beauvois</dc:creator>
				<category><![CDATA[Extension Methods]]></category>
		<category><![CDATA[Reminders]]></category>
		<category><![CDATA[Sharepoint]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=203</guid>
		<description><![CDATA[To retrieve the parent folder my extension method public static SPFolder GetParentFolder(this SPListItem spListItem) { if (spListItem == null) return null; SPFile spFile = spListItem.Web.GetFile(spListItem.Url); if (spFile == null) return null; return spFile.ParentFolder; } Use SPFolder parentFolder = sPListItem.GetParentFolder(); if (parentFolder != null) { // do some stuffs.. } public static SPFolder GetParentFolder(this SPListItem spListItem) [...]]]></description>
			<content:encoded><![CDATA[<p>To retrieve the parent folder</p>
<p>my extension method</p>
<pre class="brush: csharp; title: ;">

public static SPFolder GetParentFolder(this SPListItem spListItem)

{

if (spListItem == null)

return null;

SPFile spFile = spListItem.Web.GetFile(spListItem.Url);

if (spFile == null)

return null;

return spFile.ParentFolder;

}
</pre>
<p>Use</p>
<pre class="brush: csharp; title: ;">

SPFolder parentFolder = sPListItem.GetParentFolder();

if (parentFolder != null)

{

// do some stuffs..

}
</pre>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">public static SPFolder GetParentFolder(this SPListItem spListItem)</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">{</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">if (spListItem == null)</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">return null;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">SPFile spFile = spListItem.Web.GetFile(spListItem.Url);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">if (spFile == null)</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">return null;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">return spFile.ParentFolder;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}[/csharp]</div>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2010/02/get-the-parent-folder-for-a-splistitem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

