<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1547054644249623125</id><updated>2011-11-28T02:31:07.246+01:00</updated><category term='C#'/><category term='LINQ'/><category term='Windows Mobile'/><category term='WCM'/><category term='Visual Studio'/><category term='Publishing'/><category term='General'/><category term='.NET Compact'/><category term='Agile'/><category term='Scrum'/><category term='SharePoint'/><category term='Generics'/><category term='WSS'/><category term='ASP.NET'/><title type='text'>Weblog Danny de Haas [Macaw]</title><subtitle type='html'>Exploring .NET, SharePoint and Beyond</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://ddehaas.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://ddehaas.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Danny de Haas</name><uri>http://www.blogger.com/profile/03475646948477442965</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>16</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1547054644249623125.post-1513421295960157121</id><published>2010-03-30T23:01:00.002+02:00</published><updated>2010-04-24T16:24:37.241+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='LINQ'/><title type='text'>Using LINQ to get filenames from a directory structure using multiple include and exclude patterns</title><content type='html'>&lt;p&gt;This example shows how to get list of file names from a directory (including subdirectories) using multiple include- and exclude patterns.&lt;/p&gt;&lt;p&gt;The buildin method System.IO.Directory.GetFiles can handle only one include pattern and no exclude pattern and multiple patterns a definitely out of the question.&lt;/p&gt;&lt;p&gt;So I had to write a little helper method using LINQ to do the trick!&lt;/p&gt;&lt;pre class="brush: c-sharp;"&gt;/// &amp;lt;summary&amp;gt;
/// Get the files from the specified path, including subdirectories, which match the specified pattern.
/// Note: To specified multiple patterns, separate them by a semicolumn (;)
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name="path"&amp;gt;The path.&amp;lt;/param&amp;gt;
/// &amp;lt;param name="includePatterns"&amp;gt;An array of include patterns. Using wildcards.&amp;lt;/param&amp;gt;
/// &amp;lt;param name="excludePatterns"&amp;gt;An array of exclude patterns. Using Regular expressions.&amp;lt;/param&amp;gt;
/// &amp;lt;returns&amp;gt;Returns an array of filenames.&amp;lt;/returns&amp;gt;
public static string[] GetFiles(string path, string[] includePatterns, string[] excludePatterns)
{
 if (string.IsNullOrEmpty(path))
 {
  throw new ArgumentNullException("path", "Argument should not be NULL or an empty string.");
 }
 if (includePatterns == null)
 {
  includePatterns = new string[0];
 }
 if (excludePatterns == null)
 {
  excludePatterns = new string[0];
 }

 var files = from includePattern in includePatterns
    from includeFile in Directory.GetFiles(path, includePattern, SearchOption.AllDirectories)
    from excludePattern in excludePatterns.DefaultIfEmpty()
    where excludePattern == null || !Regex.IsMatch(includeFile, excludePattern, RegexOptions.IgnoreCase)
    select includeFile;

 return files.ToArray();
}
&lt;/pre&gt;&lt;p&gt;The following example gets all files that match the wildcard patterns 'DdH.*.Helpers.dll' &amp;amp; 'DdH.*.exe' from the c:\temp directory, but will exclude all files that match the regular expression 'Tests\.dll'.&lt;/p&gt;&lt;pre class="brush: c-sharp;"&gt;string[] fileNames = GetFiles(@"c:\temp", new string[] { "DdH.Helpers.*.dll", "DdH.*.exe" }, new string[] { "Tests\.dll" });
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1547054644249623125-1513421295960157121?l=ddehaas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ddehaas.blogspot.com/feeds/1513421295960157121/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ddehaas.blogspot.com/2010/03/using-linq-to-get-filenames-from.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/1513421295960157121'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/1513421295960157121'/><link rel='alternate' type='text/html' href='http://ddehaas.blogspot.com/2010/03/using-linq-to-get-filenames-from.html' title='Using LINQ to get filenames from a directory structure using multiple include and exclude patterns'/><author><name>Danny de Haas</name><uri>http://www.blogger.com/profile/03475646948477442965</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1547054644249623125.post-7014960448534046131</id><published>2010-02-07T22:47:00.000+01:00</published><updated>2010-02-07T23:05:58.357+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Scrum'/><category scheme='http://www.blogger.com/atom/ns#' term='Agile'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET Compact'/><category scheme='http://www.blogger.com/atom/ns#' term='Windows Mobile'/><title type='text'>Agile Poker Cards For Windows Mobile</title><content type='html'>&lt;p&gt;I just release my first Windows Mobile Application on &lt;a href="http://www.codeplex.com/" target="_blank"&gt;CodePlex&lt;/a&gt;. :-)&lt;/p&gt;  &lt;p&gt;It’s use is to display poker cards during a planning session.&lt;/p&gt;  &lt;p&gt;During a scrum or other agile processes, you have to estimate the size of a user story during a planning session.    &lt;br /&gt;With this little program there is no need for using real cards anymore!&lt;/p&gt;  &lt;p&gt;Tools I used to develop this little application:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Microsoft Visual Studio 2008 &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/netframework/aa497273.aspx" target="_blank"&gt;.NET Compact Framework 3.5&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=06111A3A-A651-4745-88EF-3D48091A390B&amp;amp;displaylang=en" target="_blank"&gt;Windows Mobile 6 Professional and Standard SDK Refresh&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=20686a1d-97a8-4f80-bc6a-ae010e085a6e" target="_blank"&gt;Windows Mobile 6.5 Developer Tool Kit&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.getpaint.net/" target="_blank"&gt;Paint.NET&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.icofx.ro/" target="_blank"&gt;IcoFX&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The program works really simple...    &lt;br /&gt;Just press a button and it will display the symbol in full screen. (nothing more, nothing less)&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td&gt;&lt;a href="http://lh5.ggpht.com/_QtiDs9W18t0/S285PpAvTEI/AAAAAAAAAKw/xv3INoKQwSA/s1600-h/AGP1%5B2%5D.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="AGP1" border="0" alt="AGP1" src="http://lh3.ggpht.com/_QtiDs9W18t0/S285QOAvQoI/AAAAAAAAAK0/tDYMeqMSmAY/AGP1_thumb.jpg?imgmax=800" width="156" height="244" /&gt;&lt;/a&gt; &lt;/td&gt;        &lt;td&gt;&lt;a href="http://lh5.ggpht.com/_QtiDs9W18t0/S285Qf5gpgI/AAAAAAAAAK4/b8i8msKITWk/s1600-h/AGP2%5B2%5D.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="AGP2" border="0" alt="AGP2" src="http://lh6.ggpht.com/_QtiDs9W18t0/S285QgesjTI/AAAAAAAAAK8/hyc3uosTUaI/AGP2_thumb.jpg?imgmax=800" width="244" height="156" /&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td&gt;&lt;a href="http://lh3.ggpht.com/_QtiDs9W18t0/S285RKlrNZI/AAAAAAAAALA/MsA88-_nEfQ/s1600-h/AGP3%5B2%5D.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="AGP3" border="0" alt="AGP3" src="http://lh5.ggpht.com/_QtiDs9W18t0/S285Rax0l-I/AAAAAAAAALE/hKCVnSPD7FA/AGP3_thumb.jpg?imgmax=800" width="156" height="244" /&gt;&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;To download or read more, go to the projectsite: &lt;a href="http://agilepokercards.codeplex.com/"&gt;Agile Poker Cards&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1547054644249623125-7014960448534046131?l=ddehaas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ddehaas.blogspot.com/feeds/7014960448534046131/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ddehaas.blogspot.com/2010/02/agile-poker-cards-for-windows-mobile.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/7014960448534046131'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/7014960448534046131'/><link rel='alternate' type='text/html' href='http://ddehaas.blogspot.com/2010/02/agile-poker-cards-for-windows-mobile.html' title='Agile Poker Cards For Windows Mobile'/><author><name>Danny de Haas</name><uri>http://www.blogger.com/profile/03475646948477442965</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/_QtiDs9W18t0/S285QOAvQoI/AAAAAAAAAK0/tDYMeqMSmAY/s72-c/AGP1_thumb.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1547054644249623125.post-4620467805882364627</id><published>2009-10-19T20:30:00.002+02:00</published><updated>2009-10-20T09:59:30.734+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><title type='text'>What’s new with SharePoint Server 2010 Web Content Management</title><content type='html'>&lt;p&gt;I’ve been waiting for this information like this since Microsoft announced a new version of SharePoint!&lt;/p&gt;  &lt;p&gt;There are a lot of blog posts out on the web which are about new features in SharePoint Server 2010, but only a small few contain some information about SharePoint Web Content Management (WCM). Now Andrew Connell wrote three very interesting blog posts only about this subject. :-)&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Part 1 – Improvements to the Core SharePoint platform&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Cleaner Markup &lt;/li&gt;    &lt;li&gt;Server Ribbon &lt;/li&gt;    &lt;li&gt;Reduced Postbacks during the authoring process &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;Part 2 - Improvements to WCM&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Improved Content Query WebPart &lt;/li&gt;    &lt;li&gt;Authoring &lt;/li&gt;    &lt;li&gt;Content Deployment &lt;/li&gt;    &lt;li&gt;Large Page Libraries &lt;/li&gt;    &lt;li&gt;Publishing Improvements &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;Part 3 – What’s new in WCM&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Content Organiser &lt;/li&gt;    &lt;li&gt;Page Ratings &lt;/li&gt;    &lt;li&gt;Metadata Everywhere &lt;/li&gt;    &lt;li&gt;Web Analytics &lt;/li&gt;    &lt;li&gt;More Video and Rich Media Support &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;For more information read the posts of Andrew Connell&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.andrewconnell.com/blog/archive/2009/10/19/part-1-improvements-to-the-core-sharepoint-platform.aspx"&gt;Part 1 - Improvements to the Core SharePoint Platform &amp;amp; How the Benefit SharePoint 2010 Web Content Management&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.andrewconnell.com/blog/archive/2009/10/19/part-2-whats-improved-with-sharepoint-server-2010-web.aspx"&gt;Part 2 – What’s Improved with SharePoint Server 2010 Web Content Management&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.andrewconnell.com/blog/archive/2009/10/19/part-3-whats-new-with-sharepoint-server-2010-web.aspx"&gt;Part 3 – What’s New with SharePoint Server 2010 Web Content Management&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1547054644249623125-4620467805882364627?l=ddehaas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ddehaas.blogspot.com/feeds/4620467805882364627/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ddehaas.blogspot.com/2009/10/whats-new-with-sharepoint-server-2010.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/4620467805882364627'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/4620467805882364627'/><link rel='alternate' type='text/html' href='http://ddehaas.blogspot.com/2009/10/whats-new-with-sharepoint-server-2010.html' title='What’s new with SharePoint Server 2010 Web Content Management'/><author><name>Danny de Haas</name><uri>http://www.blogger.com/profile/03475646948477442965</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1547054644249623125.post-9094940929771796983</id><published>2009-08-29T19:29:00.010+02:00</published><updated>2010-03-30T22:57:22.519+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Programmatically Adding a Control Adapter</title><content type='html'>&lt;p&gt;I have a Control Adapter I use frequently and every time I start a new SharePoint WCM project, I have to rethink about how to use&amp;#160; it to my Web Application and how to deploy the compat.browser modifications. After some research on the net I came up with two solutions to add Control Adapters programmatically, so no browser.compat modifications are necessary any more. &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Add a Control Adapter to the current HttpContext. &lt;/li&gt;    &lt;li&gt;Add a Control Adapter to a particular Control. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;I created some helper functions that can do the binding of the Control Adapter to a Control or Control-Type. In both cases the functions are used from within a custom (master)page class.&lt;/p&gt;  &lt;p&gt;The first solution is using strate forward .NET code, but for the second I had to use some Reflection. (so beware!)&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;1. Adding a Control Adapter to the current HttpContext&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;You can use the Global.asax file or a masterpage to add Control Adapters to the current HttpContext.&lt;/p&gt;&lt;p&gt;In the global.asax implement the code in the Application_Start event to bind the Control Adapter.&lt;/p&gt;
&lt;pre class="brush: c-sharp;"&gt;&amp;lt;script runat="server"&amp;gt;
    void Application_Start(Object sender, EventArgs e)
    {
        AddControlAdapterToType&amp;lt;Unive.Foundation.UI.ControlAdapters.SharePointWebPartZoneControlAdapter&amp;gt;(typeof(Microsoft.SharePoint.WebPartPages.WebPartZone));
    }

    private static void AddControlAdapterToType&amp;lt;T&amp;gt;(Type controlType) where T : ControlAdapter, new()
    {
        if (controlType == null)
        {
            throw new ArgumentNullException(&amp;quot;controlType&amp;quot;, &amp;quot;This argument can not be null!&amp;quot;);
        }

        IDictionary adapters = HttpContext.Current.Request.Browser.Adapters;
        string key = controlType.AssemblyQualifiedName;
        if (!adapters.Contains(key))
        {
            string adapter = typeof(T).AssemblyQualifiedName;
            adapters.Add(key, adapter);
        }
    }
&amp;lt;/script&amp;gt;&lt;/pre&gt;

&lt;p&gt;In a masterpage you must implement code in the constructor to bind the Control Adapter. This is necessary so the page will use the Control Adapter in the first run. Doing the binding in the OnInit or later is to late and all the child controls in the markup will already be instantiated.&lt;/p&gt;  &lt;pre class="brush: c-sharp;"&gt;using System;
using System.Web;
using System.Web.UI.Adapters;

public class MyMasterPage : System.Web.UI.MasterPage
{
    public MyMasterPage()
    {
        AddControlAdapterToType&amp;lt;SharePointWebPartZoneControlAdapter&amp;gt;(typeof(Microsoft.SharePoint.WebPartPages.WebPartZone));
    }

    private static void AddControlAdapterToType&amp;lt;T&amp;gt;(Type controlType) where T : ControlAdapter, new()
    {
        if (controlType == null)
        {
            throw new ArgumentNullException(&amp;quot;controlType&amp;quot;, &amp;quot;This argument can not be null!&amp;quot;);
        }

        IDictionary adapters = HttpContext.Current.Request.Browser.Adapters;
        string key = controlType.AssemblyQualifiedName;
        if (!adapters.Contains(key))
        {
            string adapter = typeof(T).AssemblyQualifiedName;
            adapters.Add(key, adapter);
        }
    }
}&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;2. Add a Control Adapter to a particular Control&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To bind a Control Adapter to a particular control, you must first find the control instance in the page and then you can do the binding.&lt;/p&gt;
&lt;pre class="brush: c-sharp;"&gt;using System;
using System.Reflection;
using System.Web.UI;
using System.Web.UI.Adapters;

public class MyMasterPage : System.Web.UI.MasterPage
{
    protected override void CreateChildControls()
    {
        base.CreateChildControls();

        Control control = Page.FindControl(&amp;quot;WebPartZone3&amp;quot;);
        AddControlAdapterToControl&amp;lt;SharePointWebPartZoneControlAdapter&amp;gt;(control);
    }

    private static void AddControlAdapterToControl&amp;lt;T&amp;gt;(Control control) where T : ControlAdapter, new()
    {
        if (control == null)
        {
            throw new ArgumentNullException(&amp;quot;control&amp;quot;, &amp;quot;This argument can not be null!&amp;quot;);
        }

        T adapter = new T();

        // Using reflection to bind controladapter to control
        control.GetType().GetField(&amp;quot;_adapter&amp;quot;, BindingFlags.Instance | BindingFlags.NonPublic).SetValue(control, adapter);
        // Using reflection to bind control to controladapter
        adapter.GetType().GetField(&amp;quot;_control&amp;quot;, BindingFlags.NonPublic | BindingFlags.Instance).SetValue(adapter, control);
    }
}&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1547054644249623125-9094940929771796983?l=ddehaas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ddehaas.blogspot.com/feeds/9094940929771796983/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ddehaas.blogspot.com/2009/08/programmatically-adding-control-adapter.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/9094940929771796983'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/9094940929771796983'/><link rel='alternate' type='text/html' href='http://ddehaas.blogspot.com/2009/08/programmatically-adding-control-adapter.html' title='Programmatically Adding a Control Adapter'/><author><name>Danny de Haas</name><uri>http://www.blogger.com/profile/03475646948477442965</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1547054644249623125.post-5207229085721138427</id><published>2009-06-24T16:32:00.006+02:00</published><updated>2009-07-01T23:23:10.287+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio'/><title type='text'>Bye Bye GuidGen.exe!</title><content type='html'>&lt;table border="0" cellspacing="0" cellpadding="2" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top"&gt;&lt;table border="0" cellspacing="0" cellpadding="2" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top"&gt;While developing in Visual Studio and I needed to create a new guid, I always used the “Create GUID” under the Tools dropdown menu. This menuitem started the “guidgen.exe” application and using this was a fine method, until I attended the last DevDays 2009 (The Hague, Netherlands). There I saw a demonstration of a much easier way to create a new guid in Visual Studio by making use of a simple macro. (Thanks Wouter)&lt;br /&gt;&lt;br /&gt;Below is the explanation on how to implement this macro. &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top"&gt;1. Open the Macro Explorer and Load or Create a Macro Project. &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_QtiDs9W18t0/SkI5CMIoRAI/AAAAAAAAAKQ/NIR4YdypePg/s1600-h/NewMacroProject%5B2%5D.jpg"&gt;&lt;img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="NewMacroProject" border="0" alt="NewMacroProject" src="http://lh4.ggpht.com/_QtiDs9W18t0/SkI5CdjAT8I/AAAAAAAAAKU/wRzvT6a-fD4/NewMacroProject_thumb.jpg?imgmax=800" width="244" height="111" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr colspan="2"&gt;&lt;td valign="top"&gt;2. Inside the macro IDE, create a method to generate a new guid.
&lt;pre class="brush: vbnet;"&gt;Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module Module1
    Sub GenerateGuid()
        If (DTE.ActiveDocument IsNot Nothing) Then
            DTE.ActiveDocument.Selection.Text = Guid.NewGuid().ToString("B")
        End If
    End Sub
End Module&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td valign="top"&gt;3. Save and close the macro IDE. &lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td valign="top"&gt;4. For the finishing though, create a keyboard shortcut to activate the GeneratGuid macro. I like to use the combination CTRL+K, CTRL+G



&lt;p&gt;&lt;a href="http://lh4.ggpht.com/_QtiDs9W18t0/SkI5D1Uap4I/AAAAAAAAAKY/BtZPb8BZmUs/s1600-h/ShortcutGenerateGuid%5B3%5D.jpg"&gt;&lt;img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="ShortcutGenerateGuid" border="0" alt="ShortcutGenerateGuid" src="http://lh3.ggpht.com/_QtiDs9W18t0/SkI5EY7vebI/AAAAAAAAAKc/nIm-m9rSsTg/ShortcutGenerateGuid_thumb%5B1%5D.jpg?imgmax=800" width="558" height="335" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td valign="top"&gt;5. Now it is so easy to create a new guid…..just by pressing your favourite keyboard shortcut.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/td&gt;

&lt;td valign="top"&gt;
&lt;p&gt;&lt;a href="http://lh4.ggpht.com/_QtiDs9W18t0/SkI5EntvgiI/AAAAAAAAAKg/Nm2XsbSkOXs/s1600-h/CreateGuid%5B7%5D.jpg"&gt;&lt;img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="CreateGuid" border="0" alt="CreateGuid" src="http://lh3.ggpht.com/_QtiDs9W18t0/SkI5E21BSVI/AAAAAAAAAKk/K0KHloyNhxw/CreateGuid_thumb%5B3%5D.jpg?imgmax=800" width="238" height="244" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh5.ggpht.com/_QtiDs9W18t0/SkI5FeFFKUI/AAAAAAAAAKo/kRwyBGEXb0I/s1600-h/CreateGuid2%5B8%5D.jpg"&gt;&lt;img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="CreateGuid2" border="0" alt="CreateGuid2" src="http://lh3.ggpht.com/_QtiDs9W18t0/SkI5FlE60pI/AAAAAAAAAKs/QvXdAyE54ms/CreateGuid2_thumb%5B2%5D.jpg?imgmax=800" width="244" height="221" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Bye Bye GuidGen!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1547054644249623125-5207229085721138427?l=ddehaas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ddehaas.blogspot.com/feeds/5207229085721138427/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ddehaas.blogspot.com/2009/06/bye-bye-guidgenexe.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/5207229085721138427'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/5207229085721138427'/><link rel='alternate' type='text/html' href='http://ddehaas.blogspot.com/2009/06/bye-bye-guidgenexe.html' title='Bye Bye GuidGen.exe!'/><author><name>Danny de Haas</name><uri>http://www.blogger.com/profile/03475646948477442965</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_QtiDs9W18t0/SkI5CdjAT8I/AAAAAAAAAKU/wRzvT6a-fD4/s72-c/NewMacroProject_thumb.jpg?imgmax=800' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1547054644249623125.post-7838514955497561083</id><published>2009-05-27T21:37:00.003+02:00</published><updated>2009-06-03T17:54:26.987+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><title type='text'>DevDays 2009 (PreConference DeepDive)</title><content type='html'>Today I visited the first day of the &lt;a href="http://www.devdays.nl/PreCon/default.aspx"&gt;DevDays 2009 (PreConference DeepDive)&lt;/a&gt; in The Hague (Netherlands) and attended a session about SharePoint developing by &lt;a href="http://www.code-counsel.net/About/Pages/default.aspx"&gt;Wouter van Vugt&lt;/a&gt;.
&lt;br/&gt;&lt;br/&gt;
After the introduction and agenda, Wouter started with presenting some develop tools you can you use while developing and talked about the pro's and con's of every one of them.
&lt;br/&gt;&lt;br/&gt;
Next was creating custom list templates and how to build your own entity picker controls using classes that are already provided inside the SharePoint object model.
&lt;br/&gt;&lt;br/&gt;
After the lunchbreak he continued with a demo of how he created a complex fieldtype using a entity picker and a resultdialog. How he stored the selected value, which contained some technical data and how to split it in a displaytext and id before displaying in a list. Wouter demonstrated how he used the RenderPattern of the fieldtype to only display the displaytext and hide to technical stuf.
&lt;br/&gt;&lt;br/&gt;
Last part of the session was about how he created his own SharePoint WCM Publishing site that is W3C Complaint. I found this a great demo and he gave me a lot of new idea's to work on.
&lt;br/&gt;&lt;br/&gt;
Overall I had a very interesting day full of How To's, demo's and lots of code examples.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1547054644249623125-7838514955497561083?l=ddehaas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ddehaas.blogspot.com/feeds/7838514955497561083/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ddehaas.blogspot.com/2009/05/devdays-2009-preconference-deepdive.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/7838514955497561083'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/7838514955497561083'/><link rel='alternate' type='text/html' href='http://ddehaas.blogspot.com/2009/05/devdays-2009-preconference-deepdive.html' title='DevDays 2009 (PreConference DeepDive)'/><author><name>Danny de Haas</name><uri>http://www.blogger.com/profile/03475646948477442965</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1547054644249623125.post-4267440213425172424</id><published>2009-05-15T10:35:00.004+02:00</published><updated>2009-05-15T10:51:44.981+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><title type='text'>The SharePoint Developer Introduction for .NET Developers</title><content type='html'>&lt;p&gt;Today I found that Microsoft release a SharePoint Introduction website for .NET develpers.The site is created with SilverLight and contains lots of information on what developer can use when they start with SharePoint.&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;Background info&lt;/li&gt;&lt;li&gt;Webcasts&lt;/li&gt;&lt;li&gt;Screencasts&lt;/li&gt;&lt;li&gt;Demo's&lt;/li&gt;&lt;li&gt;How to's&lt;/li&gt;&lt;li&gt;Virtual PC's image&lt;/li&gt;&lt;li&gt;Hands on Labs&lt;/li&gt;&lt;li&gt;Links to resources and forums&lt;/li&gt;&lt;li&gt;...and add some&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Check it out on:
&lt;a href="http://www.microsoft.com/click/SharePointDeveloper/"&gt;Do Less. Get More. Develop on SharePoint.&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1547054644249623125-4267440213425172424?l=ddehaas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ddehaas.blogspot.com/feeds/4267440213425172424/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ddehaas.blogspot.com/2009/05/sharepoint-developer-introduction-for.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/4267440213425172424'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/4267440213425172424'/><link rel='alternate' type='text/html' href='http://ddehaas.blogspot.com/2009/05/sharepoint-developer-introduction-for.html' title='The SharePoint Developer Introduction for .NET Developers'/><author><name>Danny de Haas</name><uri>http://www.blogger.com/profile/03475646948477442965</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1547054644249623125.post-1346579516779233450</id><published>2009-05-11T17:05:00.011+02:00</published><updated>2010-03-30T22:57:00.709+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Publishing'/><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='WCM'/><title type='text'>How to detect when a SharePoint Publishing Page is detached from it's PageLayout</title><content type='html'>Recently I found a new thing about SharePoint Publishing pages. From within SharePoint Designer, publishing pages can be detached from there pagelayout!&lt;br&gt;&lt;br&gt;
I guess that for some of you this not a a new thing, but I didn't know.&lt;br&gt;&lt;br&gt;In a normal publishing senario this is also not a common thing to do, because the page is disconnected from the pagelayout and changes to the pagelayout will no longer affect the page. But in certain situations it can be usefull, like using SharePoint Designer to place webparts on a publishing page. Normaly this can only be done from the browser interface. Of course a page can also be attached to a pagelayout again.&lt;br&gt;&lt;br&gt;To detach a page in SharePoint designer, open the Pages list and right click on the page.&lt;br&gt;
&lt;a href="http://4.bp.blogspot.com/_QtiDs9W18t0/SggzxDDhyXI/AAAAAAAAAJU/SQUxcCNTE3c/s1600-h/spd_detach.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5334570676347062642" style="WIDTH: 325px; CURSOR: hand; HEIGHT: 180px" alt="" src="http://4.bp.blogspot.com/_QtiDs9W18t0/SggzxDDhyXI/AAAAAAAAAJU/SQUxcCNTE3c/s400/spd_detach.jpg" border="0" /&gt;&lt;/a&gt;
&lt;br&gt;&lt;br&gt;Now you get a dialog 'Detaching from the page layouts http:/xxxx/_catalogs/masterpage/xxxx.aspx will copy its markup into this page, where it can be customized. Changes to the pagelayout will no long affect this page.'&lt;br&gt;&lt;br&gt;To reattach a page to it's pagelayout, right click on the page again.&lt;br&gt;
&lt;a href="http://4.bp.blogspot.com/_QtiDs9W18t0/Sgg1dXA0XHI/AAAAAAAAAJc/j9aRN9ZMJjk/s1600-h/spd_attach.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5334572537130278002" style="WIDTH: 300px; CURSOR: hand; HEIGHT: 244px" alt="" src="http://4.bp.blogspot.com/_QtiDs9W18t0/Sgg1dXA0XHI/AAAAAAAAAJc/j9aRN9ZMJjk/s400/spd_attach.jpg" border="0" /&gt;&lt;/a&gt;
&lt;br&gt;&lt;br&gt;After knowing how to detach a page from it's pagelayout, I wanted to find out how a publishing page would know it was detached and after some investigation I found that this information is stored in the listitem for the page. Each publishing page has a field called 'PublishingPageLayout' and this field normaly contains the url of the pagelayout and the name of the content type.&lt;br&gt;
Value format: 'http://xxxx/catalogs/masterpage/xxxx.aspx, ContentTypeName'&lt;br&gt;&lt;br&gt;But after detaching the pagelayout this field contains another kind of information. Namely an indication that the page is a disconnected publishing page and a reference to the pagelayout is once was connected to.&lt;br&gt;Value format: 'http://www.microsoft.com/publishing?DisconnectedPublishingPage=true, http://xxxx/_catalogs/masterpage/xxxx.aspx&lt;br&gt;&lt;br&gt;To detect all disconnected publishing pages in a site collection I created a the following code:&lt;br&gt;
&lt;pre class="brush: c-sharp;"&gt;
using (SPSite site = new SPSite("http://demosite"))
{
    SPWeb rootWeb = site.RootWeb;

    // Query to get all publishing pages in the sitecollection that are detached from pagelayout.
    // ServerTemplate=850, is template for the Pages lists.
    SPSiteDataQuery dataQuery = new SPSiteDataQuery();
    dataQuery.Webs = "&lt; Webs Scope="SiteCollection"&gt;";
    dataQuery.Lists = "&lt; Lists ServerTemplate="850"&gt;";
    dataQuery.ViewFields = "&lt; FieldRef Name="FileRef" Nullable="TRUE"&gt;";
    dataQuery.Query = "&lt; Where&gt;" +
                            "&lt; Contains&gt;" +
                                "&lt; FieldRef Name="PublishingPageLayout"&gt;" +
                                "&lt; Value Type="Text"&gt;?DisconnectedPublishingPage=true&lt; /Value&gt;" +
                            "&lt; /Contains&gt;" +
                        "&lt; /Where&gt;";                              

    // Store result in datatable
    DataTable dt = rootWeb.GetSiteData(dataQuery);
    foreach (DataRow row in dt.Rows)
    {
        if (row.IsNull("FileRef"))
        {
            Console.WriteLine("FileRef should not be null!");
            continue;
        }

        // Strip listitem id from fieldref value
        string fieldRef = row["FileRef"].ToString().Trim();
        if (!string.IsNullOrEmpty(fieldRef))
        {
            int pos = fieldRef.IndexOf(";#");
            if (pos &gt; -1)
            {
                fieldRef = fieldRef.Substring(pos + 2);
            }
        }

        Console.WriteLine(fieldRef);
    }
}          
&lt;/pre&gt;

Also you can use the 'Content and Structure Reports' functionality from MOSS to get an overview of all publishing pages that are disconnected from the pagelayout.&lt;br&gt;&lt;br&gt;To do this, go to the 'Content and Structure Reports' list inside to root site. Create a new item and fill the field like below.
&lt;ul&gt;&lt;li&gt;Report Title: All Pages Disconnected from PageLayout&lt;/li&gt;&lt;li&gt;Resource Id: (leave blank)&lt;/li&gt;&lt;li&gt;Resource Id: (leave blank)&lt;/li&gt;&lt;li&gt;CAML List Type: &amp;lt;Lists ServerTemplate='850' /&amp;gt;&lt;/li&gt;&lt;li&gt;CAML Query: &amp;lt;Where&amp;gt;&amp;lt;Contains&amp;gt;&amp;lt;FieldRef Name='PublishingPageLayout' /&amp;gt;&amp;lt;Value Type='Text'&amp;gt;?DisconnectedPublishingPage=true&amp;lt;/Value&amp;gt;&amp;lt;/Contains&amp;gt;&amp;lt;/Where&amp;gt;&lt;/li&gt; 
&lt;li&gt;Target Audiences: (leave blank)&lt;/li&gt;&lt;li&gt;Report Description: All publishing pages that are detached from their pagelayout by using SharePoint Designer.&lt;/li&gt;&lt;/ul&gt;
&lt;br&gt;
&lt;a href="http://1.bp.blogspot.com/_QtiDs9W18t0/Sgq8IDR0AgI/AAAAAAAAAJ8/bQjK_Zt3Gr4/s1600-h/report_detachedpages.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 258px;" src="http://1.bp.blogspot.com/_QtiDs9W18t0/Sgq8IDR0AgI/AAAAAAAAAJ8/bQjK_Zt3Gr4/s400/report_detachedpages.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5335283555078767106" /&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
Afer creating a new report, you can access it through the Site Actions button.&lt;br&gt;
&lt;a href="http://3.bp.blogspot.com/_QtiDs9W18t0/Sgq8imSg0qI/AAAAAAAAAKE/mg9Oxrl0qT4/s1600-h/report_detachedpages2.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 309px; height: 400px;" src="http://3.bp.blogspot.com/_QtiDs9W18t0/Sgq8imSg0qI/AAAAAAAAAKE/mg9Oxrl0qT4/s400/report_detachedpages2.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5335284011153543842" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1547054644249623125-1346579516779233450?l=ddehaas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ddehaas.blogspot.com/feeds/1346579516779233450/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ddehaas.blogspot.com/2009/05/how-to-detect-when-sharepoint.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/1346579516779233450'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/1346579516779233450'/><link rel='alternate' type='text/html' href='http://ddehaas.blogspot.com/2009/05/how-to-detect-when-sharepoint.html' title='How to detect when a SharePoint Publishing Page is detached from it&apos;s PageLayout'/><author><name>Danny de Haas</name><uri>http://www.blogger.com/profile/03475646948477442965</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_QtiDs9W18t0/SggzxDDhyXI/AAAAAAAAAJU/SQUxcCNTE3c/s72-c/spd_detach.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1547054644249623125.post-424267766409784846</id><published>2009-04-26T13:41:00.012+02:00</published><updated>2010-03-30T22:56:32.556+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><category scheme='http://www.blogger.com/atom/ns#' term='WSS'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='LINQ'/><title type='text'>SPSiteColumnUsage, Find all references to a site column</title><content type='html'>When I try to delete a site column from a SharePoint site I often get the message "Site columns which are included in content types cannot be deleted. Remove all references to this site column prior to deleting it."&lt;br/&gt;&lt;br/&gt;Well with only a few content types this isn't so hard to click through all content types and checking if the site column is used, but with a lot of them it's no fun and can be a hell of a job.&lt;br/&gt;&lt;br/&gt;To make my life a bit easier I decided to create a piece of code that could delete site columns programmatically. I knew that SharePoint object model has a class that can return the usage of content types, namely SPContentTypeUsage. With this class you can tell if a content type is used in one or more lists somewhere inside the complete site collection and what the urls to those lists are.&lt;br/&gt;&lt;br/&gt;My guess was that there should also be something like a site column usage, but I was wrong!&lt;br/&gt;&lt;br/&gt;After some investigation on MSDN, several SharePoint blogs and good old Reflector, I created a SPSiteColumnUsage class. This class uses the LINQ and SPContentTypeUsage and can find all references to content types and lists where a site columns is in use.&lt;br/&gt;&lt;br/&gt;
SPSiteColumnUsage&lt;br/&gt;Methods&lt;ul&gt;&lt;li&gt;GetUsages, this method takes a SPField instance as input argument and returns an array of SPSiteColumnUsage objects.&lt;/li&gt;&lt;/ul&gt;
Properties&lt;ul&gt;&lt;li&gt;Id, the Id of the site column.&lt;/li&gt;&lt;li&gt;Scope, the scope of the site column.&lt;/li&gt;&lt;li&gt;ContentTypeId, the id of a content type where the site column is in use.&lt;/li&gt;&lt;li&gt;IsUrlToList, indicates if the information is about a list or a content type.&lt;/li&gt;&lt;li&gt;Url, the server relative to a list where the site column is in use.&lt;/li&gt;&lt;/ul&gt;&lt;br/&gt;&lt;br/&gt;Usage example to get info about the site column: Title&lt;br/&gt;
&lt;pre class="brush: c-sharp;"&gt;
using (SPSite site = new SPSite("http://demosite"))
{
    using (SPWeb web = site.OpenWeb())
    {
        SPField field = web.Fields.GetFieldByInternalName("Title);

        Console.WriteLine("Field: {0}", fieldName);
        Console.WriteLine("==============================");

        var usage = SPSiteColumnUsage.GetUsages(field);
        foreach (var u in usage)
        {
            Console.WriteLine("Id: {0}", u.Id);
            Console.WriteLine("Scope: {0}", u.Scope);
            Console.WriteLine("ContentTypeId: {0}", u.ContentTypeId);
            Console.WriteLine("IsUrlToList: {0}", u.IsUrlToList);
            Console.WriteLine("Url: {0}", u.Url);
            Console.WriteLine();
        }
    }
}
&lt;/pre&gt;
See a working example on &lt;a href="http://spsitecolumnusage.codeplex.com/"&gt;http://SPSiteColumnUsage.codeplex.com&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;
The class also makes use of the extension method CoppyToArray I created.&lt;br/&gt;For this method see a previous post: &lt;a href="http://ddehaas.blogspot.com/2009/03/using-linq-to-query-sharepoint.html"&gt;Using LINQ to query SharePoint collections&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;
&lt;pre class="brush: c-sharp;"&gt;
/// &lt;summary&gt;
/// Class with site column usage information.
/// &lt;/summary&gt;
public class SPSiteColumnUsage
{
   public static IList&lt; SPSiteColumnUsage&gt; GetUsages(SPField field)
   {
       List&lt; SPSiteColumnUsage&gt; list = new List&lt; SPSiteColumnUsage&gt;();

       if(field != null &amp;amp;&amp;amp; field.UsedInWebContentTypes)
       {
           // Use reflection to get the fields collection for the specified field
           SPFieldCollection fieldCollection = field.GetType().GetProperty("Fields", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(field, null) as SPFieldCollection;
           if(fieldCollection != null)
           {
               // Get the web context from the collection
               SPWeb web = fieldCollection.Web;

               // First collect all contenttypes to an array, so we can use Linq
               var contentTypes = web.ContentTypes.CopyToArray&lt; SPContentType&gt;();

               // Filter contenttypes where field is used
               var contentTypesWithField = (from contentType in contentTypes
                                            where contentType.Fields.ContainsField(field.InternalName)
                                            select contentType).ToArray();

               // Create usages for fields in contenttypes
               foreach(SPContentType contentType in contentTypesWithField)
               {
                   SPSiteColumnUsage siteColumnUsage = new SPSiteColumnUsage(field.Id, field.Scope, contentType.Id);
                   list.Add(siteColumnUsage);
               }

               // Get unique lists-urls where contentypes are beeing used
               var listUrlsContentTypeUsage = (from contentType in contentTypesWithField
                                               let contentTypeUsages = SPContentTypeUsage.GetUsages(contentType)
                                               from contentTypeUsage in contentTypeUsages
                                               where contentTypeUsage.IsUrlToList
                                               select contentTypeUsage.Url).Distinct().ToArray();

               // Create usages for fields in list
               foreach (string listUrl in listUrlsContentTypeUsage)
               {
                   SPSiteColumnUsage siteColumnUsage = new SPSiteColumnUsage(field.Id, field.Scope, listUrl);
                   list.Add(siteColumnUsage);
               }
           }
       }

       return list;
   }

   private readonly Guid _Id;
   private readonly string _Scope;
   private readonly SPContentTypeId _ContentTypeId;
   private readonly string _Url;

   private SPSiteColumnUsage(Guid id, string scope, SPContentTypeId contentTypeId)
   {
       _Id = id;
       _Scope = scope;
       _ContentTypeId = contentTypeId;
       _Url = null;
   }

   private SPSiteColumnUsage(Guid id, string scope, string url)
   {
       _Id = id;
       _Scope = scope;
       _ContentTypeId = SPContentTypeId.Empty;
       _Url = url;
   }

   public Guid Id
   {
       [DebuggerStepThrough]
       get { return _Id; }
   }

   public string Scope
   {
       [DebuggerStepThrough]
       get { return _Scope; }
   }

   public SPContentTypeId ContentTypeId
   {
       [DebuggerStepThrough]
       get { return _ContentTypeId; }
   }

   public string Url
   {
       [DebuggerStepThrough]
       get { return _Url; }
   }

   public bool IsUrlToList
   {
       [DebuggerStepThrough]
       get { return _ContentTypeId.Equals(SPContentTypeId.Empty) &amp;amp;&amp;amp; !string.IsNullOrEmpty(_Url); }
   }
}
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1547054644249623125-424267766409784846?l=ddehaas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ddehaas.blogspot.com/feeds/424267766409784846/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ddehaas.blogspot.com/2009/04/spsitecolumnusage-find-all-references.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/424267766409784846'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/424267766409784846'/><link rel='alternate' type='text/html' href='http://ddehaas.blogspot.com/2009/04/spsitecolumnusage-find-all-references.html' title='SPSiteColumnUsage, Find all references to a site column'/><author><name>Danny de Haas</name><uri>http://www.blogger.com/profile/03475646948477442965</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1547054644249623125.post-8836732750590912689</id><published>2009-04-02T11:23:00.005+02:00</published><updated>2009-04-02T11:54:43.068+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><title type='text'>Microsoft SharePoint Designer 2007 is now free</title><content type='html'>When I first heared the news that Microsoft was going to give away SharePoint Designer 2007 for free, I thought it was a April Fool's joke. But now on April 2nd, I actual believe. :-)
&lt;br&gt;&lt;br&gt;
Download it from Microsoft Download Center.
&lt;br&gt;
&lt;a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=baa3ad86-bfc1-4bd4-9812-d9e710d44f42" target="_blank"&gt;http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=baa3ad86-bfc1-4bd4-9812-d9e710d44f42&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1547054644249623125-8836732750590912689?l=ddehaas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ddehaas.blogspot.com/feeds/8836732750590912689/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ddehaas.blogspot.com/2009/04/microsoft-sharepoint-designer-2007-is.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/8836732750590912689'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/8836732750590912689'/><link rel='alternate' type='text/html' href='http://ddehaas.blogspot.com/2009/04/microsoft-sharepoint-designer-2007-is.html' title='Microsoft SharePoint Designer 2007 is now free'/><author><name>Danny de Haas</name><uri>http://www.blogger.com/profile/03475646948477442965</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1547054644249623125.post-3112792032257929958</id><published>2009-03-24T08:47:00.005+01:00</published><updated>2009-04-02T11:54:23.771+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Publishing'/><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><category scheme='http://www.blogger.com/atom/ns#' term='WCM'/><title type='text'>Understanding Field Controls and Web Parts in SharePoint Server 2007 Publishing Sites</title><content type='html'>I just read an great article from Andrew Connell about the use of Field Controls and Web Parts in MOSS 2007 Publishing sites.
&lt;br&gt;&lt;br&gt;
He describes clearly the advantages and disadvantages of using them and that you should considered in the early phase of the implementation of a new publishing site which approach to use.
&lt;br&gt;&lt;br&gt;
Read the article on MSDN
&lt;br&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/dd571480.aspx"&gt;Understanding Field Controls and Web Parts in SharePoint Server 2007 Publishing Sites&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1547054644249623125-3112792032257929958?l=ddehaas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ddehaas.blogspot.com/feeds/3112792032257929958/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ddehaas.blogspot.com/2009/03/understanding-field-controls-and-web.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/3112792032257929958'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/3112792032257929958'/><link rel='alternate' type='text/html' href='http://ddehaas.blogspot.com/2009/03/understanding-field-controls-and-web.html' title='Understanding Field Controls and Web Parts in SharePoint Server 2007 Publishing Sites'/><author><name>Danny de Haas</name><uri>http://www.blogger.com/profile/03475646948477442965</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1547054644249623125.post-2232697394267759200</id><published>2009-03-15T22:03:00.008+01:00</published><updated>2010-03-30T22:56:07.081+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Publishing'/><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><category scheme='http://www.blogger.com/atom/ns#' term='WSS'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='WCM'/><title type='text'>SharePoint PublishingWeb class inside out</title><content type='html'>For a project I've done in the past, I had to create an application that could report all sorts of SharePoint site information. While developing this application, the biggest challenge was to gather information about publishing sites, without the use off the Micosoft.SharePoint.Publishing assembly. The reason for this was that the application also had to run on a WSS only installation of SharePoint. During refactoring I found out that most information was stored in the propertybag of the web.
&lt;br&gt;&lt;br&gt;
I created a SharePoint Publishing helper class that can retrieve values for the following PublishingWeb properties and functions.
&lt;ul&gt;
&lt;li&gt;GetAvailablePageLayouts&lt;/li&gt;
&lt;li&gt;GetIncludeInNavigation&lt;/li&gt;
&lt;li&gt;IncludeInCurrentNavigation&lt;/li&gt;
&lt;li&gt;IncludeInGlobalNavigation&lt;/li&gt;
&lt;li&gt;IncludePagesInNavigation&lt;/li&gt;
&lt;li&gt;IncludeSubSitesInNavigation&lt;/li&gt;
&lt;li&gt;InheritAlternateCssUrl&lt;/li&gt;
&lt;li&gt;InheritCurrentNavigation&lt;/li&gt;
&lt;li&gt;InheritCustomMasterUrl&lt;/li&gt;
&lt;li&gt;InheritGlobalNavigation&lt;/li&gt;
&lt;li&gt;IsInheritingAvailablePageLayouts&lt;/li&gt;
&lt;li&gt;IsInheritingAvailableWebTemplates&lt;/li&gt;
&lt;li&gt;IsPublishingWeb&lt;/li&gt;
&lt;li&gt;NavigationAutomaticSortingMethod&lt;/li&gt;
&lt;li&gt;NavigationShowSiblings&lt;/li&gt;
&lt;li&gt;NavigationSortAscending&lt;/li&gt;
&lt;li&gt;OrderingMethod&lt;/li&gt;
&lt;li&gt;PagesListId&lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="brush: c-sharp;"&gt;
public static class SharePointPublishingHelper
{
 public static bool IsPublishingWeb(SPWeb web)
 {
  return GetBooleanValueFromPropertyBag(web, "__PublishingFeatureActivated", false);
 }

 public static bool IncludeInGlobalNavigation(SPWeb web)
 {
  return GetIncludeInNavigation(web, "__GlobalNavigationExcludes");
 }
 
 public static bool IncludeInCurrentNavigation(SPWeb web)
 {
  return GetIncludeInNavigation(web, "__CurrentNavigationExcludes");
 }
 
 private static bool GetIncludeInNavigation(SPWeb web, string propertyKey)
 {
  if(web == null)
  {
   throw new ArgumentNullException("web");
  }
  if (string.IsNullOrEmpty(propertyKey))
  {
   throw new ArgumentException("The argument can't be null or a empty string.", "propertyKey");
  }
 
  SPWeb parentWeb = web.ParentWeb;
  if (!web.IsRootWeb &amp;&amp; parentWeb != null)
  {
   string globalNavigationExcludes = GetValueFromPropertyBag(parentWeb, propertyKey) as string;
   if (!string.IsNullOrEmpty(globalNavigationExcludes))
   {
    string[] list = globalNavigationExcludes.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
    bool found = list.Contains(web.ID.ToString("D"));
 
    return !found;
   }
  }
 
  return true;
 }
 
 public static bool InheritGlobalNavigation(SPWeb web)
 {
  if (web == null)
  {
   throw new ArgumentNullException("web");
  }
 
  if (web.IsRootWeb)
  {
   return false;
  }
 
  return web.Navigation.UseShared;
 }
 
 public static bool InheritCurrentNavigation(SPWeb web)
 {
  if (web == null)
  {
   throw new ArgumentNullException("web");
  }
 
  if (web.IsRootWeb)
  {
   return false;
  }
 
  return GetBooleanValueFromPropertyBag(web, "__InheritCurrentNavigation", true);
 }
 
 public static bool IncludeSubSitesInNavigation(SPWeb web)
 {
  if (web == null)
  {
   throw new ArgumentNullException("web");
  }
 
  return GetBooleanValueFromPropertyBag(web, "__IncludeSubSitesInNavigation", true);
 }
 
 public static bool IncludePagesInNavigation(SPWeb web)
 {
  if (web == null)
  {
   throw new ArgumentNullException("web");
  }
 
  return GetBooleanValueFromPropertyBag(web, "__IncludePagesInNavigation", true);
 }
 
 public static string OrderingMethod(SPWeb web)
 {
  if (web == null)
  {
   throw new ArgumentNullException("web");
  }
 
  string value = GetValueFromPropertyBag(web, "__NavigationOrderingMethod").ToString();
  switch (value)
  {
   case "0":
    return "Automatic";
   case "1":
    return "ManualWithAutomaticPageSorting";
   case "2":
    return "Manual";
   default:
    break;
  }
 
  return "Manual";
 }
 
 public static bool NavigationShowSiblings(SPWeb web)
 {
  if (web == null)
  {
   throw new ArgumentNullException("web");
  }
 
  if (web.IsRootWeb)
  {
   return false;
  }
 
  return GetBooleanValueFromPropertyBag(web, "__NavigationShowSiblings", true);
 }
 
 public static string NavigationAutomaticSortingMethod(SPWeb web)
 {
  if (web == null)
  {
   throw new ArgumentNullException("web");
  }
 
  string value = GetValueFromPropertyBag(web, "__NavigationAutomaticSortingMethod").ToString();
  switch (value)
  {
   case "0":
    return "Title";
   case "1":
    return "CreatedDate";
   case "2":
    return "LastModifiedDate";
   default:
    break;
  }
 
  return "Title";
 }
 
 public static bool NavigationSortAscending(SPWeb web)
 {
  if (web == null)
  {
   throw new ArgumentNullException("web");
  }
 
  return GetBooleanValueFromPropertyBag(web, "__NavigationSortAscending", true);
 }
 
 public static Guid PagesListId(SPWeb web)
 {
  if (web == null)
  {
   throw new ArgumentNullException("web");
  }
 
  string value = GetValueFromPropertyBag(web, "__PagesListId").ToString();
  if (string.IsNullOrEmpty(value))
  {
   return Guid.Empty;
  }
 
  return new Guid(value);
 }
 
 public static bool InheritCustomMasterUrl(SPWeb web)
 {
  if (web == null)
  {
   throw new ArgumentNullException("web");
  }
 
  return GetBooleanValueFromPropertyBag(web, "__InheritsCustomMasterUrl", false);
 }
 
 public static bool InheritAlternateCssUrl(SPWeb web)
 {
  if (web == null)
  {
   throw new ArgumentNullException("web");
  }
 
  return GetBooleanValueFromPropertyBag(web, "__InheritsAlternateCssUrl", false);
 }
 
 public static bool IsInheritingAvailableWebTemplates(SPWeb web)
 {
  if (web == null)
  {
   throw new ArgumentNullException("web");
  }
 
  return GetBooleanValueFromPropertyBag(web, "__InheritWebTemplates", false);
 }
 
 public static bool IsInheritingAvailablePageLayouts(SPWeb web)
 {
  if (web == null)
  {
   throw new ArgumentNullException("web");
  }
 
  string value = GetValueFromPropertyBag(web, "__PageLayouts").ToString();
  if (!string.IsNullOrEmpty(value))
  {
   return value.Equals("__inherit", StringComparison.InvariantCultureIgnoreCase);
  }
 
  return false;
 }
 
 public static string[] GetAvailablePageLayouts(SPWeb web)
 {
  if (web == null)
  {
   throw new ArgumentNullException("web");
  }
 
  List&lt;string&gt; list = new List&lt;string&gt;();
 
  string value = GetValueFromPropertyBag(web, "__PageLayouts").ToString();
  if (!string.IsNullOrEmpty(value))
  {
   SPWeb rootWeb = web.Site.RootWeb;
 
   var pageLayouts = XElement.Parse(value).Elements("layout");
   foreach (var pageLayout in pageLayouts)
   {
    string itemUrl = null;
 
    string id = null;
    XAttribute guidAttribute = pageLayout.Attribute("guid");
    if (guidAttribute != null)
    {
     id = guidAttribute.Value;
    }
 
    // first try to find pagelayout by id
    if (!string.IsNullOrEmpty(id))
    {
     SPFile file = rootWeb.GetFile(new Guid(id));
     if (file != null &amp;&amp; file.Exists)
     {
      itemUrl = file.ServerRelativeUrl;
     }
    }
 
    // if no pagelayout is found by id, try the url
    if (string.IsNullOrEmpty(itemUrl))
    {
     string url = null;
     XAttribute urlAttribute = pageLayout.Attribute("url");
     if (urlAttribute != null)
     {
      url = urlAttribute.Value;
     }
 
     SPFile file = rootWeb.GetFile(url);
     if (file != null &amp;&amp; file.Exists)
     {
      itemUrl = file.ServerRelativeUrl;
     }
    }
 
    if (!string.IsNullOrEmpty(itemUrl))
    {
     list.Add(itemUrl);
    }
   }
  }
 
  return list.ToArray();
 }
 
 private static object GetValueFromPropertyBag(SPWeb web, string key)
 {
  if (web == null)
  {
   throw new ArgumentNullException("web");
  }
  if (string.IsNullOrEmpty(key))
  {
   throw new ArgumentException("The argument can't be null or a empty string.", "key");
  }
 
  object value = null;
 
  // First check the AllProperties collection
  if (web.AllProperties.ContainsKey(key))
  {
   value = web.AllProperties[key];
  }
 
  // Still empty, check also the Properties collection
  if (value == null)
  {
   if (web.Properties.ContainsKey(key))
   {
    value = web.Properties[key];
   }
  }
 
  return value;
 }
 
 private static bool GetBooleanValueFromPropertyBag(SPWeb web, string key, bool defaultValue)
 {
  string value = GetValueFromPropertyBag(web, key) as string;
 
  bool ret;
  if (!bool.TryParse(value, out ret))
  {
   ret = defaultValue;
  }
 
  return ret;
 }
}
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1547054644249623125-2232697394267759200?l=ddehaas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ddehaas.blogspot.com/feeds/2232697394267759200/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ddehaas.blogspot.com/2009/03/sharepoint-publishingweb-class-inside.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/2232697394267759200'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/2232697394267759200'/><link rel='alternate' type='text/html' href='http://ddehaas.blogspot.com/2009/03/sharepoint-publishingweb-class-inside.html' title='SharePoint PublishingWeb class inside out'/><author><name>Danny de Haas</name><uri>http://www.blogger.com/profile/03475646948477442965</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1547054644249623125.post-8473021709042601925</id><published>2009-03-08T22:41:00.025+01:00</published><updated>2010-03-30T22:55:42.639+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><category scheme='http://www.blogger.com/atom/ns#' term='WSS'/><category scheme='http://www.blogger.com/atom/ns#' term='Generics'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='LINQ'/><title type='text'>Using LINQ to query SharePoint collections</title><content type='html'>I came across a challenge when I wanted to using LINQ on several SharePoint collection classes and I noticed that it wasn't possible to do this....So why not?
LINQ lets you query any collection implementing the IEnumerable&lt;t&gt; interface and after some research I found that most of the SharePoint collections don't implement this interface.
&lt;br/&gt;&lt;br/&gt;
Ok, how to overcome this challenge?
Arrays implement IEnumerable&lt;t&gt;....Copy the items from the collection to an array!
SharePoint collections implement the ICollection interface which provides the method: void CopyTo(Array array, int index), so this should not be a problem.
Well it does!
&lt;br/&gt;&lt;br/&gt;
SharePoint collections derive from a class called SPBaseCollection and this class implements ICollection. But because the explicit implementation of CopyTo, this method is private.
&lt;br/&gt;&lt;br/&gt;
For this I wrote a little helper extension method that makes it possible to copy a SharePoint collections (or any class that implements ICollection) to an array of a particular type and validate for null at the same time.
&lt;pre class="brush: c-sharp;"&gt;
public static class Helpers
{
 public static T[] CopyToArray&lt;t&gt;(this ICollection collection)
 {
     if (collection == null) { return new T[0]; }

     T[] array = new T[collection.Count];
     collection.CopyTo(array, 0);

     return array;
 }
}
&lt;/pre&gt;

Now it is possible to make Linq queries like this:

&lt;pre class="brush: c-sharp;"&gt;
using (SPSite site = new SPSite("http://demosite"))
{
 using (SPWeb web = site.OpenWeb())
 {
     // Get all webs ordered by Title
     var items1 = web.Webs.CopyToArray&lt; SPWeb&gt;().OrderBy(p =&gt; p.Title);
     foreach (var item in items1)
     {
         Console.WriteLine(item.Title);
     }

     // Get all content types grouped by group and ordered by group and name
     var items2 = web.ContentTypes.CopyToArray&lt; SPContentType&gt;().GroupBy(p =&gt; p.Group).OrderBy(g =&gt; g.Key);
     foreach (IGrouping&lt;&gt; group in items2)
     {
         Console.WriteLine(group.Key);

         foreach (var item in group.OrderBy(p =&gt; p.Name))
         {
             Console.WriteLine(item.Name);
         }
     }

     // Get a list by name and not by title
     var list = web.Lists.CopyToArray&lt; SPList&gt;().SingleOrDefault(p =&gt; p.RootFolder.Name.Equals("pages", StringComparison.InvariantCultureIgnoreCase));
     if (list != null)
     {
         Console.WriteLine("List: {0} found!", list.Title);
     }
 }
}
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1547054644249623125-8473021709042601925?l=ddehaas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ddehaas.blogspot.com/feeds/8473021709042601925/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ddehaas.blogspot.com/2009/03/using-linq-to-query-sharepoint.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/8473021709042601925'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/8473021709042601925'/><link rel='alternate' type='text/html' href='http://ddehaas.blogspot.com/2009/03/using-linq-to-query-sharepoint.html' title='Using LINQ to query SharePoint collections'/><author><name>Danny de Haas</name><uri>http://www.blogger.com/profile/03475646948477442965</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1547054644249623125.post-3064397709367594014</id><published>2009-02-23T13:20:00.006+01:00</published><updated>2010-03-30T22:55:17.546+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><category scheme='http://www.blogger.com/atom/ns#' term='WSS'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Create a Fake HttpContext for SharePoint</title><content type='html'>While coding for SharePoint I usualy start by putting code in a console application to create the nessasary functionaly and on a later stage move it over to a browser application. I do this because I find it speeding up the development cycle, because SharePoint deployment cause a bit of overhead. But once in a while I need the HttpContext.Current to be set and I there isn't one in a console app.
&lt;br/&gt;&lt;br/&gt;
To overcome this problem I created my own WorkerRequest class and a helper method that returns a HttpContext to fake a current http context. Both the class and method take a SPWeb as contructor parameter to put the correct SharePoint context into the http context.

&lt;pre class="brush: c-sharp;"&gt;
public class FakeSharePointWorkerRequest : SimpleWorkerRequest
{
    private readonly string _ServerName;

    public FakeSharePointWorkerRequest(SPWeb web) : base(web.ServerRelativeUrl, web.Site.WebApplication.IisSettings[SPUrlZone.Default].Path.FullName, string.Empty, string.Empty, null)
    {
        _ServerName = web.Site.HostName;
    }

    public override string GetServerName()
    {
        return _ServerName;
    }
}

public static HttpContext GetFakeHttpContextForSharePoint(SPWeb web)
{
    FakeSharePointWorkerRequest workerRequest = new FakeSharePointWorkerRequest(web);
    HttpContext httpContext = new HttpContext(workerRequest);
    httpContext.Items["HttpHandlerSPWeb"] = web;
    httpContext.Items["HttpHandlerSPSite"] = web.Site;
 
    return httpContext;
}
&lt;/pre&gt;

&lt;em&gt;&lt;strong&gt;Usage example&lt;/strong&gt;&lt;/em&gt;

&lt;pre class="brush: c-sharp;"&gt;
using(SPSite site = new SPSite("http://demosite"))
{
    using(SPWeb web = site.OpenWeb())
    {
        bool httpContextIsFake = false;
        if (HttpContext.Current == null)
        {
            // Must be set before using the SPLimitedWebPartManager in a console app
            HttpContext.Current = GetFakeHttpContextForSharePoint(web);
            httpContextIsFake = true;
        }
 
        // Do your own thingies!
        // .....
 
        // Don't forget to reset the current http context
        if (httpContextIsFake)
        {
            HttpContext.Current = null;
        }                     
    }
}
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1547054644249623125-3064397709367594014?l=ddehaas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ddehaas.blogspot.com/feeds/3064397709367594014/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ddehaas.blogspot.com/2009/02/create-fake-httpcontext-for-sharepoint.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/3064397709367594014'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/3064397709367594014'/><link rel='alternate' type='text/html' href='http://ddehaas.blogspot.com/2009/02/create-fake-httpcontext-for-sharepoint.html' title='Create a Fake HttpContext for SharePoint'/><author><name>Danny de Haas</name><uri>http://www.blogger.com/profile/03475646948477442965</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1547054644249623125.post-3533471593976449273</id><published>2009-02-17T10:44:00.007+01:00</published><updated>2010-03-30T22:54:59.685+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><category scheme='http://www.blogger.com/atom/ns#' term='WSS'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Programmatically show all list templates for a SharePoint web</title><content type='html'>To programmatically create lists in a SharePoint web, I found you have to look for list templates in two different locations.
&lt;br/&gt;&lt;br/&gt;
The first (obvious) location is in the ListTemplates collection on the SPWeb object, but then u would mis the custom list templates stored in the List Template Gallery.
&lt;br/&gt;&lt;br/&gt;
The code belows shows all list templates for a web.
&lt;br/&gt;&lt;br/&gt;
&lt;pre class="brush: c-sharp;"&gt;
using(SPSite site = new SPSite("http://demosite"))
{
    using(SPWeb web = site.OpenWeb())
    {
        Console.WriteLine("==== List Templates");
        foreach(SPListTemplate template in web.ListTemplates)
        {
            Console.WriteLine(template.Name);
        }
  
        Console.WriteLine("==== List Templates from the List Template Gallery");
        foreach (SPListTemplate template in site.GetCustomListTemplates(web))
        {
            Console.WriteLine(template.Name);
        }
    }
}
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1547054644249623125-3533471593976449273?l=ddehaas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ddehaas.blogspot.com/feeds/3533471593976449273/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ddehaas.blogspot.com/2009/02/programmatically-show-all-list.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/3533471593976449273'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/3533471593976449273'/><link rel='alternate' type='text/html' href='http://ddehaas.blogspot.com/2009/02/programmatically-show-all-list.html' title='Programmatically show all list templates for a SharePoint web'/><author><name>Danny de Haas</name><uri>http://www.blogger.com/profile/03475646948477442965</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1547054644249623125.post-5238218082342209979</id><published>2009-02-12T23:23:00.005+01:00</published><updated>2009-03-25T10:06:38.119+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>Introduction</title><content type='html'>Welcome to my webblog!
&lt;br/&gt;&lt;br/&gt;
I'm Danny de Haas, a Dutch guy who is living in Amsterdam. I'm a professional software developer since 1999 and have experiences with C#, VB.NET, VB6, SQL 2000/2005, SharePoint Portal Server 2003 and MOSS 2007.
&lt;br/&gt;&lt;br/&gt;
I work for a Dutch software company called &lt;a href="http://www.macaw.nl/" target="_blank"&gt;Macaw&lt;/a&gt; and I am a member of the solution center 'Rich Internet Solutions' (RIS). Most of the time I've been busy with SharePoint Web Content Management. This platform has alot to talk about. So stay tuned! :-)
&lt;br/&gt;&lt;br/&gt;
....to be continued.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1547054644249623125-5238218082342209979?l=ddehaas.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ddehaas.blogspot.com/feeds/5238218082342209979/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ddehaas.blogspot.com/2009/02/introduction.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/5238218082342209979'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1547054644249623125/posts/default/5238218082342209979'/><link rel='alternate' type='text/html' href='http://ddehaas.blogspot.com/2009/02/introduction.html' title='Introduction'/><author><name>Danny de Haas</name><uri>http://www.blogger.com/profile/03475646948477442965</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
