﻿<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:blogChannel="http://backend.userland.com/blogChannelModule" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
  <channel>
    <title>Håvard Hebnes</title>
    <description>SharePoint and my notes</description>
    <link>http://blog.hhebnes.no/</link>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>BlogEngine.NET 1.6.0.0</generator>
    <language>en-US</language>
    <blogChannel:blogRoll>http://blog.hhebnes.no/opml.axd</blogChannel:blogRoll>
    <blogChannel:blink>http://blog.hhebnes.no/syndication.axd</blogChannel:blink>
    <dc:creator>Håvard Hebnes</dc:creator>
    <dc:title>Håvard Hebnes</dc:title>
    <geo:lat>0.000000</geo:lat>
    <geo:long>0.000000</geo:long>
    <item>
      <title>Change AssociatedContentType for a pagelayout</title>
      <description>&lt;p&gt;If you want to change the associated contenttype for a pagelayout, you can do it like this:&lt;/p&gt;
&lt;pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;"&gt;// first you need a reference to a PublihingSite or PublishingWeb
var pubSite = new PublishingSite(site); 

// then we need to get all available pagelayouts
var pageLayouts = pubSite.GetPageLayouts(false); 

// try to find the pagelayout you want to update
var pageLayout = GetPageLayout(pageLayouts, "pagelayout.aspx"); 

// if pagelayout exists, update it (here you need to have a ref to the contenttype)
if (pageLayout != null)
    UpdateAssiciationContentType(contentType, pageLayout); 

/// &amp;lt;summary&amp;gt;
/// Helper method to update associated contenttype for a pagelayout
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name="newsContentType"&amp;gt;&amp;lt;/param&amp;gt;
/// &amp;lt;param name="pageLayout"&amp;gt;&amp;lt;/param&amp;gt;
private static void UpdateAssiciationContentType(SPContentType contentType, PageLayout pageLayout)
{
    // Check out the pagelayout
    pageLayout.ListItem.File.CheckOut(); 

    // set AssociatedContentType
    pageLayout.AssociatedContentType = contentType; 

    pageLayout.Update(); 

    // CheckIn, Publish and approve changes
    pageLayout.ListItem.File.CheckIn("Changed associated contenttype");
    pageLayout.ListItem.File.Publish("");
    pageLayout.ListItem.File.Approve("Change approved");
} 

/// &amp;lt;summary&amp;gt;
/// Get pagelayout by name
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name="pageLayouts"&amp;gt;&amp;lt;/param&amp;gt;
/// &amp;lt;param name="name"&amp;gt;&amp;lt;/param&amp;gt;
/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
private static PageLayout GetPageLayout(IEnumerable&amp;lt;PageLayout&amp;gt; pageLayouts, string name)
{
    var layouts = from PageLayout layout in pageLayouts
                  where layout.Name == name
                  select layout; 

    return layouts.Count() == 1 ? layouts.ElementAt(0) : null;
}&lt;/pre&gt;</description>
      <link>http://blog.hhebnes.no/post/Change-AssociatedContentType-for-a-pagelayout.aspx</link>
      <author>hhebnes</author>
      <comments>http://blog.hhebnes.no/post/Change-AssociatedContentType-for-a-pagelayout.aspx#comment</comments>
      <guid>http://blog.hhebnes.no/post.aspx?id=436e911d-0339-4e98-8462-b5cb0d3862db</guid>
      <pubDate>Sat, 18 Jul 2009 11:37:00 +0200</pubDate>
      <category>SharePoint</category>
      <dc:publisher>hhebnes</dc:publisher>
      <pingback:server>http://blog.hhebnes.no/pingback.axd</pingback:server>
      <pingback:target>http://blog.hhebnes.no/post.aspx?id=436e911d-0339-4e98-8462-b5cb0d3862db</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://blog.hhebnes.no/trackback.axd?id=436e911d-0339-4e98-8462-b5cb0d3862db</trackback:ping>
      <wfw:comment>http://blog.hhebnes.no/post/Change-AssociatedContentType-for-a-pagelayout.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.hhebnes.no/syndication.axd?post=436e911d-0339-4e98-8462-b5cb0d3862db</wfw:commentRss>
    </item>
    <item>
      <title>Create ContentType programatically</title>
      <description>&lt;p&gt;Out of the box SharePoint has a few content types that you can use. If you would like to create your own that inherits from one of these you could do it like this:&lt;/p&gt;
&lt;pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;"&gt;// first we reference the content type we want to inherit from
SPContentType pageContentType = web.AvailableContentTypes[ContentTypeId.Page];

// create our new content type
var customContentType = new SPContentType(pageContentType, web.ContentTypes, "Name of content type");
newsContentType.Group = "Custom content type group";

// add content type to the site
web.ContentTypes.Add(customContentType);
web.Update();&lt;/pre&gt;
&lt;p&gt;To add a custom sitecolumn to our new content type:&lt;/p&gt;
&lt;pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;"&gt;// first we need to find our site column
SPField siteColumn = web.AvailableFields.GetFieldByInternalName("InternalSiteColumnName");

// Add column to our new content type
customContentType.FieldLinks.Add(new SPFieldLink(siteColumn));

// Update content type
customContentType.Update();&lt;/pre&gt;</description>
      <link>http://blog.hhebnes.no/post/Create-ContentType-programatically.aspx</link>
      <author>hhebnes</author>
      <comments>http://blog.hhebnes.no/post/Create-ContentType-programatically.aspx#comment</comments>
      <guid>http://blog.hhebnes.no/post.aspx?id=b12b6bd7-95cf-4e6f-a61b-8e45c4362d62</guid>
      <pubDate>Tue, 14 Jul 2009 21:49:00 +0200</pubDate>
      <category>SharePoint</category>
      <dc:publisher>hhebnes</dc:publisher>
      <pingback:server>http://blog.hhebnes.no/pingback.axd</pingback:server>
      <pingback:target>http://blog.hhebnes.no/post.aspx?id=b12b6bd7-95cf-4e6f-a61b-8e45c4362d62</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://blog.hhebnes.no/trackback.axd?id=b12b6bd7-95cf-4e6f-a61b-8e45c4362d62</trackback:ping>
      <wfw:comment>http://blog.hhebnes.no/post/Create-ContentType-programatically.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.hhebnes.no/syndication.axd?post=b12b6bd7-95cf-4e6f-a61b-8e45c4362d62</wfw:commentRss>
    </item>
    <item>
      <title>Trouble running stsadm –o migrateuser</title>
      <description>&lt;p&gt;Yesterday I tried to migrate a user from one domain to another domain running: &lt;br /&gt; &lt;sub&gt;stsadm -o migrateuser -oldlogin domain1\user -newlogin domain2\user &amp;ndash;ignoresidhistory&lt;/sub&gt;&lt;/p&gt;
&lt;p&gt;This resulted in the following error: &lt;br /&gt; &lt;sub&gt;The site with the id c725736f-d942-4475-b3c1-bf1f8c8a1339 could not be found.&lt;/sub&gt;&lt;/p&gt;
&lt;p&gt;To find out which sitecollection this id belongs to I ran the following sql query: &lt;br /&gt; &lt;sub&gt;SELECT [Id], [SiteId], [FullUrl] &lt;br /&gt; FROM [WSS_Content_DB].[dbo].[Webs] where SiteId = 'c725736f-d942-4475-b3c1-bf1f8c8a1339'&lt;/sub&gt;&lt;/p&gt;
&lt;p&gt;Result: &lt;br /&gt; &lt;sub&gt;Id&amp;nbsp;&amp;nbsp;&amp;nbsp; SiteId&amp;nbsp;&amp;nbsp;&amp;nbsp; FullUrl &lt;br /&gt; 99642E4D-6C53-49D0-996C-7650C494971C&amp;nbsp;&amp;nbsp;&amp;nbsp; c725736f-d942-4475-b3c1-bf1f8c8a1339&amp;nbsp;&amp;nbsp;&amp;nbsp; personal/mysiteuser&lt;/sub&gt;&lt;/p&gt;
&lt;p&gt;After this I ran another test which requires that SP2 is installed on your server: &lt;br /&gt; &lt;sub&gt;stsadm -o preupgradecheck&lt;/sub&gt;&lt;/p&gt;
&lt;p&gt;The result from this command can be found here: &lt;br /&gt; C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\LOGS\PreUpgradeCheck-TIMESTAMP.htm&lt;/p&gt;
&lt;p&gt;Look for the following section: &lt;br /&gt; &lt;strong&gt;Failed : Orphaned site collections&lt;/strong&gt; &lt;br /&gt; &lt;br /&gt; An orphaned site collection is a site collection exists in the content database, but it is not in the configruation site map. Such site collections is not accessible and will not be upgraded properly.The follow orphaned site collections where found:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;/personal/mysiteuser(Data Source=sqlserver\instance;Initial Catalog=WSS_Content_DB;Integrated Security=True;Enlist=False;Connect Timeout=15) &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I then confirmed that this sitecollection was the same as the one that I had problems with.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt; &lt;br /&gt; To fix this I deleted the sitecollection with this command (Requires SP2 if you use &amp;ndash;force or -siteid): &lt;br /&gt; &lt;sub&gt;stsadm -o deletesite -siteid c725736f-d942-4475-b3c1-bf1f8c8a1339 -databaseserver SQLSERVER\instance &lt;br /&gt; -databasename wss_content_db -force &lt;/sub&gt;&lt;/p&gt;
&lt;p&gt;After this I migrated the user successfully.&lt;/p&gt;
&lt;p&gt;Links: &lt;br /&gt; &lt;a title="Deletesite- Stsadm operation" href="http://technet.microsoft.com/en-us/library/cc288016.aspx"&gt;Deletesite- Stsadm operation&lt;/a&gt;&lt;/p&gt;</description>
      <link>http://blog.hhebnes.no/post/Trouble-running-stsadm-e28093o-migrateuser.aspx</link>
      <author>hhebnes</author>
      <comments>http://blog.hhebnes.no/post/Trouble-running-stsadm-e28093o-migrateuser.aspx#comment</comments>
      <guid>http://blog.hhebnes.no/post.aspx?id=835ff7e1-2ad9-4ef6-8513-d9537c0a6b4e</guid>
      <pubDate>Wed, 08 Jul 2009 10:26:00 +0200</pubDate>
      <category>SharePoint</category>
      <dc:publisher>hhebnes</dc:publisher>
      <pingback:server>http://blog.hhebnes.no/pingback.axd</pingback:server>
      <pingback:target>http://blog.hhebnes.no/post.aspx?id=835ff7e1-2ad9-4ef6-8513-d9537c0a6b4e</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://blog.hhebnes.no/trackback.axd?id=835ff7e1-2ad9-4ef6-8513-d9537c0a6b4e</trackback:ping>
      <wfw:comment>http://blog.hhebnes.no/post/Trouble-running-stsadm-e28093o-migrateuser.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.hhebnes.no/syndication.axd?post=835ff7e1-2ad9-4ef6-8513-d9537c0a6b4e</wfw:commentRss>
    </item>
    <item>
      <title>Workflow Failed On Start</title>
      <description>&lt;p&gt;Recently I tried to create a custom approval workflow using VS2008 with wspbuilder. I successfully deployed the wsp and added the workflow to a custom list, but when I started the workflow I got an error saying: Failed on Start (retrying)&lt;/p&gt;
&lt;p&gt;In the SharePoint logfile I found this error: &lt;br /&gt;&lt;sub&gt;Engine RunWorkflow: System.Workflow.ComponentModel.Compiler.WorkflowValidationFailedException: The &lt;br /&gt;workflow failed validation. at System.Workflow.Runtime.WorkflowDefinitionDispenser.ValidateDefinition(Activity &lt;br /&gt;root, Boolean isNewType, ITypeProvider typeProvider) at System.Workflow.Runtime.WorkflowDefinitionDispenser.LoadRootActivity(Type workflowType, Boolean createDefinition, Boolean initForRuntime) at System.Workflow.Runtime.WorkflowDefinitionDispenser.GetRootActivity(Type &lt;br /&gt;workflowType, Boolean createNew, Boolean initForRuntime) &lt;br /&gt;at System.Workflow.Runtime.WorkflowRuntime.InitializeExecutor(Guid instanceId, &lt;br /&gt;CreationContext context, WorkflowExecutor executor, WorkflowInstance workflowInstance)&lt;/sub&gt;&lt;/p&gt;
&lt;p&gt;After debugging my workflow I noticed that the error occured in a while loop where I used &amp;ldquo;Declarative Rule Condition&amp;rdquo;. The solution for this problem was to edit the Visual Studio project file (using notepad) and add the second line below:&lt;/p&gt;
&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;
&lt;p id="codeSnippet"&gt;&lt;sub&gt;&amp;lt;Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /&amp;gt;&lt;br /&gt;&lt;strong&gt;&amp;lt;Import Project="$(MSBuildExtensionsPath)\Microsoft\Windows Workflow Foundation\v3.5\Workflow.Targets" /&amp;gt;&lt;/strong&gt;&lt;/sub&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Then I reloaded the project and redeployed the wsp and everything worked :)&lt;/p&gt;</description>
      <link>http://blog.hhebnes.no/post/WSPBuilder-Workflow-Failed-On-Start.aspx</link>
      <author>hhebnes</author>
      <comments>http://blog.hhebnes.no/post/WSPBuilder-Workflow-Failed-On-Start.aspx#comment</comments>
      <guid>http://blog.hhebnes.no/post.aspx?id=a5db46f9-be20-4927-ba33-72a7680f77b8</guid>
      <pubDate>Fri, 26 Jun 2009 14:48:00 +0200</pubDate>
      <category>SharePoint</category>
      <category>Workflows</category>
      <dc:publisher>hhebnes</dc:publisher>
      <pingback:server>http://blog.hhebnes.no/pingback.axd</pingback:server>
      <pingback:target>http://blog.hhebnes.no/post.aspx?id=a5db46f9-be20-4927-ba33-72a7680f77b8</pingback:target>
      <slash:comments>8</slash:comments>
      <trackback:ping>http://blog.hhebnes.no/trackback.axd?id=a5db46f9-be20-4927-ba33-72a7680f77b8</trackback:ping>
      <wfw:comment>http://blog.hhebnes.no/post/WSPBuilder-Workflow-Failed-On-Start.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.hhebnes.no/syndication.axd?post=a5db46f9-be20-4927-ba33-72a7680f77b8</wfw:commentRss>
    </item>
    <item>
      <title>Using LINQ with SharePoint</title>
      <description>&lt;p&gt;If you're looking for a specific item in a list, there are many ways you can get it.&lt;/p&gt;
&lt;p&gt;You could go through the whole list using a loop (not recommended):&lt;/p&gt;
&lt;pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;"&gt;foreach (SPListItem item in list.Items) 
{ 
    if(item.Title == "Title1892") 
        return item; 
}&lt;/pre&gt;
&lt;p&gt;You could use a SPQuery:&lt;/p&gt;
&lt;pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;"&gt;var tmpQuery = new SPQuery 
                   { 
                       Query = 
                           @"&amp;lt;Where&amp;gt; 
                              &amp;lt;Eq&amp;gt; 
                                 &amp;lt;FieldRef Name='Title' /&amp;gt; 
                                 &amp;lt;Value Type='Text'&amp;gt;Title1892&amp;lt;/Value&amp;gt; 
                              &amp;lt;/Eq&amp;gt; 
                           &amp;lt;/Where&amp;gt;" 
                   }; 
list.GetItems(tmpQuery);&lt;/pre&gt;
&lt;p&gt;or you could use LINQ: &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Method 1&lt;/strong&gt;:&lt;/p&gt;
&lt;pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;"&gt;List&amp;lt;SPListItem&amp;gt; q = (from SPListItem item in list.Items 
        orderby item.Title 
            ascending 
        where item.Title == "Title1892" 
        select item).ToList();

Console.WriteLine(q[0].Title);&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Method 2&lt;/strong&gt;:&lt;/p&gt;
&lt;pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;"&gt;var query = from SPListItem item in list.Items 
                      orderby item.Title 
                          ascending 
                      where item.Title == "Title1892" 
                      select item;

Console.WriteLine(query.ElementAt(0).Title);&lt;/pre&gt;</description>
      <link>http://blog.hhebnes.no/post/Using-LINQ-with-SharePoint.aspx</link>
      <author>hhebnes</author>
      <comments>http://blog.hhebnes.no/post/Using-LINQ-with-SharePoint.aspx#comment</comments>
      <guid>http://blog.hhebnes.no/post.aspx?id=ed0bfa28-4afa-4540-9d14-2f2341ffdd4b</guid>
      <pubDate>Sat, 20 Jun 2009 16:46:00 +0200</pubDate>
      <category>LINQ</category>
      <category>SharePoint</category>
      <dc:publisher>hhebnes</dc:publisher>
      <pingback:server>http://blog.hhebnes.no/pingback.axd</pingback:server>
      <pingback:target>http://blog.hhebnes.no/post.aspx?id=ed0bfa28-4afa-4540-9d14-2f2341ffdd4b</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://blog.hhebnes.no/trackback.axd?id=ed0bfa28-4afa-4540-9d14-2f2341ffdd4b</trackback:ping>
      <wfw:comment>http://blog.hhebnes.no/post/Using-LINQ-with-SharePoint.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.hhebnes.no/syndication.axd?post=ed0bfa28-4afa-4540-9d14-2f2341ffdd4b</wfw:commentRss>
    </item>
    <item>
      <title>Access is denied crawl SharePoint 2007 webapplications</title>
      <description>&lt;p&gt;If you're using host headers when creating new webapplications in SharePoint, you'll probably get this error when you're trying to run the search crawler:&lt;/p&gt;
&lt;p&gt;"Access is denied. Verify that either the Default Content Access Account has access to this repository, or add a crawl rule to crawl this repository. If the repository being crawled is a SharePoint repository, verify that the account you are using has "Full Read" permissions on the SharePoint Web Application being crawled. (The item was deleted because it was either not found or the crawler was denied access to it.)"&lt;/p&gt;
&lt;p&gt;To fix this you can create the webapplications without hostheaders or you can try this:&lt;br /&gt;&lt;a href="http://support.microsoft.com/kb/896861" target="_blank"&gt;http://support.microsoft.com/kb/896861&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I've used the first method:&lt;br /&gt;- run regedit&lt;br /&gt;- goto &lt;strong class="uiterm"&gt;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0&lt;br /&gt;&lt;/strong&gt;&lt;span class="uiterm"&gt;- add a new &lt;/span&gt;&lt;strong class="uiterm"&gt;Multi-String Value &lt;/strong&gt;named &lt;strong&gt;&lt;span class="userInput"&gt;BackConnectionHostNames &lt;/span&gt;&lt;/strong&gt;and press enter&lt;strong&gt;&lt;span class="userInput"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;- edit the new key and type the host headers you would like (seperate by newline)&lt;br /&gt;- exit regedit and restart the &lt;strong&gt;IISAdmin service&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;More details can be found at &lt;a href="http://www.sharepointblogs.com/tommysegoro/archive/2009/02/03/moss-2007-search-crawling-error-access-denied.aspx" target="_blank"&gt;Tommy Segoros blog&lt;/a&gt;.&lt;strong&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong class="uiterm"&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/p&gt;</description>
      <link>http://blog.hhebnes.no/post/Access-is-denied-crawl-SharePoint-2007-webapplications.aspx</link>
      <author>hhebnes</author>
      <comments>http://blog.hhebnes.no/post/Access-is-denied-crawl-SharePoint-2007-webapplications.aspx#comment</comments>
      <guid>http://blog.hhebnes.no/post.aspx?id=1d4278fd-1ab4-4752-adac-d694eb712a4b</guid>
      <pubDate>Fri, 19 Jun 2009 07:35:00 +0200</pubDate>
      <category>Search</category>
      <category>Shared Services Provider</category>
      <category>SharePoint</category>
      <dc:publisher>hhebnes</dc:publisher>
      <pingback:server>http://blog.hhebnes.no/pingback.axd</pingback:server>
      <pingback:target>http://blog.hhebnes.no/post.aspx?id=1d4278fd-1ab4-4752-adac-d694eb712a4b</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://blog.hhebnes.no/trackback.axd?id=1d4278fd-1ab4-4752-adac-d694eb712a4b</trackback:ping>
      <wfw:comment>http://blog.hhebnes.no/post/Access-is-denied-crawl-SharePoint-2007-webapplications.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.hhebnes.no/syndication.axd?post=1d4278fd-1ab4-4752-adac-d694eb712a4b</wfw:commentRss>
    </item>
  </channel>
</rss>