27 May 2009

DevDays 2009 (PreConference DeepDive)

Today I visited the first day of the DevDays 2009 (PreConference DeepDive) in The Hague (Netherlands) and attended a session about SharePoint developing by Wouter van Vugt.

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.

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.

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.

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.

Overall I had a very interesting day full of How To's, demo's and lots of code examples.

15 May 2009

The SharePoint Developer Introduction for .NET Developers

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.

  • Background info
  • Webcasts
  • Screencasts
  • Demo's
  • How to's
  • Virtual PC's image
  • Hands on Labs
  • Links to resources and forums
  • ...and add some

Check it out on: Do Less. Get More. Develop on SharePoint.

11 May 2009

How to detect when a SharePoint Publishing Page is detached from it's PageLayout

Recently I found a new thing about SharePoint Publishing pages. From within SharePoint Designer, publishing pages can be detached from there pagelayout!

I guess that for some of you this not a a new thing, but I didn't know.

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.

To detach a page in SharePoint designer, open the Pages list and right click on the page.


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.'

To reattach a page to it's pagelayout, right click on the page again.


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.
Value format: 'http://xxxx/catalogs/masterpage/xxxx.aspx, ContentTypeName'

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.
Value format: 'http://www.microsoft.com/publishing?DisconnectedPublishingPage=true, http://xxxx/_catalogs/masterpage/xxxx.aspx

To detect all disconnected publishing pages in a site collection I created a the following code:
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 = "< Webs Scope="SiteCollection">";
    dataQuery.Lists = "< Lists ServerTemplate="850">";
    dataQuery.ViewFields = "< FieldRef Name="FileRef" Nullable="TRUE">";
    dataQuery.Query = "< Where>" +
                            "< Contains>" +
                                "< FieldRef Name="PublishingPageLayout">" +
                                "< Value Type="Text">?DisconnectedPublishingPage=true< /Value>" +
                            "< /Contains>" +
                        "< /Where>";                              

    // 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 > -1)
            {
                fieldRef = fieldRef.Substring(pos + 2);
            }
        }

        Console.WriteLine(fieldRef);
    }
}          
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.

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.
  • Report Title: All Pages Disconnected from PageLayout
  • Resource Id: (leave blank)
  • Resource Id: (leave blank)
  • CAML List Type: <Lists ServerTemplate='850' />
  • CAML Query: <Where><Contains><FieldRef Name='PublishingPageLayout' /><Value Type='Text'>?DisconnectedPublishingPage=true</Value></Contains></Where>
  • Target Audiences: (leave blank)
  • Report Description: All publishing pages that are detached from their pagelayout by using SharePoint Designer.



Afer creating a new report, you can access it through the Site Actions button.