<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Florent Clairambault &#187; Sharepoint 2007</title>
	<atom:link href="http://florent.clairambault.fr/tag/sharepoint-2007/feed" rel="self" type="application/rss+xml" />
	<link>http://florent.clairambault.fr</link>
	<description></description>
	<lastBuildDate>Sat, 04 Feb 2012 19:56:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-alpha-19719</generator>
		<item>
		<title>Inside Sharepoint</title>
		<link>http://florent.clairambault.fr/inside-sharepoint?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=inside-sharepoint</link>
		<comments>http://florent.clairambault.fr/inside-sharepoint#comments</comments>
		<pubDate>Tue, 04 Aug 2009 20:55:01 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[.NET Reflector]]></category>
		<category><![CDATA[C# .Net]]></category>
		<category><![CDATA[File Disassembler]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[Sharepoint 2007]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=1397</guid>
		<description><![CDATA[I recently took the time to take a look inside the Microsoft.Sharepoint.dll using reflector. I&#8217;m not sure I have the right to do that. And I&#8217;m pretty sure I don&#8217;t have the right to publish any code extracted from it, so I won&#8217;t show any. Using SPSite(s) and SPWeb(s) If you do some timing on [...]]]></description>
			<content:encoded><![CDATA[<p>I recently took the time to take a look inside the Microsoft.Sharepoint.dll <a href="http://florent.clairambault.fr/net-reflector-file-disassembler">using reflector</a>. I&#8217;m <a href="http://stackoverflow.com/questions/906746/is-it-legal-to-use-reflector-to-analyze-binaries-when-the-owner-forbids-a-viewing">not sure I have the right to do that</a>. And I&#8217;m pretty sure I don&#8217;t have the right to publish any code extracted from it, so I won&#8217;t show any.</p>
<p><strong>Using SPSite(s) and SPWeb(s)</strong><br />
If you do some timing on the SPWeb creation call (SPSite.OpenWeb), you will find out that it&#8217;s freaking fast (less then 1 ms on my server). The reason is that the most heavy object, the SPRequest class, is shared among SPWebs of a SPSite. The Dispose call only &#8220;Invalidate&#8221; the SPWeb, and if this SPWeb is the owner of the SPRequest (which is SPContext.Current.Web object in most of the cases), it releases it. </p>
<p>Personnaly, I like to have something like that when I use a particular SPWeb along my code in a WebPart :</p>

<div class="wp_codebox"><table><tr id="p13975"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p1397code5"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> SPWeb _rootWeb<span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> SPWeb RootWeb <span style="color: #008000;">&#123;</span>
    get <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> _rootWeb <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            _rootWeb <span style="color: #008000;">=</span> SPContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Site</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RootWeb</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> _rootWeb <span style="color: #008000;">!=</span> SPContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Web</span> <span style="color: #008000;">&#41;</span>
                _toDispose<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span> _rootWeb <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>  
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> _rootWeb<span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">private</span> List<span style="color: #008000;">&lt;</span>IDisposable<span style="color: #008000;">&gt;</span> _toDispose <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span>IDisposable<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnUnLoad<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">foreach</span><span style="color: #008000;">&#40;</span> var disp <span style="color: #0600FF; font-weight: bold;">in</span> _toDispose <span style="color: #008000;">&#41;</span>
        disp<span style="color: #008000;">.</span><span style="color: #0000FF;">Dispose</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>But the code above won&#8217;t make you gain a 1 ms compared to this code (which is shorter and potentially safer, you don&#8217;t need to dispose everything) :</p>

<div class="wp_codebox"><table><tr id="p13976"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p1397code6"><pre class="csharp" style="font-family:monospace;">var rootWeb <span style="color: #008000;">=</span> SPContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Site</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">try</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Your code</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">finally</span> <span style="color: #008000;">&#123;</span>
     <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> rootWeb <span style="color: #008000;">!=</span> SPContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Web</span> <span style="color: #008000;">&#41;</span>
         rootWeb<span style="color: #008000;">.</span><span style="color: #0000FF;">Dispose</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>If you had to access some more indirect objects, you certainly should keep the code showed earlier. For instance to use a SuperToken Web :</p>

<div class="wp_codebox"><table><tr id="p13977"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code" id="p1397code7"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> SPSite _stSite<span style="color: #008000;">;</span>
SPSite STSite <span style="color: #008000;">&#123;</span>
    get <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> _stSite <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            _stSite <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SPSite<span style="color: #008000;">&#40;</span> SPContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Site</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Url</span>, SPContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Site</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SystemAccount</span><span style="color: #008000;">.</span><span style="color: #0000FF;">UserToken</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> _stSite <span style="color: #008000;">!=</span> SPContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Site</span> <span style="color: #008000;">&#41;</span>
                _toDispose<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span> _stSite <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> _stSite<span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">private</span> SPWeb _stWeb<span style="color: #008000;">;</span>
SPWeb STWeb <span style="color: #008000;">&#123;</span>
    get <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> _stWeb <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            _stWeb <span style="color: #008000;">=</span> STSite<span style="color: #008000;">.</span><span style="color: #0000FF;">OpenWeb</span><span style="color: #008000;">&#40;</span> SPContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Web</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Url</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> _stWeb <span style="color: #008000;">!=</span> SPContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Web</span> <span style="color: #008000;">&#41;</span>
                _toDispose<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span> _stWeb <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> _stWeb<span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">private</span> List<span style="color: #008000;">&lt;</span>IDisposable<span style="color: #008000;">&gt;</span> _toDispose <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span>IDisposable<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnUnLoad<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">foreach</span><span style="color: #008000;">&#40;</span> var disp <span style="color: #0600FF; font-weight: bold;">in</span> _toDispose <span style="color: #008000;">&#41;</span>
        disp<span style="color: #008000;">.</span><span style="color: #0000FF;">Dispose</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Here, opening these new SPSite and SPWeb takes 200 ms on my server. Making sure this only happen once per webpart (or better, per page) can really boost your performances.</p>
<p><strong>The SPRequest object</strong><br />
Well&#8230; I was very disapointed, the SPRequest object references an SPRequestInternalClass from the Microsoft.Sharepoint.Library assembly which only uses interrop COM+ methods. So, it&#8217;s basically wrapping COM+ methods. The SPRequest does a lot of exception handling and it keeps track of where (with the stacktrace) it has been created and the size of the &#8220;unmanaged stack&#8221;.</p>
<p><strong>Optimization</strong><br />
I like how they did their code. It&#8217;s pretty optimized (they even use a bunch of gotos). But sometimes there is some weird things and I don&#8217;t know if it&#8217;s the compiler&#8217;s or the developer&#8217;s fault. If you look at the code, they have an SPRequestManager.SPRequestsPerThreadWarning property, which gets (in the Registry, at &#8220;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\HeapSettings\LocalSPRequestWarnCount&#8221;) the max number of opened SPRequest objects opened before logging it (or 8 if this entry doesn&#8217;t exist), that takes twice the amount of code it would normaly require.</p>
<p><strong>The limit of disassembling</strong><br />
The most frustrating part is there are tons of really important methods that are obfuscated (and that .Net reflector doesn&#8217;t disassemble, it could at least give the IL code in comments). I just have :</p>

<div class="wp_codebox"><table><tr id="p13978"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p1397code8"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> xxx<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// This item is obfuscated and can not be translated.</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>For instance, I really would have liked to see how works the SPList.Update() method, but it&#8217;s also obfuscated. </p>
<p><strong>You should explore it too</strong><br />
In the Microsoft.Office.Server.Search assembly, you will also find some pretty interesting things. If you look how works the standard search webparts, well you will be pretty disapointed. The advanced search uses an internal (in the C# meaning) shared object.</p>
<p>Before doing your own webpart, you should take a look at the overriden methods of some sharepoint webparts. It can show you, for instance, how to create your own toolparts. In my last project, I used a stupid text property instead of using a DropDownList in a ToolPart, I was very disappointed with myself when I discovered this.</p>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/inside-sharepoint/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sharepoint : Using BaseFieldControl</title>
		<link>http://florent.clairambault.fr/sharepoint-using-basefieldcontrol?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sharepoint-using-basefieldcontrol</link>
		<comments>http://florent.clairambault.fr/sharepoint-using-basefieldcontrol#comments</comments>
		<pubDate>Tue, 28 Jul 2009 20:45:50 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[BaseFieldControl]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[Sharepoint 2007]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=1519</guid>
		<description><![CDATA[What for ? Sharepoint&#8217;s API provides some standard form controls to render each column. This is the controls used to render the standard add and edit forms. And they all inherit the BaseFieldControl class. In other word : In any SPList, you have some SPField fields and each of these SPField has the super power [...]]]></description>
			<content:encoded><![CDATA[<p><strong>What for ?</strong><br />
Sharepoint&#8217;s API provides some standard form controls to render each column. This is the controls used to render the standard add and edit forms. And they all inherit the BaseFieldControl class.</p>
<p>In other word : In any SPList, you have some SPField fields and each of these SPField has the super power to create a BaseFieldControl. Each BaseFieldControl is a CompositeControl containing ASP.Net controls.</p>
<p>For a single line field, you will just have a wrapped TextBox. But for some more advanced fields like a multi-select lookup field (SPFieldLookup) or rich text field, it can generate some &#8220;complex&#8221; controls and their related javascript code.</p>
<p>The BaseFieldControl can be directly connected to your Sharepoint&#8217;s SPListItem and the BaseFieldControl.Value will match the format required to fill the SPListItem.</p>
<p>You can create your own BaseFieldControl controls, and you can directly mess up the BaseFieldControl.Controls property if you like to (that can be useful). I personally had to create a variation of the MultipleLookupField (that&#8217;s the BaseFieldControl used for a SPLookupField with the AllowMultipleValues property enabled) to create a CheckBoxList of selected items (that what the client wanted).</p>
<p><strong>How to use them to display data ?</strong><br />
You can get it by accessing the SPField.FieldRenderingControl property. It gives you everything you need. Each BaseFieldControl has a ControlMode property (SPControlMode enum) which can be set to New, Edit, Display or Invalid (I don&#8217;t know why this third one exists).</p>
<p>Here is a stripped down version of the necessary code :</p>

<div class="wp_codebox"><table><tr id="p151914"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code" id="p1519code14"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> CreateChildControls<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
&nbsp;
     <span style="color: #008080; font-style: italic;">// The web used</span>
     var web <span style="color: #008000;">=</span> SPContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Web</span><span style="color: #008000;">;</span>
&nbsp;
     <span style="color: #008080; font-style: italic;">// This is the code you could have easily guessed :</span>
     var list <span style="color: #008000;">=</span> web<span style="color: #008000;">.</span><span style="color: #0000FF;">Lists</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;MyList&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
     var item <span style="color: #008000;">=</span> list<span style="color: #008000;">.</span><span style="color: #0000FF;">GetItemById</span><span style="color: #008000;">&#40;</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
     var field <span style="color: #008000;">=</span> item<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;DateOfEvent&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
     var bfc <span style="color: #008000;">=</span> field<span style="color: #008000;">.</span><span style="color: #0000FF;">FieldRenderingControl</span><span style="color: #008000;">;</span>
&nbsp;
     <span style="color: #008080; font-style: italic;">// This is when it becomes tricky :</span>
     var renderContext <span style="color: #008000;">=</span> SPContext<span style="color: #008000;">.</span><span style="color: #0000FF;">GetContext</span><span style="color: #008000;">&#40;</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Context</span>, <span style="color: #FF0000;">0</span>, list<span style="color: #008000;">.</span><span style="color: #0000FF;">ID</span>, web <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
     bfc<span style="color: #008000;">.</span><span style="color: #0000FF;">ListId</span> <span style="color: #008000;">=</span> list<span style="color: #008000;">.</span><span style="color: #0000FF;">ID</span><span style="color: #008000;">;</span>
     bfc<span style="color: #008000;">.</span><span style="color: #0000FF;">FieldName</span> <span style="color: #008000;">=</span> field<span style="color: #008000;">.</span><span style="color: #0000FF;">InternalName</span><span style="color: #008000;">;</span>
     bfc<span style="color: #008000;">.</span><span style="color: #0000FF;">ID</span> <span style="color: #008000;">=</span> field<span style="color: #008000;">.</span><span style="color: #0000FF;">InternalName</span><span style="color: #008000;">;</span>
     bfc<span style="color: #008000;">.</span><span style="color: #0000FF;">ControlMode</span> <span style="color: #008000;">=</span> SPControlMode<span style="color: #008000;">.</span><span style="color: #0000FF;">Edit</span><span style="color: #008000;">;</span>
     bfc<span style="color: #008000;">.</span><span style="color: #0000FF;">RenderContext</span> <span style="color: #008000;">=</span> renderContext<span style="color: #008000;">;</span>
     bfc<span style="color: #008000;">.</span><span style="color: #0000FF;">ItemContext</span> <span style="color: #008000;">=</span> renderContext<span style="color: #008000;">;</span>
     bfc<span style="color: #008000;">.</span><span style="color: #0000FF;">EnableViewState</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
     bfc<span style="color: #008000;">.</span><span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
&nbsp;
     Controls<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span> bfc <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>And if you want to use it as an input form, you have to get a non existing SPListItem :</p>

<div class="wp_codebox"><table><tr id="p151915"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p1519code15"><pre class="csharp" style="font-family:monospace;">var item <span style="color: #008000;">=</span> list<span style="color: #008000;">.</span><span style="color: #0000FF;">GetItemById</span><span style="color: #008000;">&#40;</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
var field <span style="color: #008000;">=</span> item<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;DateOfEvent&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>By this :</p>

<div class="wp_codebox"><table><tr id="p151916"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p1519code16"><pre class="csharp" style="font-family:monospace;">var item <span style="color: #008000;">=</span> list<span style="color: #008000;">.</span><span style="color: #0000FF;">Items</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
var field <span style="color: #008000;">=</span> list<span style="color: #008000;">.</span><span style="color: #0000FF;">Fields</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;DateOfEvent&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>And then later add this reflection code to force the render context to take into account the temporary created item :</p>

<div class="wp_codebox"><table><tr id="p151917"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p1519code17"><pre class="csharp" style="font-family:monospace;">var fiContextItem <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span> <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span> SPContext <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetField</span><span style="color: #008000;">&#40;</span> <span style="color: #666666;">&quot;m_item&quot;</span>, BindingFlags<span style="color: #008000;">.</span><span style="color: #0000FF;">Instance</span> <span style="color: #008000;">|</span> BindingFlags<span style="color: #008000;">.</span><span style="color: #0000FF;">NonPublic</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
fiContextItem<span style="color: #008000;">.</span><span style="color: #0000FF;">SetValue</span><span style="color: #008000;">&#40;</span> renderContext, item <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p><strong>If you use multiple SPWeb&#8230;</strong><br />
In your Sharepoint code, you might need to use more than one SPWeb. In that case, you must absolutely take care of creating the right SPContext (using the SPWeb of the SPList of the source SPField) for each BaseFieldControl used.</p>
<p>And if the SPWeb used doesn&#8217;t have the same language as your current site, you can change it easily by doing something like that :</p>

<div class="wp_codebox"><table><tr id="p151918"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1519code18"><pre class="csharp" style="font-family:monospace;">web<span style="color: #008000;">.</span><span style="color: #0000FF;">Locale</span> <span style="color: #008000;">=</span> SPContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Web</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Locale</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p><strong>If you create your own BaseFieldControl&#8230;</strong><br />
If you create your own BaseFieldControl, you should really take a look on the disassembled code of the default BaseFieldControls. It could make you save a lot of time and efforts. And please note that the LookupField (which directly inherits BaseFieldControl) isn&#8217;t sealed. Inheriting from it might be a good way to do your own custom lookup BaseFieldControl.</p>
<p><strong>If you enable the ControlMode = SPControlMode.Display</strong><br />
If you want to use your BFC with the Display ControlMode and want to set a value, you must take care of setting the Value BEFORE setting the ControlMode. If you don&#8217;t do that it will work on the first render but fail on the first PostBack : Your value will not be used (and displayed) by the BFC.</p>
<p><strong>If you check the value of the BFC</strong><br />
If you check the value of the BFC, you have to remember that each BFC create its value for the SPField from which it has been created. For instance, empty values can be returned as String.Empty, null or even the 0 integer.</p>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/sharepoint-using-basefieldcontrol/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Debugging on Sharepoint 2007</title>
		<link>http://florent.clairambault.fr/debugging-on-sharepoint-2007?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=debugging-on-sharepoint-2007</link>
		<comments>http://florent.clairambault.fr/debugging-on-sharepoint-2007#comments</comments>
		<pubDate>Sun, 26 Jul 2009 20:45:48 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[Sharepoint 2007]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=1361</guid>
		<description><![CDATA[Sharepoint debugging isn&#8217;t fully automated. So you should really know how to debug and diagnose your assemblies in any given situation. 1. Attaching to the process It only applies to a debugging environnement. This is the one that everybody knows (or should at least). You deploy your DLL in the GAC, restart your application pool, [...]]]></description>
			<content:encoded><![CDATA[<p>Sharepoint debugging isn&#8217;t fully automated. So you should really know how to debug and diagnose your assemblies in any given situation.</p>
<p><strong>1. Attaching to the process</strong><br />
It only applies to a debugging environnement. </p>
<p>This is the one that everybody knows (or should at least). You deploy your DLL in the GAC, restart your application pool, access your sharepoint web application in order to load the application pool and the DLL and then attach to the right w3wp.exe process (or every w3wp.exe process if you don&#8217;t really know which one to choose).</p>
<p><strong>2. Displaying where the exception happens</strong><br />
It should be used everywhere.</p>
<p>Just after deploying your DLL into the GAC, you should deploy the PDB file with it. In your exception management code, you have the exact line where the exception was thrown. Wether your users report it (with the exact line number), you see it in the logs or you have an automatic reporting system, the point is : You will know exactly where it fails.</p>
<p>If you have a WSP deployment method, you will have :</p>

<div class="wp_codebox"><table><tr id="p136123"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p1361code23"><pre class="batch" style="font-family:monospace;">rem This WSP File contains the MyCorp.MyApp.MyLib library with the 0x123456789 public key token
stsadm -o addsolution -filename %WSPFILE%</pre></td></tr></table></div>

<p>If you have a DLL deployment method, you will have :</p>

<div class="wp_codebox"><table><tr id="p136124"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1361code24"><pre class="batch" style="font-family:monospace;">gacutil /if GAC\MyCorp.MyApp.MyLib.dll</pre></td></tr></table></div>

<p>Either way, you need to add the PDB with this command :</p>

<div class="wp_codebox"><table><tr id="p136125"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p1361code25"><pre class="batch" style="font-family:monospace;">subst X: c:\windows\assembly\gac_msil
copy GAC\MyCorp.MyApp.MyLib.pdb X:\MyCorp.MyApp.MyLib\1.0.0.0_123456789\</pre></td></tr></table></div>

<p>If you&#8217;re not willing to give away your PDB file (it contains you complete code source and consumes space), you can find out where you app exactly failed just from the offset of the stacktrace reported by Sharepoint (with the <a href="http://blog.thekid.me.uk/archive/2007/02/15/a-solution-to-quot-an-unexpected-error-has-occurred-quot-in-wss-v3.aspx">CustomError=&#8221;Off&#8221; and StackTrace=&#8221;true&#8221;</a> in the web.config). Some people explain how to do it <a href="http://stackoverflow.com/questions/1037925/recreate-stack-trace-with-line-numbers-from-user-bug-report-in-net">here</a>. Answer &#8220;3&#8243; allows you to get the IL offset like ASP.Net does in its (non customized) error page.</p>
<p><strong>3. Launching the debugger from the code</strong><br />
This is very useful for features deactivation/uninstallation/installation/activation code.</p>
<p>You just have to add this line when you want to ask the debugger to attach to the assembly.</p>

<div class="wp_codebox"><table><tr id="p136126"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1361code26"><pre class="csharp" style="font-family:monospace;">Debugger<span style="color: #008000;">.</span><span style="color: #0000FF;">Launch</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p><strong>4. Other options</strong><br />
<a href="http://blog.thekid.me.uk/archive/2007/07/25/debugging-tips-for-sharepoint-and-wss-exceptions.aspx">This article</a> focuses on hardcore problems : Problems that occur inside sharepoint or weird problem that only appear on your production servers.</p>
<p>The WinDBG method seems a little bit overkill to me. Mostly because you still can&#8217;t analyze the state of the local variables with our current tools (but I hope it will be made available in a short future).</p>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/debugging-on-sharepoint-2007/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sharepoint : SPWebConfigModification</title>
		<link>http://florent.clairambault.fr/sharepoint-spwebconfigmodification?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sharepoint-spwebconfigmodification</link>
		<comments>http://florent.clairambault.fr/sharepoint-spwebconfigmodification#comments</comments>
		<pubDate>Sun, 19 Jul 2009 08:30:10 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[binding redirect]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[Sharepoint 2007]]></category>
		<category><![CDATA[SPWebConfigModification]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=1265</guid>
		<description><![CDATA[I&#8217;ve seen lots of Sharepoint software having an installation manual of at least 20 pages (sometimes 60). Most of the operations they describe could be fully automated. And these software were made by freaking big companies. They should be ashamed of themselves. Maybe they just forgot that computer science is all about saving some time [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve seen lots of Sharepoint software having an installation manual of at least 20 pages (sometimes 60). Most of the operations they describe could be fully automated. And these software were made by freaking big companies. They should be ashamed of themselves. Maybe they just forgot that computer science is all about saving some time (and not only making money).</p>
<p>One good example is MOSS Faceted search 2.5 (I haven&#8217;t tested the 3.0). It takes at least 40 minutes to uninstall this crap. Why isn&#8217;t it just ONE WSP or at least one BAT file launching the WSP installation and the other steps ? Is there any real reason for that ?</p>
<p>The SPWebConfigModification solves this web.config modification problem. It&#8217;s a pretty interesting feature of Sharepoint. You can edit the web.config file without any complex XML parsing. It doesn&#8217;t even matter that you add XML or not. The SPWebConfigModification class manages your add/mod/del operations easily. The only restriction is that you have to add your first configuration elements using the SPWebConfigModification.  You cannot modify existing elements this way.</p>

<div class="wp_codebox"><table><tr id="p126529"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
</pre></td><td class="code" id="p1265code29"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Source : http://sharethelearning.blogspot.com/2008/01/adding-bindingredirect-to-webconfig.html</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> AddBindingRedirect<span style="color: #008000;">&#40;</span> SPWebApplication webApp, <span style="color: #6666cc; font-weight: bold;">string</span> libraryName, <span style="color: #6666cc; font-weight: bold;">string</span> libraryPublicToken, <span style="color: #6666cc; font-weight: bold;">string</span> oldVersion, <span style="color: #6666cc; font-weight: bold;">string</span> newVersion <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	var ownerName <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span> <span style="color: #666666;">&quot;BindingRedirect.{0}&quot;</span>, libraryName <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008000;">&#123;</span> <span style="color: #008080; font-style: italic;">// We delete last bindingRedirect</span>
&nbsp;
		var list <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span>SPWebConfigModification<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span> SPWebConfigModification mod <span style="color: #0600FF; font-weight: bold;">in</span> webApp<span style="color: #008000;">.</span><span style="color: #0000FF;">WebConfigModifications</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			list<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span> mod <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span> var mod <span style="color: #0600FF; font-weight: bold;">in</span> list <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> mod<span style="color: #008000;">.</span><span style="color: #0000FF;">Owner</span> <span style="color: #008000;">==</span> ownerName <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
				LoggerCommon<span style="color: #008000;">.</span><span style="color: #0000FF;">LogVerbose</span><span style="color: #008000;">&#40;</span> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span> <span style="color: #666666;">&quot;Deleting: <span style="color: #008080; font-weight: bold;">\&quot;</span>{0}<span style="color: #008080; font-weight: bold;">\&quot;</span>&quot;</span>, mod<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
				webApp<span style="color: #008000;">.</span><span style="color: #0000FF;">WebConfigModifications</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Remove</span><span style="color: #008000;">&#40;</span> mod <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #008000;">&#125;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008000;">&#123;</span> <span style="color: #008080; font-style: italic;">// We add our redirection</span>
		<span style="color: #6666cc; font-weight: bold;">String</span> path <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;configuration/runtime/*[namespace-uri()='urn:schemas-microsoft-com:asm.v1' and local-name()='assemblyBinding']&quot;</span><span style="color: #008000;">;</span>
		<span style="color: #6666cc; font-weight: bold;">String</span> name <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span> <span style="color: #666666;">&quot;*[namespace-uri()='urn:schemas-microsoft-com:asm.v1' and local-name()='dependentAssembly']/*[namespace-uri()='urn:schemas-microsoft-com:asm.v1' and local-name()='assemblyIdentity'][@name='{0}']/parent::*&quot;</span>, libraryName <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #6666cc; font-weight: bold;">String</span> webConfigValue <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span> <span style="color: #666666;">@&quot;
	&lt;dependentAssembly&gt;
		&lt;!-- Added automatically at {4} --&gt;
		&lt;assemblyIdentity name='{0}' publicKeyToken='{1}' culture='neutral' /&gt;
		&lt;bindingRedirect oldVersion='{2}' newVersion='{3}' /&gt;
	&lt;/dependentAssembly&gt;
&quot;</span>, libraryName, libraryPublicToken, oldVersion, newVersion, DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		SPWebConfigModification mod <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SPWebConfigModification<span style="color: #008000;">&#40;</span> name, path <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		mod<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> webConfigValue<span style="color: #008000;">;</span>
		mod<span style="color: #008000;">.</span><span style="color: #0000FF;">Owner</span> <span style="color: #008000;">=</span> ownerName<span style="color: #008000;">;</span>
		mod<span style="color: #008000;">.</span><span style="color: #0000FF;">Sequence</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
		mod<span style="color: #008000;">.</span><span style="color: #0000FF;">Type</span> <span style="color: #008000;">=</span> SPWebConfigModification<span style="color: #008000;">.</span><span style="color: #0000FF;">SPWebConfigModificationType</span><span style="color: #008000;">.</span><span style="color: #0000FF;">EnsureChildNode</span><span style="color: #008000;">;</span>
&nbsp;
		webApp<span style="color: #008000;">.</span><span style="color: #0000FF;">WebConfigModifications</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span> mod <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008000;">&#123;</span> <span style="color: #008080; font-style: italic;">// We save our changes</span>
		webApp<span style="color: #008000;">.</span><span style="color: #0000FF;">Update</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		SPFarm<span style="color: #008000;">.</span><span style="color: #0000FF;">Local</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Services</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&lt;</span>SPWebService<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ApplyWebConfigModifications</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>If you do a binding redirect from 1.0.0.0 to 1.0.1.0 and your .webpart file references the 1.0.0.0 version, sharepoint will store your webpart as referencing the 1.0.1.0 assembly (and not 1.0.0.0 as you told him). So if you then chose to change the binding redirect from 1.0.0.0 to 1.0.2.0, without redirecting 1.0.1.0 to 1.0.2.0, your webpart will still be the 1.0.1.0 version.  </p>
<p>I haven&#8217;t tested this for event receivers, but the way they are registered (Sharepoint doesn&#8217;t check the assembly you add to the event receivers of a list), I would guess Sharepoint doesn&#8217;t change the assembly version.</p>
<p>To solve this webpart updating problem, you can use ranged binding redirect (.Net rules) :</p>

<div class="wp_codebox"><table><tr id="p126530"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p1265code30"><pre class="csharp" style="font-family:monospace;">var site <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SPSite<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;http://localhost&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
AddBindingRedirect<span style="color: #008000;">&#40;</span> site<span style="color: #008000;">.</span><span style="color: #0000FF;">WebApplication</span>, <span style="color: #666666;">&quot;MyCorp.MyApp.MyLib&quot;</span>, <span style="color: #666666;">&quot;0x123456789&quot;</span>, <span style="color: #666666;">&quot;1.0.0.0-1.0.3.5&quot;</span>, <span style="color: #666666;">&quot;1.0.3.5&quot;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>That means that any webpart using a previous version of the &#8220;MyCorp.MyApp.MyLib&#8221; assembly between 1.0.0.0 and 1.0.3.5 will be redirected to the 1.0.3.5 version.</p>
<p>If your assembly contains page code-behind classes, you should take care of updating the aspx files as well.</p>
<p><u>Reference :</u>
<ul>
<li><a href="http://sharethelearning.blogspot.com/2008/01/adding-bindingredirect-to-webconfig.html">The original code</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/sharepoint-spwebconfigmodification/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>My little Sharepoint</title>
		<link>http://florent.clairambault.fr/my-little-sharepoint?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=my-little-sharepoint</link>
		<comments>http://florent.clairambault.fr/my-little-sharepoint#comments</comments>
		<pubDate>Fri, 03 Jul 2009 22:10:12 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[MOSS 2007]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[Sharepoint 2007]]></category>
		<category><![CDATA[Windows Server 2008]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=1283</guid>
		<description><![CDATA[I recently bought a new laptop. I choose a P8600 processor to make sure to have virtualization support and a little TDP (Thermal Dissipation Power) because I don&#8217;t really like the fan noise. And it has 4GB or RAM for these little virtual hosts. So today, I decided to have a little Sharepoint 2007 of [...]]]></description>
			<content:encoded><![CDATA[<p>I recently bought a new laptop. I choose a P8600 processor to make sure to have virtualization support and a little TDP (Thermal Dissipation Power) because I don&#8217;t really like the fan noise. And it has 4GB or RAM for these little virtual hosts.</p>
<p>So today, I decided to have a little Sharepoint 2007 of my own. I installed Windows Server 2008 on a VMWare host, activated Remote Desktop, added Sharepoint 2007 and then MOSS 2007. I choose the x86 version of WS2008 because I wanted to limit RAM usage. With only 1GB of RAM, it worked like a charm and it is really fast.</p>
<p>Installing MOSS 2007 wasn&#8217;t as simple as you could expect. I had to &#8220;patch&#8221; the MOSS 2007 install CD with the MOSS 2007 SP1, <a href="http://mindsharpblogs.com/ben/archive/2007/12/16/3837.aspx">following this post</a>. You don&#8217;t have to follow exactly what it says. You can just take the content of the x86 (or x64 if you have a x64 arch) directory, put it somewhere (like C:\mossinstall) and then do the upgrade with the SP1 by typing &#8220;officeserver2007sp1-kb936984-x86-fullfile-en-us.exe /extract:c:\mossinstall\updates&#8221;.</p>
<p>By the way, you don&#8217;t need to do the same thing with WSS as you can find an already updated version of WSS 3.0, compatible with Windows Server 2008. I guess you could also find (or more likely buy) an updated version of MOSS 2007, but I didn&#8217;t.</p>
<p>I&#8217;ve developped a little bit on sharepoint but I never installed one. What is pretty astonishing from my point of view is that the installer setups the SSE SQL Server, the IIS + ASP.Net server and then configure everything automatically. It is as easy to install as any software.</p>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/my-little-sharepoint/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SPGridView : Filtering</title>
		<link>http://florent.clairambault.fr/spgridview-filtering?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=spgridview-filtering</link>
		<comments>http://florent.clairambault.fr/spgridview-filtering#comments</comments>
		<pubDate>Sun, 21 Jun 2009 18:50:31 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[MOSS]]></category>
		<category><![CDATA[MOSS 2007]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[Sharepoint 2007]]></category>
		<category><![CDATA[SPGridView]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=1175</guid>
		<description><![CDATA[I wanted to use a little SPGridView in a software and had a little problem. First of all, in order to use filtering on a SPGridView, you have to give an ObjectDataSource by it&#8217;s control&#8217;s ID. For anything else, you can use the DataSource property directly. The best sample code I could fin on the [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to use a little SPGridView in a software and had a little problem. First of all, in order to use filtering on a SPGridView, you have to give an ObjectDataSource by it&#8217;s control&#8217;s ID. For anything else, you can use the DataSource property directly.</p>
<p>The best sample code I could fin on the net was this one : <a href="http://www.reversealchemy.net/2009/05/01/building-a-spgridview-control-part-1-introducing-the-spgridview/">Creating the SPGridView with sorting</a> and <a href="http://www.reversealchemy.net/2009/05/24/building-a-spgridview-control-part-2-filtering/">adding filtering</a>. </p>
<p>This example is great because it only shows the basic requirements to setup a SPGridView and it gives you a clean way to build the ObjectDataSource and it explains step by step why you have to do things this way (in Sharepoint, it&#8217;s very important).</p>
<p>The problem, and this is the subject of this post, came when I activated the filtering functionnality. The menu displayed and then got stuck on &#8220;Loading&#8230;&#8221; with an alert message saying it got a NullReferenceException. Here is the pic :<br />
<a href="http://i.mivi.fr/a0bd84f3b7f879c8374940076820b16f1ed23429.png" target="_blank"><img src="http://i.mivi.fr/a0bd84f3b7f879c8374940076820b16f1ed23429.x.500.png" /></a></p>
<p>I finally found the origin of my problem. In my first version, I was giving the DataSource to my SPGridView on the &#8220;PreRender&#8221; loading step. For the AJAX call, you never reach this step, you have to give the DataSource sooner. </p>
<p>Once I got that right, I just cached the last DataSource in the ViewState to give in the CreateChildControls method and it worked. The menu was finally displaying fine.</p>
<p>It can&#8217;t exactly give you my code (because it&#8217;s not legally mine), but here is the basic Idea :</p>
<p>In the real world usage, you will give your DataTable to a property so that it can be displayed later by your SPGridView. So you can basically just copy/paste the ASPGridView class given by Erik Burger and just replace the &#8220;SelectData&#8221; method by this one :</p>

<div class="wp_codebox"><table><tr id="p117532"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p1175code32"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> DataTable SelectData <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> DataTable<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> DataTable DataTable <span style="color: #008000;">&#123;</span>
    get <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> ViewState<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;DataTable&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> DataTable<span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    set <span style="color: #008000;">&#123;</span>
        ViewState<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;DataTable&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>And anywhere in your WebPart&#8217;s OnPreRender method, or in any button&#8217;s event receiver method, you could build your DataSource.</p>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/spgridview-filtering/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>MOSS 2007 : Managing search properties</title>
		<link>http://florent.clairambault.fr/moss-2007-managing-search-properties?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=moss-2007-managing-search-properties</link>
		<comments>http://florent.clairambault.fr/moss-2007-managing-search-properties#comments</comments>
		<pubDate>Sat, 13 Jun 2009 18:08:53 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[MOSS 2007]]></category>
		<category><![CDATA[MOSS Search]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[Sharepoint 2007]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=907</guid>
		<description><![CDATA[In Microsoft Office Sharepoint Server, you have a powerful search service. It can&#8217;t say I like everything in sharepoint but the MOSS Search Engine is really amazing. It enables to search fulltext on everything and also to filter precisely your results by searching on columns at the same time. But the MOSS search engine isn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>In Microsoft Office Sharepoint Server, you have a powerful search service. It can&#8217;t say I like everything in sharepoint but the MOSS Search Engine is really amazing. It enables to search fulltext on everything and also to filter precisely your results by searching on columns at the same time.</p>
<p>But the MOSS search engine isn&#8217;t as easy as searching directly in CAML. You have to prepare managed properties (from your lists columns) to be able to search on them.</p>
<p>All the code below is just a simplified, more understandable code for what you need to build to suit your needs. This code will need some rework to be used.</p>
<p><strong>How to map columns to managed properties</strong></p>
<p>So, to deploy a (WSP) solution which maps the right columns, you need to :</p>
<ul>
<li>(0. Have a SSP for your site collection)</li>
<li>1. Create the list programaticaly</li>
<li>2. Add the site collection to the content sources</li>
<li>3. Put some data in the list (you have to fill every column with some rubish data)</li>
<li>4. Start a crawl and wait for it (you need to loop on the CrawlStatus of ContentSource object)</li>
<li>5. Create all the mapped columns from the cawled columns in the &#8220;Sharepoint&#8221; category (not really hard). The best way to do that is to use the fields of your list. So that when you will change some fields in your list, you won&#8217;t have to update your column mapping code.</li>
</ul>
<p>If you still haven&#8217;t undertand it, the way data are organized in MOSS search engine is. data (field &#8220;Data&#8221; for instance) &#8211;> crawled property (&#8220;ows_Data&#8221;) &#8211;> managed property( &#8220;owsData&#8221;, &#8220;Data&#8221; or any name you want). This is done like this because you might want to map multiple crawled properties with one managed property.</p>
<p><strong>Step 1</strong> is really easy. If you don&#8217;t know how to do that, you should stop right here.</p>
<p><strong>Step 2</strong> : Creating a Content Site programaticaly and adding a 15 minutes schedule to it :</p>

<div class="wp_codebox"><table><tr id="p90742"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code" id="p907code42"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// With a given web SPWeb...</span>
var site <span style="color: #008000;">=</span> web<span style="color: #008000;">.</span><span style="color: #0000FF;">Site</span><span style="color: #008000;">;</span>
var sspSchema <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Schema<span style="color: #008000;">&#40;</span> SearchContext<span style="color: #008000;">.</span><span style="color: #0000FF;">GetContext</span><span style="color: #008000;">&#40;</span> site <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
var sspContent <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Content<span style="color: #008000;">&#40;</span> SearchContext<span style="color: #008000;">.</span><span style="color: #0000FF;">GetContext</span><span style="color: #008000;">&#40;</span> site <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// We choose an &quot;unique&quot; name for this content source, we wouldn't want to add it twice</span>
var name <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span> <span style="color: #666666;">&quot;Web - {0}&quot;</span>, web<span style="color: #008000;">.</span><span style="color: #0000FF;">Url</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008000;">&#123;</span> <span style="color: #008080; font-style: italic;">// We check if content site doesn't exist yet</span>
	<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span> ContentSource cs <span style="color: #0600FF; font-weight: bold;">in</span> sspContent<span style="color: #008000;">.</span><span style="color: #0000FF;">ContentSources</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> cs<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span> <span style="color: #008000;">==</span> name <span style="color: #008000;">&#41;</span>
			<span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008000;">&#123;</span> <span style="color: #008080; font-style: italic;">// We add the content site</span>
	var cs <span style="color: #008000;">=</span> sspContent<span style="color: #008000;">.</span><span style="color: #0000FF;">ContentSources</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span>
		<a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span> SharePointContentSource <span style="color: #008000;">&#41;</span>,
		name
	<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	cs<span style="color: #008000;">.</span><span style="color: #0000FF;">StartAddresses</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Uri<span style="color: #008000;">&#40;</span> web<span style="color: #008000;">.</span><span style="color: #0000FF;">Url</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	var schedule <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> DailySchedule<span style="color: #008000;">&#40;</span> SearchContext<span style="color: #008000;">.</span><span style="color: #0000FF;">GetContext</span><span style="color: #008000;">&#40;</span> site <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		RepeatDuration <span style="color: #008000;">=</span> <span style="color: #FF0000;">1440</span>,
		RepeatInterval <span style="color: #008000;">=</span> <span style="color: #FF0000;">15</span>,
		StartHour <span style="color: #008000;">=</span> <span style="color: #FF0000;">8</span>,
		StartMinute <span style="color: #008000;">=</span> 00
	<span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
	cs<span style="color: #008000;">.</span><span style="color: #0000FF;">IncrementalCrawlSchedule</span> <span style="color: #008000;">=</span> schedule<span style="color: #008000;">;</span>
	cs<span style="color: #008000;">.</span><span style="color: #0000FF;">Update</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p><strong>Step 3</strong> is pretty easy too. I don&#8217;t have to show you anything. The only difficulty you might have is that for document libraries, inserting data is done differently. Here is how you can manage it :</p>

<div class="wp_codebox"><table><tr id="p90743"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code" id="p907code43"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// for a given list SPList </span>
&nbsp;
var rand <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Random<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
SPListItem item<span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// If it's a document library</span>
<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> list<span style="color: #008000;">.</span><span style="color: #0000FF;">BaseTemplate</span> <span style="color: #008000;">==</span> SPListTemplateType<span style="color: #008000;">.</span><span style="color: #0000FF;">DocumentLibrary</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	var fileUrl <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span> <span style="color: #666666;">&quot;{0}/Data_{1}.txt&quot;</span>, list<span style="color: #008000;">.</span><span style="color: #0000FF;">RootFolder</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span>, rand<span style="color: #008000;">.</span><span style="color: #0000FF;">Next</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	var content <span style="color: #008000;">=</span>  UTF8Encoding<span style="color: #008000;">.</span><span style="color: #0000FF;">UTF8</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetBytes</span><span style="color: #008000;">&#40;</span> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span> <span style="color: #666666;">&quot;Random data file ! {0}&quot;</span>, rand<span style="color: #008000;">.</span><span style="color: #0000FF;">Next</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// New &quot;items&quot; are inserted by adding new files</span>
	var file <span style="color: #008000;">=</span> web<span style="color: #008000;">.</span><span style="color: #0000FF;">Files</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span> fileUrl, content <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	file<span style="color: #008000;">.</span><span style="color: #0000FF;">Update</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	item <span style="color: #008000;">=</span> file<span style="color: #008000;">.</span><span style="color: #0000FF;">Item</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008000;">&#123;</span>
	item <span style="color: #008000;">=</span> list<span style="color: #008000;">.</span><span style="color: #0000FF;">Items</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// from here, the item SPListItem can be handled the same way between these two lists</span></pre></td></tr></table></div>

<p><strong>Step 4</strong>, to start a crawl on every content source and wait for it :</p>

<div class="wp_codebox"><table><tr id="p90744"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code" id="p907code44"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// For a defined site SPSite...</span>
var sspContent <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Content<span style="color: #008000;">&#40;</span> SearchContext<span style="color: #008000;">.</span><span style="color: #0000FF;">GetContext</span><span style="color: #008000;">&#40;</span> site <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span> ContentSource cs <span style="color: #0600FF; font-weight: bold;">in</span> sspContent<span style="color: #008000;">.</span><span style="color: #0000FF;">ContentSources</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// Not doing this may be considered as altering the enumeration (and throws an Exception)</span>
	ContentSource cs2 <span style="color: #008000;">=</span> cs<span style="color: #008000;">;</span>
	cs2<span style="color: #008000;">.</span><span style="color: #0000FF;">StartIncrementalCrawl</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008000;">&#123;</span> <span style="color: #008080; font-style: italic;">// We wait until it ends</span>
	Boolean indexFinished<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span> <span style="color: #0600FF; font-weight: bold;">true</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		indexFinished <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// We check if each content-source is still crawling something</span>
		<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span> ContentSource cs <span style="color: #0600FF; font-weight: bold;">in</span> sspContent<span style="color: #008000;">.</span><span style="color: #0000FF;">ContentSources</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>
				cs<span style="color: #008000;">.</span><span style="color: #0000FF;">CrawlStatus</span> <span style="color: #008000;">==</span> CrawlStatus<span style="color: #008000;">.</span><span style="color: #0000FF;">CrawlingFull</span> <span style="color: #008000;">||</span>
				cs<span style="color: #008000;">.</span><span style="color: #0000FF;">CrawlStatus</span> <span style="color: #008000;">==</span> CrawlStatus<span style="color: #008000;">.</span><span style="color: #0000FF;">CrawlingIncremental</span> <span style="color: #008000;">&#41;</span>
				indexFinished <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> indexFinished <span style="color: #008000;">&#41;</span>
			<span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008000;">&#123;</span>
			Thread<span style="color: #008000;">.</span><span style="color: #0000FF;">Sleep</span><span style="color: #008000;">&#40;</span> <span style="color: #FF0000;">1000</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>You might wonder why we way for the crawl to end. The reason is you can&#8217;t use crawled properties before they have been created by detecting new columns in the list. This is the only way you can do this step by step.</p>
<p><strong>And Step 5</strong> : Make sure that every column of the list has its mapped property. Well, this is why might prefer to do some automatic mapping.<br />
Here, to make things easier, we will say that we want to make managed property to be named like &#8220;owsInternalName&#8221;. You will see why later.</p>

<div class="wp_codebox"><table><tr id="p90745"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
</pre></td><td class="code" id="p907code45"><pre class="csharp" style="font-family:monospace;">Category sharepoint <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// We take the &quot;SharePoint&quot; category</span>
<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span> Category cat <span style="color: #0600FF; font-weight: bold;">in</span> _sspSchema<span style="color: #008000;">.</span><span style="color: #0000FF;">AllCategories</span> <span style="color: #008000;">&#41;</span>
	<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> cat<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;SharePoint&quot;</span> <span style="color: #008000;">&#41;</span>
		sharepoint <span style="color: #008000;">=</span> cat<span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// We only select fields that are in the defaultView </span>
<span style="color: #008080; font-style: italic;">// (you might want to change this behaviour)</span>
var fields <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span>SPField<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span> <span style="color: #6666cc; font-weight: bold;">String</span> fieldName <span style="color: #0600FF; font-weight: bold;">in</span> list<span style="color: #008000;">.</span><span style="color: #0000FF;">DefaultView</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ViewFields</span> <span style="color: #008000;">&#41;</span>
	fields<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span> list<span style="color: #008000;">.</span><span style="color: #0000FF;">Fields</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetFieldByInternalName</span><span style="color: #008000;">&#40;</span> fieldName <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
&nbsp;
<span style="color: #008080; font-style: italic;">// for every one of these fields...</span>
<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span> SPField field <span style="color: #0600FF; font-weight: bold;">in</span> fields <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
&nbsp;
	var owsNameUnderscore <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span> <span style="color: #666666;">&quot;ows_{0}&quot;</span>, field<span style="color: #008000;">.</span><span style="color: #0000FF;">InternalName</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	var owsName <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span> <span style="color: #666666;">&quot;ows{0}&quot;</span>, field<span style="color: #008000;">.</span><span style="color: #0000FF;">InternalName</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	CrawledProperty cp<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// We check if the crawled property exists</span>
	<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#40;</span> cp <span style="color: #008000;">=</span> CrawledPropertyExists<span style="color: #008000;">&#40;</span> sharepoint<span style="color: #008000;">.</span><span style="color: #0000FF;">GetAllCrawledProperties</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, owsNameUnderscore <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// We then try to get the linked managed property</span>
		ManagedProperty mp <span style="color: #008000;">=</span> ManagedPropertyExists<span style="color: #008000;">&#40;</span> cp<span style="color: #008000;">.</span><span style="color: #0000FF;">GetMappedManagedProperties</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, owsName <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// If it doesn't exist</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> mp <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
&nbsp;
			<span style="color: #008080; font-style: italic;">// We create this mapped property</span>
			<span style="color: #0600FF; font-weight: bold;">try</span> <span style="color: #008000;">&#123;</span>
				mp <span style="color: #008000;">=</span> _sspSchema<span style="color: #008000;">.</span><span style="color: #0000FF;">AllManagedProperties</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span> name, CrawledPropertyTypeToManagedPropertyType<span style="color: #008000;">&#40;</span> cp <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #008000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span> SqlException <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
				<span style="color: #008080; font-style: italic;">// If the mapped property already exists</span>
				<span style="color: #008080; font-style: italic;">// it means that it isn't mapped with our crawled property, so we get it from the </span>
				<span style="color: #008080; font-style: italic;">// global Managed property store</span>
				mp <span style="color: #008000;">=</span> ManagedPropertyExists<span style="color: #008000;">&#40;</span> _sspSchema<span style="color: #008000;">.</span><span style="color: #0000FF;">AllManagedProperties</span>, owsName <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #008000;">&#125;</span>
&nbsp;
			<span style="color: #008080; font-style: italic;">// And we finally map it with the crawled property</span>
			var mappingColl <span style="color: #008000;">=</span> mp<span style="color: #008000;">.</span><span style="color: #0000FF;">GetMappings</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			mappingColl<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>
				<a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Mapping<span style="color: #008000;">&#40;</span>
					cp<span style="color: #008000;">.</span><span style="color: #0000FF;">Propset</span>,
					cp<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span>,
					cp<span style="color: #008000;">.</span><span style="color: #0000FF;">VariantType</span>,
					mp<span style="color: #008000;">.</span><span style="color: #0000FF;">PID</span>
				<span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			mp<span style="color: #008000;">.</span><span style="color: #0000FF;">SetMappings</span><span style="color: #008000;">&#40;</span> mappingColl <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			mp<span style="color: #008000;">.</span><span style="color: #0000FF;">Update</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #008080; font-style: italic;">// Crawled property doesn't exist. You have to put some data in it or crawl it.</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>To make this code work, you must have the following methods in your code.</p>

<div class="wp_codebox"><table><tr id="p90746"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
</pre></td><td class="code" id="p907code46"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> ManagedDataType CrawledPropertyTypeToManagedPropertyType<span style="color: #008000;">&#40;</span> CrawledProperty cp <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">switch</span> <span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#40;</span>VariantType<span style="color: #008000;">&#41;</span> cp<span style="color: #008000;">.</span><span style="color: #0000FF;">VariantType</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">case</span> VariantType<span style="color: #008000;">.</span><span style="color: #0000FF;">Array</span><span style="color: #008000;">:</span>
		<span style="color: #0600FF; font-weight: bold;">case</span> VariantType<span style="color: #008000;">.</span><span style="color: #0000FF;">UserDefinedType</span><span style="color: #008000;">:</span>
		<span style="color: #0600FF; font-weight: bold;">case</span> VariantType<span style="color: #008000;">.</span><span style="color: #6666cc; font-weight: bold;">Object</span><span style="color: #008000;">:</span>
		<span style="color: #0600FF; font-weight: bold;">case</span> VariantType<span style="color: #008000;">.</span><span style="color: #0000FF;">Error</span><span style="color: #008000;">:</span>
		<span style="color: #0600FF; font-weight: bold;">case</span> VariantType<span style="color: #008000;">.</span><span style="color: #0000FF;">Variant</span><span style="color: #008000;">:</span>
		<span style="color: #0600FF; font-weight: bold;">case</span> VariantType<span style="color: #008000;">.</span><span style="color: #0000FF;">DataObject</span><span style="color: #008000;">:</span>
		<span style="color: #0600FF; font-weight: bold;">case</span> VariantType<span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">:</span>
		<span style="color: #0600FF; font-weight: bold;">case</span> VariantType<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Null</span><span style="color: #008000;">:</span>
		<span style="color: #0600FF; font-weight: bold;">case</span> VariantType<span style="color: #008000;">.</span><span style="color: #0000FF;">Currency</span><span style="color: #008000;">:</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> ManagedDataType<span style="color: #008000;">.</span><span style="color: #0000FF;">Unsupported</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">case</span> VariantType<span style="color: #008000;">.</span><span style="color: #0000FF;">Single</span><span style="color: #008000;">:</span>
		<span style="color: #0600FF; font-weight: bold;">case</span> VariantType<span style="color: #008000;">.</span><span style="color: #6666cc; font-weight: bold;">Double</span><span style="color: #008000;">:</span>
		<span style="color: #0600FF; font-weight: bold;">case</span> VariantType<span style="color: #008000;">.</span><span style="color: #6666cc; font-weight: bold;">Decimal</span><span style="color: #008000;">:</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> ManagedDataType<span style="color: #008000;">.</span><span style="color: #6666cc; font-weight: bold;">Decimal</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">case</span> VariantType<span style="color: #008000;">.</span><span style="color: #0000FF;">Boolean</span><span style="color: #008000;">:</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> ManagedDataType<span style="color: #008000;">.</span><span style="color: #0000FF;">YesNo</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">case</span> VariantType<span style="color: #008000;">.</span><span style="color: #6666cc; font-weight: bold;">Byte</span><span style="color: #008000;">:</span>
		<span style="color: #0600FF; font-weight: bold;">case</span> VariantType<span style="color: #008000;">.</span><span style="color: #6666cc; font-weight: bold;">Long</span><span style="color: #008000;">:</span>
		<span style="color: #0600FF; font-weight: bold;">case</span> VariantType<span style="color: #008000;">.</span><span style="color: #6666cc; font-weight: bold;">Short</span><span style="color: #008000;">:</span>
		<span style="color: #0600FF; font-weight: bold;">case</span> VariantType<span style="color: #008000;">.</span><span style="color: #0000FF;">Integer</span><span style="color: #008000;">:</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> ManagedDataType<span style="color: #008000;">.</span><span style="color: #0000FF;">Integer</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">case</span> VariantType<span style="color: #008000;">.</span><span style="color: #6666cc; font-weight: bold;">Char</span><span style="color: #008000;">:</span>
		<span style="color: #0600FF; font-weight: bold;">case</span> VariantType<span style="color: #008000;">.</span><span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">:</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> ManagedDataType<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">case</span> VariantType<span style="color: #008000;">.</span><span style="color: #0000FF;">Date</span><span style="color: #008000;">:</span>
		<span style="color: #0600FF; font-weight: bold;">case</span> VariantType<span style="color: #008000;">.</span><span style="color: #0000FF;">Date2</span><span style="color: #008000;">:</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> ManagedDataType<span style="color: #008000;">.</span><span style="color: #0000FF;">DateTime</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">default</span><span style="color: #008000;">:</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> ManagedDataType<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">enum</span> VariantType <span style="color: #008000;">&#123;</span>
	Empty <span style="color: #008000;">=</span> 0x0000,
	<span style="color: #0600FF; font-weight: bold;">Null</span> <span style="color: #008000;">=</span> 0x0001,
	<span style="color: #6666cc; font-weight: bold;">Short</span> <span style="color: #008000;">=</span> 0x0002,
	Integer <span style="color: #008000;">=</span> 0x0003,
	Single <span style="color: #008000;">=</span> 0x0004,
	<span style="color: #6666cc; font-weight: bold;">Double</span> <span style="color: #008000;">=</span> 0x0005,
	Currency <span style="color: #008000;">=</span> 0x0006,
	Date <span style="color: #008000;">=</span> 0x0007,
	Date2 <span style="color: #008000;">=</span> 0x0040,
	<span style="color: #6666cc; font-weight: bold;">String</span> <span style="color: #008000;">=</span> 0x0008,
	<span style="color: #6666cc; font-weight: bold;">Object</span> <span style="color: #008000;">=</span> 0x0009,
	Error <span style="color: #008000;">=</span> 0x000A,
	Boolean <span style="color: #008000;">=</span> 0x000B,
	Variant <span style="color: #008000;">=</span> 0x000C,
	DataObject <span style="color: #008000;">=</span> 0x000D,
	<span style="color: #6666cc; font-weight: bold;">Decimal</span> <span style="color: #008000;">=</span> 0x000E,
	<span style="color: #6666cc; font-weight: bold;">Byte</span> <span style="color: #008000;">=</span> 0x0011,
	<span style="color: #6666cc; font-weight: bold;">Char</span> <span style="color: #008000;">=</span> 0x0012,
	<span style="color: #6666cc; font-weight: bold;">Long</span> <span style="color: #008000;">=</span> 0x0014,
	UserDefinedType <span style="color: #008000;">=</span> 0x0024,
	Array <span style="color: #008000;">=</span> 0x2000
<span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> CrawledProperty CrawledPropertyExists<span style="color: #008000;">&#40;</span> IEnumerable enu, <span style="color: #6666cc; font-weight: bold;">String</span> name <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span> CrawledProperty cp <span style="color: #0600FF; font-weight: bold;">in</span> enu <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> cp<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span> <span style="color: #008000;">==</span> name <span style="color: #008000;">&#41;</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> cp<span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> ManagedProperty ManagedPropertyExists<span style="color: #008000;">&#40;</span> ManagedPropertyCollection coll, <span style="color: #6666cc; font-weight: bold;">String</span> name <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span> ManagedProperty mp <span style="color: #0600FF; font-weight: bold;">in</span> coll <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> mp<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span> <span style="color: #008000;">==</span> name <span style="color: #008000;">&#41;</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> mp<span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> ManagedProperty ManagedPropertyExists<span style="color: #008000;">&#40;</span> IEnumerable enu, <span style="color: #6666cc; font-weight: bold;">String</span> name <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span> ManagedProperty mp <span style="color: #0600FF; font-weight: bold;">in</span> enu <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> mp<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span> <span style="color: #008000;">==</span> name <span style="color: #008000;">&#41;</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> mp<span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p><strong> Automatically added columns</strong></p>
<p>There also is an other way around, and this is the subject of this post : You can tell the &#8220;Sharepoint&#8221; category in the crawled columns to automatically map new crawled columns with mapped columns. You just have to enable this option in the Sharepoint UI for the &#8220;Sharepoint&#8221; Category or to do this programaticaly like that :</p>

<div class="wp_codebox"><table><tr id="p90747"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p907code47"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// For a defined site SPSite...</span>
var sspSchema <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Schema<span style="color: #008000;">&#40;</span> SearchContext<span style="color: #008000;">.</span><span style="color: #0000FF;">GetContext</span><span style="color: #008000;">&#40;</span> site <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span> Category cat <span style="color: #0600FF; font-weight: bold;">in</span> sspSchema<span style="color: #008000;">.</span><span style="color: #0000FF;">AllCategories</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> cat<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;SharePoint&quot;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		cat<span style="color: #008000;">.</span><span style="color: #0000FF;">AutoCreateNewManagedProperties</span> <span style="color: #008000;">=</span> autoCreate<span style="color: #008000;">;</span>
		cat<span style="color: #008000;">.</span><span style="color: #0000FF;">MapToContents</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
		cat<span style="color: #008000;">.</span><span style="color: #0000FF;">DiscoverNewProperties</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
		cat<span style="color: #008000;">.</span><span style="color: #0000FF;">Update</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>You should only apply it to the &#8220;Sharepoint&#8221; category because other categories will add new crawled properties and then not require them anymore. That would add some trashy crawled (and managed) properties that you should clean later.</p>
<p>These new crawled columns are indexed by their internal name (&#8220;ows_ReleaseDate&#8221; for instance) and the mapped property will have a similar name (&#8220;owsReleaseDate&#8221;).</p>
<p>By the way, you don&#8217;t have to wait for the crawl to end within your solution deployment. Because, new columns will be automatically created. But you should still do it, just in case&#8230;</p>
<p>The thing is, it only applies to new crawled columns. For these already crawled columns, you will have no other choice but to map them to managed columns your self (step 5).</p>
<p><strong>Delete crawled properties</strong></p>
<p>You might want to delete useless mapped properties to clean your site collection or to allow future new crawled properties with the same name to be automatically mapped. To do this you need to :</p>
<ul>
<li>Make sure they are not mapped</li>
<li>Disable their mapping with the data, managed by the checkbox &#8220;contains indexed values of the columns&#8221; in the Sharepoint UI</li>
<li>Delete all unmapped data (by code or UI) in the &#8220;Sharepoint&#8221; category option</li>
</ul>
<p>Programaticaly, it looks like that :</p>

<div class="wp_codebox"><table><tr id="p90748"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code" id="p907code48"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// For a defined site SPSite...</span>
var sspSchema <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Schema<span style="color: #008000;">&#40;</span> SearchContext<span style="color: #008000;">.</span><span style="color: #0000FF;">GetContext</span><span style="color: #008000;">&#40;</span> site <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span> Category cat <span style="color: #0600FF; font-weight: bold;">in</span> sspSchema<span style="color: #008000;">.</span><span style="color: #0000FF;">AllCategories</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// We don't need to mess with any other category. </span>
	<span style="color: #008080; font-style: italic;">// Doing this wiht the whole &quot;SharePoint category is brutal enough...</span>
	<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> cat<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span> <span style="color: #008000;">!=</span> <span style="color: #666666;">&quot;SharePoint&quot;</span><span style="color: #008000;">&#41;</span>
		<span style="color: #0600FF; font-weight: bold;">continue</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span> CrawledProperty pr <span style="color: #0600FF; font-weight: bold;">in</span> cat<span style="color: #008000;">.</span><span style="color: #0000FF;">GetAllCrawledProperties</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// We look if there's some data indexed by the crawled property</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> <span style="color: #008000;">!</span> pr<span style="color: #008000;">.</span><span style="color: #0000FF;">GetSamples</span><span style="color: #008000;">&#40;</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MoveNext</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">// This is necessary to be able to delete this unmapped property</span>
			pr<span style="color: #008000;">.</span><span style="color: #0000FF;">IsMappedToContents</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
			pr<span style="color: #008000;">.</span><span style="color: #0000FF;">Update</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// Let's do it !</span>
	cat<span style="color: #008000;">.</span><span style="color: #0000FF;">DeleteUnmappedProperties</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	cat<span style="color: #008000;">.</span><span style="color: #0000FF;">Update</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p><strong>Search database reset</strong></p>
<p>If your crawled properties have been deleted, they won&#8217;t come back when you add a list with the same columns. What you need to do is reset the search database and launch a crawl on it :</p>

<div class="wp_codebox"><table><tr id="p90749"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p907code49"><pre class="csharp" style="font-family:monospace;">var sspContent <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Content<span style="color: #008000;">&#40;</span> SearchContext<span style="color: #008000;">.</span><span style="color: #0000FF;">GetContext</span><span style="color: #008000;">&#40;</span> site <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
sspContent<span style="color: #008000;">.</span><span style="color: #0000FF;">SearchDatabaseCleanup</span><span style="color: #008000;">&#40;</span> <span style="color: #0600FF; font-weight: bold;">false</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p><strong>The scope problem</strong></p>
<p>If you want to use your managed property in a scope, you have to enable it :</p>

<div class="wp_codebox"><table><tr id="p90750"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p907code50"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// For a defined site SPSite...</span>
var sspSchema <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Schema<span style="color: #008000;">&#40;</span> SearchContext<span style="color: #008000;">.</span><span style="color: #0000FF;">GetContext</span><span style="color: #008000;">&#40;</span> site <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
var sspContent <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Content<span style="color: #008000;">&#40;</span> SearchContext<span style="color: #008000;">.</span><span style="color: #0000FF;">GetContext</span><span style="color: #008000;">&#40;</span> site <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">foreach</span><span style="color: #008000;">&#40;</span> ManagedProperty mp <span style="color: #0600FF; font-weight: bold;">in</span> sspSchema<span style="color: #008000;">.</span><span style="color: #0000FF;">getAllManagedProperties</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> <span style="color: #008000;">!</span> mp<span style="color: #008000;">.</span><span style="color: #0000FF;">EnabledForScoping</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		mp<span style="color: #008000;">.</span><span style="color: #0000FF;">EnabledForScoping</span>  <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
		mp<span style="color: #008000;">.</span><span style="color: #0000FF;">Update</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Note on crawl : I think you should always do some incremental crawl instead of full crawl, it&#8217;s really fast (it can take less than 20 seconds) and does all the work. If your search database has been reset or if you added a new content source, sharepoint will do a full crawl when you ask an incremental crawl.</p>
<p>Note 2 on crawl : Crawl isn&#8217;t indexing data when new items are added, but you can make it do it. You just have to create an event receiver which will start the crawl when the ItemAdded / ItemUpdated event is triggered.<br />
If you have frequent list updates, you might have modifications while MOSS is performing a crawl. In that case, you have to create an asynchronous mechanism to enable &#8220;recrawling&#8221; just after the crawl has finished (in a threaded object in the ASP.Net Application object store for instance).</p>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/moss-2007-managing-search-properties/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sharepoint : The 0&#215;80020009 (DISP_E_EXCEPTION) error</title>
		<link>http://florent.clairambault.fr/sharepoint-the-0x80020009-disp_e_exception-error?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sharepoint-the-0x80020009-disp_e_exception-error</link>
		<comments>http://florent.clairambault.fr/sharepoint-the-0x80020009-disp_e_exception-error#comments</comments>
		<pubDate>Wed, 03 Jun 2009 20:20:52 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[C# .Net]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[Sharepoint 2007]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=895</guid>
		<description><![CDATA[If you&#8217;re faced with that error, you should know that it doesn&#8217;t mean anything except you have a problem. Lots of people have written posts about it, but most of their explanations are wrong. It just means that sharepoint didn&#8217;t like what you did somewhere in your masterpage, your page, your webpart, your user control [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re faced with that error, you should know that it doesn&#8217;t mean anything except you have a problem. Lots of people have written posts about it, but most of their explanations are wrong. It just means that sharepoint didn&#8217;t like what you did somewhere in your masterpage, your page, your webpart, your user control or anything else.</p>
<p>For me, it was because I used the <a href="http://msdn.microsoft.com/fr-fr/library/microsoft.sharepoint.spweb.getlistfromurl.aspx">SPWeb.GetListFromUrl</a> method to test if the user actually had access to a list. If it didn&#8217;t, I was just catching the exception thrown.</p>
<p>The problem is, sharepoint never behaves like it should. As soon as Sharepoint has thrown the Exception, I couldn&#8217;t save any parameters of the webpart.</p>
<p>By the way, I corrected my webpart by checking available lists in the <a href="http://msdn.microsoft.com/fr-fr/library/microsoft.sharepoint.spweb.lists.aspx">SPWeb.Lists</a> property.</p>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/sharepoint-the-0x80020009-disp_e_exception-error/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 1/43 queries in 0.018 seconds using disk: basic
Object Caching 1578/1674 objects using disk: basic

Served from: florent.clairambault.fr @ 2012-02-08 12:36:41 -->
