<?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; Extension Methods</title>
	<atom:link href="http://www.sambeauvois.be/blog/category/extensionmethods/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>Get the first day of the current week</title>
		<link>http://www.sambeauvois.be/blog/2011/02/get-the-first-day-of-the-current-week/</link>
		<comments>http://www.sambeauvois.be/blog/2011/02/get-the-first-day-of-the-current-week/#comments</comments>
		<pubDate>Thu, 24 Feb 2011 16:00:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Extension Methods]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=871</guid>
		<description><![CDATA[Here is a quick way to get the first day of the current week. If you are happy with sunday as the first day of the week, then you can simply do this : public static DateTime FirstDayOfWeek(this DateTime date) { return DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek); } But if you want that the first day of the week [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a quick way to get the first day of the current week.</p>
<p>If you are happy with sunday as the first day of the week, then you can simply do this :</p>
<pre class="brush: csharp; title: ;">

 public static DateTime FirstDayOfWeek(this DateTime date)
 {
            return DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek);
 }
</pre>
<p>But if you want that the first day of the week matches your culture (eg: the belgian week starts on monday), you have to take care of the culture&#8217;s DateTime format.</p>
<p>So the method will change a bit :</p>
<pre class="brush: csharp; title: ;">

public static DateTime FirstDayOfWeek(this DateTime date)
{
     return DateTime.Today.AddDays(-((int)DateTime.Today.DayOfWeek - (int)CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek));
}
</pre>
</pre>
<h5>Usage :</h5>
<pre class="brush: csharp; title: ;">

    DateTime FirstDayOfWeek = DateTime.Today.FirstDayOfWeek();
</pre>
<p>or</p>
<pre class="brush: csharp; title: ;">
 DateTime FirstDayOfWeek = DateTime.Now.FirstDayOfWeek();
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2011/02/get-the-first-day-of-the-current-week/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>

