<?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; MOSS 2007</title>
	<atom:link href="http://florent.clairambault.fr/tag/moss-2007/feed" rel="self" type="application/rss+xml" />
	<link>http://florent.clairambault.fr</link>
	<description></description>
	<lastBuildDate>Wed, 28 Jul 2010 20:31:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1-alpha</generator>
		<item>
		<title>My little Sharepoint</title>
		<link>http://florent.clairambault.fr/my-little-sharepoint?utm_source=rss&amp;utm_medium=rss&amp;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&amp;utm_medium=rss&amp;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="p11752"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p1175code2"><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&amp;utm_medium=rss&amp;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="p90712"><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="p907code12"><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="p90713"><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="p907code13"><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="p90714"><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="p907code14"><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="p90715"><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="p907code15"><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="p90716"><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="p907code16"><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="p90717"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p907code17"><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="p90718"><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="p907code18"><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="p90719"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p907code19"><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="p90720"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p907code20"><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>
	</channel>
</rss>

<!-- Dynamic page generated in 0.330 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-07-29 16:36:27 -->
