<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>SharePoint Weekly</title>
	
	<link>http://sharepoint-weekly.com</link>
	<description>Weekly SharePoint development articles</description>
	<lastBuildDate>Mon, 15 Mar 2010 00:24:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<meta xmlns="http://www.w3.org/1999/xhtml" name="robots" content="noindex,follow" />
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/SharepointWeekly" /><feedburner:info uri="sharepointweekly" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Dissecting SharePoint content approval</title>
		<link>http://feedproxy.google.com/~r/SharepointWeekly/~3/ZZEnLbAJfMg/</link>
		<comments>http://sharepoint-weekly.com/2010/02/dissecting-sharepoint-content-approval/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 22:58:52 +0000</pubDate>
		<dc:creator>Gunnar</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Queries]]></category>
		<category><![CDATA[CAML]]></category>
		<category><![CDATA[Lists]]></category>
		<category><![CDATA[Moderation]]></category>

		<guid isPermaLink="false">http://sharepoint-weekly.com/?p=105</guid>
		<description><![CDATA[SharePoint lists support content approval. On code level it is called moderation. Querying lists by approval or moderation status needs some explanations. Due to some very bad design decisions there are some dirty tricks that one must use when querying lists by approval status. This posting shows safe way how to query lists by approval [...]


Related posts:<ol><li><a href='http://sharepoint-weekly.com/2009/09/querying-sharepoint-lists/' rel='bookmark' title='Permanent Link: Querying SharePoint lists'>Querying SharePoint lists</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img src="http://dev.sharepoint-weekly.com/wp-content/themes/inove/img/development.jpg" alt="Development topic" title="Development" style="margin-right:10px;margin-top:3px;margin-bottom:10px" align="left" />SharePoint lists support content approval. On code level it is called moderation. Querying lists by approval or moderation status needs some explanations. Due to some very bad design decisions there are some dirty tricks that one must use when querying lists by approval status. This posting shows safe way how to query lists by approval status. <span id="more-105"></span></p>
<h3>SPModerationInformation class</h3>
<p>Moderation information is kept in separate class called <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spmoderationinformation.aspx">SPModerationInformation</a>. It has properties <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spmoderationinformation.status.aspx">Status</a> and <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spmoderationinformation.comment.aspx">Comment</a>. First one of them shows moderation status of list item and the other one contains comment inserted by user who last changed moderation status. List item has property called <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitem.moderationinformation.aspx">ModerationInformation</a> that returns this object.</p>
<p align="center"><img style="border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px" border="0" alt="SharePoint: List versioning settings" src="http://sharepoint-weekly.com/wp-content/uploads/2009/09/listversioningsettings.png" width="502" height="242" />    <br /><em>SharePoint list versioning settings. First setting is for content approval.&#160; <br />By default content approval is disabled.</em>&#160;</p>
<p>SPModerationInformation class does nothing special – it is only wrapper for two fields: _ModerationStatus and _ModerationComment (these are internal names of these fields). These fields are added to list when user enables content approval. If content approval is disabled then ModerationInformation property is always null for list items. </p>
<h3>Querying list by moderation status</h3>
<p>It is possible to query lists by moderation status using CAML queries. As I mentioned before there is field with internal name _ModerationStatus. In database and web services it is integer that keeps values from <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spmoderationstatustype.aspx">SPModerationStatusType</a> enumerator. But if you are dealing with list items then this field contains string. </p>
<p>In CAML queries we must use moderation status as string. </p>
<hr size="1" />
<div style="font-family: courier new;background: white;color: black;font-size: 10pt">
<p style="margin: 0px"><span style="color: blue">var</span> queryString = <span style="color: #a31515">@&quot;&lt;Where&gt;</span></p>
<p style="margin: 0px"><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;Eq&gt;</span></p>
<p style="margin: 0px"><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;FieldRef Name=&#8217;_ModerationStatus&#8217;/&gt;</span></p>
<p style="margin: 0px"><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;Value Type=&#8217;ModStat&#8217;&gt;Approved&lt;/Value&gt;</span></p>
<p style="margin: 0px"><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/Eq&gt;</span></p>
<p style="margin: 0px"><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/Where&gt;&quot;</span>;</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: blue">var</span> query = <span style="color: blue">new</span> <span style="color: #2b91af">SPQuery</span> { Query = queryString };</p>
<p style="margin: 0px"><span style="color: blue">var</span> items = list.GetItems(query);</p>
</p></div>
<hr size="1" />
<p>You can see that we have to use special field type called ModStat. Yes, there is even class called <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldmodstat.aspx">SPFieldModStat</a> for this type.</p>
<h3>Awful bug in SharePoint</h3>
<p>So far, so good, but this solution works only in english installations of SharePoint. If your SharePoint site uses some other language than english you are in trouble because query shown above doesn’t return items anymore. But it also doesn’t give you any errors.</p>
<blockquote><p>Names of moderation statuses are not taken from SPModerationStatusType enumerator. There values are read from resource file!</p>
</blockquote>
<p>Well, now consider what happens when somebody makes a little typo in one of those translations. I think I don’t have to mention that building code and process logic around translation variables is something we can expect from complete noobs.</p>
<h3>Unified solution</h3>
<p>To make these queries work in any SharePoint site we have to read correct values from resource file. </p>
<ol>
<li>From Global Assembly Cache (GAC) copy assembly called Microsoft.SharePoint.intl.dll to some place where you can access it. </li>
<li>Run Reflector and open this assembly. </li>
<li>Under resources section you will find resources in this assembly. </li>
<li>Open Microsoft.SharePoint.resources, sort resources list and find constants that start with word ModerationStatus as shown on the image below.</li>
</ol>
<ol>
<p align="center"><a href="http://sharepoint-weekly.com/wp-content/uploads/2009/09/reflectorsharepointresources.png"><img style="border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px" border="0" alt="reflector-sharepoint-resources" src="http://sharepoint-weekly.com/wp-content/uploads/2009/09/reflectorsharepointresources_thumb.png" width="600" height="364" /></a>      <br /><em>.NET Reflector showing contents of Microsoft.SharePoint.resources. On the right pane        <br />moderation status Approved is highlighted.</em></p>
<p> Now we want to use these resources in our code. Here is class that provides you with static properties that return correct values for _ModerationStatus fields.</ol>
<div style="font-family: courier new;background: white;color: black;font-size: 10pt">
<hr size="1" />
<p style="margin: 0px"><span style="color: blue">internal</span> <span style="color: blue">class</span> <span style="color: #2b91af">Resources</span></p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">static</span> Resources()</p>
<p style="margin: 0px">&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">var</span> intlAsssembly = <span style="color: #2b91af">Assembly</span>.Load(<span style="color: #a31515">&quot;Microsoft.SharePoint.intl, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot;</span>);</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; IntlResources = <span style="color: blue">new</span> <span style="color: #2b91af">ResourceManager</span>(<span style="color: #a31515">&quot;Microsoft.SharePoint&quot;</span>,</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;intlAsssembly);</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">private</span> <span style="color: blue">static</span> <span style="color: #2b91af">ResourceManager</span> IntlResources { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: blue">string</span> ModerationStatusApproved</p>
<p style="margin: 0px">&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">get</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">return</span> IntlResources.GetString(<span style="color: #a31515">&quot;ModerationStatusApproved&quot;</span>);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: blue">string</span> ModerationStatusPending</p>
<p style="margin: 0px">&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">get</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">return</span> IntlResources.GetString(<span style="color: #a31515">&quot;ModerationStatusPending&quot;</span>);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
<p style="margin: 0px">}</p>
<hr size="1" /> </div>
<p>Now you can write query shown above as follows.</p>
<hr size="1" />
<div style="font-family: courier new;background: white;color: black;font-size: 10pt">
<p style="margin: 0px"><span style="color: blue">var</span> queryString = <span style="color: #a31515">@&quot;&lt;Where&gt;</span></p>
<p style="margin: 0px"><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;Eq&gt;</span></p>
<p style="margin: 0px"><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;FieldRef Name=&#8217;_ModerationStatus&#8217;/&gt;</span></p>
<p style="margin: 0px"><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;Value Type=&#8217;ModStat&#8217;&gt;{0}&lt;/Value&gt;</span></p>
<p style="margin: 0px"><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/Eq&gt;</span></p>
<p style="margin: 0px"><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/Where&gt;&quot;</span>;</p>
<p style="margin: 0px">queryString = <span style="color: blue">string</span>.Format(queryString,&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Resources</span>.ModerationStatusApproved); </p>
</p></div>
<hr size="1" />
<p>This solution is nothing elegant but I don’t think there are completely nice ways to get around hacks without replacing them with correct code. </p>
<h3>References</h3>
<ul>
<li><a href="http://blogs.msdn.com/jannemattila/archive/2007/04/14/adding-functionalities-to-pages-by-inheriting-publishingpagelayout.aspx">Adding functionalities to pages by inheriting PublishingLayoutPage</a> (Janne Mattila’s blog) </li>
<li><a href="http://www.hezser.de/blog/archive/2007/10/28/howto-use-the-resource-files-from-sharepoint.aspx">HowTo use the resource files from SharePoint</a> (SharePoint Blog &#8211; René Hézser) </li>
<li><a href="http://www.red-gate.com/products/reflector/">.NET Reflector home page</a> </li>
</ul>


<p>Related posts:<ol><li><a href='http://sharepoint-weekly.com/2009/09/querying-sharepoint-lists/' rel='bookmark' title='Permanent Link: Querying SharePoint lists'>Querying SharePoint lists</a></li>
</ol></p><img src="http://feeds.feedburner.com/~r/SharepointWeekly/~4/ZZEnLbAJfMg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sharepoint-weekly.com/2010/02/dissecting-sharepoint-content-approval/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://sharepoint-weekly.com/2010/02/dissecting-sharepoint-content-approval/</feedburner:origLink></item>
		<item>
		<title>Writing build and deployment scripts for SharePoint solutions</title>
		<link>http://feedproxy.google.com/~r/SharepointWeekly/~3/DdMxyuJy5pM/</link>
		<comments>http://sharepoint-weekly.com/2010/01/writing-build-and-deployment-scripts-for-sharepoint-solutions/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 04:23:48 +0000</pubDate>
		<dc:creator>Gunnar</dc:creator>
				<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Solution package]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://sharepoint-weekly.com/?p=85</guid>
		<description><![CDATA[For medium and large SharePoint solutions it is nice to have building and deployment scripts to save a lot of time you otherwise waste on repeating same actions manually. In this posting I will show you how to create simple scripts that build, package and deploy custom SharePoint solution built on Visual Studio 2008. 
Solution [...]


Related posts:<ol><li><a href='http://sharepoint-weekly.com/2010/01/moving-sharepoint-solutions-from-vsewss-to-wspbuilder/' rel='bookmark' title='Permanent Link: Moving SharePoint solutions from VSeWSS to WSPBuilder'>Moving SharePoint solutions from VSeWSS to WSPBuilder</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img src="/wp-content/themes/inove/img/deployment.jpg" alt="Deployment" title="Deployment" align="left"  style="margin-right:10px;margin-top:3px;margin-bottom:10px" />For medium and large SharePoint solutions it is nice to have building and deployment scripts to save a lot of time you otherwise waste on repeating same actions manually. In this posting I will show you how to create simple scripts that build, package and deploy custom SharePoint solution built on Visual Studio 2008. <span id="more-85"></span></p>
<h3>Solution structure and scripts</h3>
<p>To get scripts small and focused on conrete task we will create more than one batch file. It makes it very easy to create scripts for composite tasks – just add calls to base scripts and you are done. We will write the following scripts:<img style="border-right-width: 0px;margin: 10px 0px 0px 10px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px" border="0" alt="SharePoint solution deployment scripts" align="right" src="http://sharepoint-weekly.com/wp-content/uploads/2009/08/scripts.png" width="265" height="240" /> </p>
<ul>
<li><strong>build.bat</strong> – builds Visual Studio solution using MSBuild, </li>
<li><strong>package.bat</strong> – creates deployment packages for all projects using WSPBuilder, </li>
<li><strong>deploy.bat</strong> – deploys all solution packages to SharePoint, </li>
<li><strong>recycle-all.bat</strong> – recycles all application pools, </li>
<li><strong>replace-spsite.bat</strong> – replaces test site with new one if solution contains site template, </li>
<li><strong>full-build.bat</strong> – runs all previous scripts (you can call it also coffee-break.bat). </li>
</ul>
<p>We also need some modifications to our Visual Studio solution. It is good practice to keep all external tools you are using in your solution also in source-code control. So we need solution folder for tools. And we also need another solution folder – we need a place for scripts too. You can see Tools and Scripts folders on the image above. This image also illustrates Visual Studio solution folder structure.</p>
<blockquote><p><font><strong>NB!</strong> Scripts provided here are very raw but they work. At least for us. There is lot of room for these scripts to be improved and optimized.</font></p>
</blockquote>
<h3>Build script</h3>
<p>Build script will build Visual Studio solution. This is the first script we run when we start replacing our test site. I am using MSBuild because it turns out to be easiest tool for this task and also it is also in your computer if you have Visual Studio installed. </p>
<p>As I have currently no more actions related to code building then one line is enough from me.</p>
</p>
<hr size="1" /><code>Tools\MSBuild.exe Solutions\Eneta.Portal.sln<br />
<hr size="1" /></code>
</p>
<p>You can add all other build related commands to this file too.</p>
<h3>Packaging script</h3>
<p>After build we need to create new deployment packages for solutions. We will use WSPBuilder command-line tool that creates solution packages and deployment scripts. Here is the packaging script. </p>
<hr size="1" /><code>Tools\WSPBuilder.exe -SolutionPath Projects\Project1 -ProjectPath Projects\Project1 -OutputPath Projects\Project1 -ExpandTypes true -CreateDeploymentFolder stsadm     </p>
<p></code><code>...    </p>
<p></code><code>Tools\WSPBuilder.exe -SolutionPath Projects\ProjectN -ProjectPath Projects\ProjectN -OutputPath Projects\ProjectN -ExpandTypes true -CreateDeploymentFolder stsadm<br />
<hr size="1" /></code>
<p>Notice that WSPBuilder is put into Tools folder and called from there. Also notice that there is packaging command for each project in solution that needs packaging.</p>
<h3>Recycle script</h3>
<p>Well, recycling application pools can be done also on one line but it is not very sure I will use same recycling mechanism forever from now on. Also it is possible that same tools are not available on some development environments. </p>
<hr size="1" /><code>%windir%\system32\inetsrv\appcmd.exe list apppool /xml | %windir%\system32\inetsrv\appcmd.exe recycle apppool /in<br />
<hr size="1" /></code>
<p>This recycle method works well if you have IIS 7.0. </p>
<h3>Deployment script</h3>
<p>Deployment scrip deploys all our solutions to current SharePoint server. It is the slowest script and I don’t suggest it to run without good reason. It uses global deployment so all solutions regardless of their contents get deployed for sure. It is also compatible to deployments that WSPBuilder allows you to do through Visual Studio IDE.</p>
<hr size="1" /><code>Tools\gacutil.exe /u Project1    <br />...     <br />Tools\gacutil.exe /u ProjectN     <br />iisreset     </p>
<p>cd Projects\Project1\bin\deploy\Project1     <br />call deploywithstsadmnocontenturls.bat     <br />cd ..\..\..\..\..\     <br />call recycle-all.bat     </p>
<p>...     </p>
<p>cd Projects\ProjectN\bin\deploy\ProjectN     <br />call deploywithstsadm.bat     <br />cd ..\..\..\..\..\     <br />call recycle-all.bat<br />
<hr size="1" /></code>
<p>Before using this script we have to copy gacutil.exe to Tools folder. Before deploying solution to SharePoint the script removes all related assemblies from Global Assembly Cache (GAC). To make sure that there is no instances of assemblies anymore used by SharePoint iisreset is called.</p>
<p>Now take a look at two deployment call blocks shown above. First one of them makes global deployment to SharePoint. ProjectN will be deployed to all content applications automatically. It depends on your Visual Studio project contents what kind of deployment to use.</p>
<h3>Site replacement script</h3>
<p>Site replacement script is optional. My solution contains site definition that gets updates couple of times per day and I have to test if sites created by this definition are created correctly. Best way to test it is to create a new site. I prefer keeping things simple in my development machine so I delete site collection and create it again based on my site definition. Here is my script.</p>
<hr size="1" /><code>    call &quot;C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm.exe&quot; -o deletesite -url http://mossdev    </p>
<p>call &quot;C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm.exe&quot; -o createsite -url http://mossdev -owneremail me@example.com -ownerlogin mossdev\Administrator -lcid 1033 -sitetemplate SiteDef#0</code><code><br />
<hr size="1" /></code>
<p>Consider hard if you want to run this script for update deployments because this script deletes site and all its subsites and creates new site based on given site definition.</p>
<h3>Full-run script</h3>
<p>Our last script is for full run. It buils, packages, deploys our solution and replaces site collection. Script is simple because it calls other scripts we wrote previously.</p>
<hr size="1" /> <code>call build.bat   <br />call package.bat    <br />call deploy.bat    <br />call replace-spsite.bat<br />
<hr size="1" /></code>
<p>You don’t have to run these scripts for all builds because they take some time to complete. If you are modifying only some web parts and you need to get them online then do it through Visual Studio IDE. </p>
<h3>Conclusion</h3>
<p>As you saw it is not hard to write build and deployment scripts. You saw also that using powerful tools keeps your scripts simple. Of course, scripts provided here are just examples of what is possible. You should write your own scripts for your own scenarios. </p>
<h3>References</h3>
<ul>
<li><a href="http://wspbuilder.codeplex.com/">WSPBuilder homepage</a> </li>
<li><a href="http://msdn.microsoft.com/en-us/library/0k6kkbsd.aspx">MSBuild reference</a> </li>
<li><a href="http://blogs.msdn.com/msbuild/">MSBuild Team Blog</a> </li>
<li><a href="http://technet.microsoft.com/en-us/library/cc261956.aspx">Stsadm command-line tool</a> </li>
</ul>


<p>Related posts:<ol><li><a href='http://sharepoint-weekly.com/2010/01/moving-sharepoint-solutions-from-vsewss-to-wspbuilder/' rel='bookmark' title='Permanent Link: Moving SharePoint solutions from VSeWSS to WSPBuilder'>Moving SharePoint solutions from VSeWSS to WSPBuilder</a></li>
</ol></p><img src="http://feeds.feedburner.com/~r/SharepointWeekly/~4/DdMxyuJy5pM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sharepoint-weekly.com/2010/01/writing-build-and-deployment-scripts-for-sharepoint-solutions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://sharepoint-weekly.com/2010/01/writing-build-and-deployment-scripts-for-sharepoint-solutions/</feedburner:origLink></item>
		<item>
		<title>Moving SharePoint solutions from VSeWSS to WSPBuilder</title>
		<link>http://feedproxy.google.com/~r/SharepointWeekly/~3/29uJiWrSPDQ/</link>
		<comments>http://sharepoint-weekly.com/2010/01/moving-sharepoint-solutions-from-vsewss-to-wspbuilder/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 10:00:00 +0000</pubDate>
		<dc:creator>Gunnar</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Package creator]]></category>
		<category><![CDATA[Solution package]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://sharepoint-weekly.com/?p=72</guid>
		<description><![CDATA[WSPBuilder is currently one of the best tools to build SharePoint solutions and create deployment packages. Migration from VSeWSS to WSPBuilder is easy but there are some little tricks. In current posting I will show you how to move solutions from VSeWSS to WSPBuilder. 
VSeWSS is great tool by idea but it causes for me [...]


Related posts:<ol><li><a href='http://sharepoint-weekly.com/2010/01/writing-build-and-deployment-scripts-for-sharepoint-solutions/' rel='bookmark' title='Permanent Link: Writing build and deployment scripts for SharePoint solutions'>Writing build and deployment scripts for SharePoint solutions</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img src="/wp-content/themes/inove/img/tools.jpg" alt="Tools" title="Tools" align="left"  style="margin-right:10px;margin-top:3px;margin-bottom:10px" /><a href="http://wspbuilder.codeplex.com/">WSPBuilder</a> is currently one of the best tools to build SharePoint solutions and create deployment packages. Migration from VSeWSS to WSPBuilder is easy but there are some little tricks. In current posting I will show you how to move solutions from VSeWSS to WSPBuilder. <span id="more-72"></span></p>
<blockquote style="clear:left"><p>VSeWSS is great tool by idea but it causes for me heavy performance problems when I develop SharePoint solutions that contain more modules. Also I face serious performance problems when developing VSeWSS based projects on virtual machines. VSeWSS 1.3 was pretty hard to install and configure in my environments and I decided to abandon it. WSPBuilder introduces sometimes only some minor problems that are very easy to get over.</p>
</blockquote>
<p>Let’s suppose we have Visual Studio solution that contains couple of web parts. Solution uses VSeWSS based SharePoint project. We don’t have VSeWSS installed on our machine but we have WSPBuilder. We will modify project file and project structure. I show you on one web part what exactly to do.</p>
<h3>1. Modify project file</h3>
<p>When you open VSeWSS project you get the following error message.</p>
<p align="center"><img style="border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px" border="0" alt="Error message: The project type is not supported by this installation." src="http://sharepoint-weekly.com/wp-content/uploads/2009/08/projecttypenotsupported.png" width="416" height="178" /> </p>
<p>Visual Studio is not able to detect project type because you don’t have VSeWSS installed on your machine. WSPBuilder uses typical class libraries and doesn’t expect any additional project types to be installed or applied to project. Now follow these steps:</p>
<ol>
<li>Click Okay. Message disappears and project is shown as disabled in Solution Explorer. </li>
<li>Right click on project and select Edit your-project.csproj. </li>
<li>Project file will be opened in XML-editor. </li>
<li>Look for ProjectTypeGuids tag. It should look like this:<br />
<hr size="1" />
<div style="font-family: courier new;background: white;color: black;font-size: 10pt">
<p style="margin: 0px"><span style="color: blue">&lt;</span><span style="color: #a31515">ProjectTypeGuids</span><span style="color: blue">&gt;</span>{593B0543-81F6-4436-BA1E-4747859CAAE2};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}<span style="color: blue">&lt;/</span><span style="color: #a31515">ProjectTypeGuids</span><span style="color: blue">&gt;</span></p>
</p></div>
<hr size="1" /></li>
<li>Remove first GUID and semicolon from GUIDs list:<br />
<hr size="1" />
<div style="font-family: courier new;background: white;color: black;font-size: 10pt">
<p style="margin: 0px"><span style="color: blue">&lt;</span><span style="color: #a31515">ProjectTypeGuids</span><span style="color: blue">&gt;</span>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}<span style="color: blue">&lt;/</span><span style="color: #a31515">ProjectTypeGuids</span><span style="color: blue">&gt;</span></p>
</p></div>
<hr size="1" /></li>
<li>Save project file and close it. </li>
<li>Right click on project file and select Reload Project. </li>
<li>Project should load now and you should see its contents in Solution Explorer. </li>
</ol>
<h3>2. Modify project structure</h3>
<p><img style="border-right-width: 0px;margin: 0px 0px 5px 10px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px" border="0" alt="WSPBuilder Visual Studio project structure" align="right" src="http://sharepoint-weekly.com/wp-content/uploads/2009/08/wspbuilderprojectstructure.png" width="299" height="364" /> WSPBuilder expects project structure that is more similar to that you can find under 12-hive. You have to create also folder for your solution features and create feature files. Although VSeWSS creates feature files automatically I am not happy with it – I don’t need feature per web part in project. Usually one feature is enough. </p>
<p>Here is new project structure that is okay for WSPBuilder. As you can see form Solution Explorer screenshot the folder structure is same as under 12-hive. </p>
<p>I put all web parts in project under same feature – EventsWebParts. If you want you can also definer more than one feature per one project. WSPBuilder will handle the situation without problems.</p>
<p>Currently I expected that you moved existing web part definitions to your feature folder as shown on screenshot.</p>
<h3>3. Creating Feature.xml</h3>
<p>Let’s create now Feature.xml file. File creation process is like for any other file type in Visual Studio. Right click on your feature folder, select Add new … and then Data and XML file. Name file as Feature.xml and you are almost done.</p>
<p>In your feature file you must define elements and manifests locations. You can take the following example and modify it.</p>
<div style="font-family: courier new;background: white;color: black;font-size: 10pt">
<hr size="1" />
<p style="margin: 0px"><span style="color: blue">&lt;?</span><span style="color: #a31515">xml</span><span style="color: blue"> </span><span style="color: red">version</span><span style="color: blue">=</span>&quot;<span style="color: blue">1.0</span>&quot;<span style="color: blue"> </span><span style="color: red">encoding</span><span style="color: blue">=</span>&quot;<span style="color: blue">utf-8</span>&quot;<span style="color: blue"> ?&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&lt;</span><span style="color: #a31515">Feature</span><span style="color: blue"> </span><span style="color: red">xmlns</span><span style="color: blue">=</span>&quot;<span style="color: blue">http://schemas.microsoft.com/sharepoint/</span>&quot;</p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">YOUR-GUIDE-HERE</span>&quot;</p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: red">Title</span><span style="color: blue">=</span>&quot;<span style="color: blue">Feature title</span>&quot;</p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: red">Description</span><span style="color: blue">=</span>&quot;<span style="color: blue">Feature description</span>&quot;</p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: red">Scope</span><span style="color: blue">=</span>&quot;<span style="color: blue">Site</span>&quot;</p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: red">Hidden</span><span style="color: blue">=</span>&quot;<span style="color: blue">FALSE</span>&quot;<span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: blue">&#160; &lt;</span><span style="color: #a31515">ElementManifests</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160; &lt;</span><span style="color: #a31515">ElementManifest</span><span style="color: blue"> </span><span style="color: red">Location</span><span style="color: blue">=</span>&quot;<span style="color: blue">EventsWebPart.xml</span>&quot;<span style="color: blue"> /&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160; &lt;</span><span style="color: #a31515">ElementFile</span><span style="color: blue"> </span><span style="color: red">Location</span><span style="color: blue">=</span>&quot;<span style="color: blue">EventsWebPart.webpart</span>&quot;<span style="color: blue">/&gt;</span></p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160; &lt;</span><span style="color: #a31515">ElementManifest</span><span style="color: blue"> </span><span style="color: red">Location</span><span style="color: blue">=</span>&quot;<span style="color: blue">PastEventsWebPart.xml</span>&quot;<span style="color: blue"> /&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160; &lt;</span><span style="color: #a31515">ElementFile</span><span style="color: blue"> </span><span style="color: red">Location</span><span style="color: blue">=</span>&quot;<span style="color: blue">PastEventsWebPart.webpart</span>&quot;<span style="color: blue">/&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160; &lt;/</span><span style="color: #a31515">ElementManifests</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&lt;/</span><span style="color: #a31515">Feature</span><span style="color: blue">&gt;</span></p>
<hr size="1" /></div>
<p>&#160;</p>
<h3>4. Modifying web part files</h3>
<p>If you are using web part definitions created by VSeWSS you need to modify files with .webpart extension. Open some of these files in Visual Studio. You should see something like this.</p>
<div style="font-family: courier new;background: white;color: black;font-size: 10pt">
<hr size="1" />
<p style="margin: 0px"><span style="color: blue">&lt;?</span><span style="color: #a31515">xml</span><span style="color: blue"> </span><span style="color: red">version</span><span style="color: blue">=</span>&quot;<span style="color: blue">1.0</span>&quot;<span style="color: blue"> </span><span style="color: red">encoding</span><span style="color: blue">=</span>&quot;<span style="color: blue">UTF-8</span>&quot;<span style="color: blue">?&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&lt;</span><span style="color: #a31515">webParts</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160; &lt;</span><span style="color: #a31515">webPart</span><span style="color: blue"> </span><span style="color: red">xmlns</span><span style="color: blue">=</span>&quot;<span style="color: blue">http://schemas.microsoft.com/WebPart/v3</span>&quot;<span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160; &lt;</span><span style="color: #a31515">metaData</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">type</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue"><strong>HERE IS GUID</strong></span>&quot;<span style="color: blue"> /&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">importErrorMessage</span><span style="color: blue">&gt;</span>Cannot import Web Part.<span style="color: blue">&lt;/</span><span style="color: #a31515">importErrorMessage</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160; &lt;/</span><span style="color: #a31515">metaData</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160; &lt;</span><span style="color: #a31515">data</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">properties</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">property</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Title</span>&quot;<span style="color: blue"> </span><span style="color: red">type</span><span style="color: blue">=</span>&quot;<span style="color: blue">string</span>&quot;<span style="color: blue">&gt;</span>Web part title<span style="color: blue">&lt;/</span><span style="color: #a31515">property</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">property</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Description</span>&quot;<span style="color: blue"> </span><span style="color: red">type</span><span style="color: blue">=</span>&quot;<span style="color: blue">string</span>&quot;<span style="color: blue">&gt;</span><span style="color: blue">&lt;/</span><span style="color: #a31515">property</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160;&#160;&#160; &lt;/</span><span style="color: #a31515">properties</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160; &lt;/</span><span style="color: #a31515">data</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160; &lt;/</span><span style="color: #a31515">webPart</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&lt;/</span><span style="color: #a31515">webParts</span><span style="color: blue">&gt;</span></p>
<hr size="1" /> </div>
<p>Take a look at type tag under metaData. There is GUID of web part that this file defines. The same GUID is assigned to web part in its code file. When you build solution package with VSeWSS then VSeWSS replaces this GUID automatically with web part’s full type name. WSPBuilder is not able for that currently, so you have to replace the GUID in web part file with web part’s full name.</p>
<h3>5. Test</h3>
<p>Now you are almost done. Build your project and deploy web part to SharePoint.</p>
<ol>
<li>Right click on project title in Solution Explorer.</li>
<li>Select WSPBuilder –&gt; Create Deployment Folder.</li>
<li>WSPBuilder build solution package and generates installation scripts.</li>
<li>Select WSPBuilder –&gt; Deploy.</li>
<li>WSPBuilder deploys your solution to SharePoint.</li>
<li>Open SharePoint and try to add your web parts to some page to make sure that package was built correctly.</li>
</ol>
<h3>Epilogue</h3>
<p>Although VSeWSS is built with good intentions it offers very basic functionality and has sometimes serious performance problems. Newest version is harder to install and configure than older versions. WSPBuilder is free and open-source utility that works very well and doesn’t cause problems in development environment. It is very easy to install and use. To save your time you should think about moving to WSPBuilder if you are not using it already.</p>
<h3>References</h3>
<ul>
<li><a href="http://wspbuilder.codeplex.com/">WSPBuilder homepage</a></li>
<li><a href="http://wspbuilder.codeplex.com/Thread/List.aspx">WSPBuilder support forum</a></li>
<li><a href="http://keutmann.blogspot.com/">Carsten Keutmann’s blog</a> (author of WSPBuilder)</li>
<li><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=FB9D4B85-DA2A-432E-91FB-D505199C49F6&amp;displaylang=en">VSeWSS 1.3 download page</a>&#160;</li>
<li><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=7bf65b28-06e2-4e87-9bad-086e32185e68&amp;displaylang=en">VSeWSS 1.2 download page</a></li>
</ul>


<p>Related posts:<ol><li><a href='http://sharepoint-weekly.com/2010/01/writing-build-and-deployment-scripts-for-sharepoint-solutions/' rel='bookmark' title='Permanent Link: Writing build and deployment scripts for SharePoint solutions'>Writing build and deployment scripts for SharePoint solutions</a></li>
</ol></p><img src="http://feeds.feedburner.com/~r/SharepointWeekly/~4/29uJiWrSPDQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sharepoint-weekly.com/2010/01/moving-sharepoint-solutions-from-vsewss-to-wspbuilder/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://sharepoint-weekly.com/2010/01/moving-sharepoint-solutions-from-vsewss-to-wspbuilder/</feedburner:origLink></item>
		<item>
		<title>SPGenerateFileDefinitions: generate File and ElementFile blocks for definition files</title>
		<link>http://feedproxy.google.com/~r/SharepointWeekly/~3/90BNuq7cNLE/</link>
		<comments>http://sharepoint-weekly.com/2010/01/spgeneratefiledefinitions/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 00:01:49 +0000</pubDate>
		<dc:creator>Gunnar</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[Definitions]]></category>
		<category><![CDATA[Files]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://sharepoint-weekly.com/?p=65</guid>
		<description><![CDATA[This is excerpt]]></description>
			<content:encoded><![CDATA[<p><img src="/wp-content/themes/inove/img/tools.jpg" alt="Tools" title="Tools" align="left"  style="margin-right:10px;margin-top:0px;margin-bottom:10px" />I wrote simple utility that creates File and ElementFile XML-blocks based on files given folder. We have a lot of small files in one of our SharePoint portal site definitions and it was not very good idea to create feature elements for these files manually. During development also design gets some modifications and it is sure that these modifications introduce some new files and some older files may be not needed anymore. Our utility is fast and easy to use, so check it out! <span id="more-65"></span></p>
<p style="clear:left">I also put it up to CodePlex and named it as <a href="http://spgeneratefiledefs.codeplex.com/">SPGenerateFileDefinitions</a>. </p>
<p>Here is screenshot of application’s only screen. All you need is there – just make couple of mouse clicks and your work is done.</p>
<p align="center">&#160;<img style="border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px" border="0" alt="SPGenerateFileDefinitions: Definitions are done!" src="http://sharepoint-weekly.com/wp-content/uploads/2009/08/spgeneratefiledefinitions.png" width="600" height="321" /> </p>
<h3>How to use</h3>
<ol>
<li>Download application from <a href="http://spgeneratefiledefs.codeplex.com/">project page in CodePlex</a>.</li>
<li>Unpack it and run SPGenerateFileDefinitions.exe.</li>
<li>Click on button […] and show where are files located.</li>
<li>Click on button [Create XML].</li>
<li>When definitions are done click [OK] on message box.</li>
<li>Put definitions to your feature files using copy and paste.</li>
</ol>
<p>SPGenerateFileDefinitions is new tool and currently we are updating it if we need more features. If <strong>YOU</strong> need more features, then please let us know about it in <a href="http://spgeneratefiledefs.codeplex.com/Thread/List.aspx">project discussion</a>. If you find bugs or you have problems with SPGenerateFileDefinitions then please submit all this feedback to <a href="http://spgeneratefiledefs.codeplex.com/WorkItem/List.aspx">our issue tracker</a>. And as a last thing – happy using!</p>
<img src="http://feeds.feedburner.com/~r/SharepointWeekly/~4/90BNuq7cNLE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sharepoint-weekly.com/2010/01/spgeneratefiledefinitions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://sharepoint-weekly.com/2010/01/spgeneratefiledefinitions/</feedburner:origLink></item>
		<item>
		<title>Reading and writing SharePoint logs</title>
		<link>http://feedproxy.google.com/~r/SharepointWeekly/~3/mGA1n0BDVlE/</link>
		<comments>http://sharepoint-weekly.com/2010/01/sharepoint-logs-read-write/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 20:21:26 +0000</pubDate>
		<dc:creator>Gunnar</dc:creator>
				<category><![CDATA[Diagnostics and logging]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Extensions]]></category>
		<category><![CDATA[Logging]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[ULS]]></category>

		<guid isPermaLink="false">http://sharepoint-weekly.com/?p=26</guid>
		<description><![CDATA[In this posting I will introduce internals of SharePoint logs. You will get overview of logging background and I suggest some tools to browse and analyze log files. I will also introduce some tricks how to send messages to log from your own web parts and other extensions. Each topic here has also rich set [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/wp-content/themes/inove/img/diagnostics.jpg" alt="Diagnostics and logging" title="Diagnostics and logging" align="left"  style="margin-right:10px;margin-top:0px;margin-bottom:10px" />In this posting I will introduce internals of SharePoint logs. You will get overview of logging background and I suggest some tools to browse and analyze log files. I will also introduce some tricks how to send messages to log from your own web parts and other extensions. Each topic here has also rich set of links that help you go further. <span id="more-26"></span></p>
<h3>Unified Logging System</h3>
<p>WSS 3.0 and MOSS 2007 both use Unified Logging System (ULS) to write messages to SharePoint log. ULS uses <a href="http://msdn.microsoft.com/en-us/library/aa468736.aspx">Event Tracing for Windows</a> (ETW). This is logging and tracing technology first introduced in Windows 2000. ETW is available through Windows API and it should be very efficient logging technology.</p>
<p>Although ULS is powerful technology it is not easy to use without third-party tools. You can configure some settings in SharePoint Central Administration site but there are no default tools that make reading the logs easy. </p>
<h4>References</h4>
<ul>
<li><a href="http://technet.microsoft.com/en-us/library/cc288649.aspx">Configure diagnostic logging settings</a> (TechNet) </li>
<li><a href="http://www.andrewconnell.com/blog/archive/2008/06/11/SharePoint-Debugging-and-Logging-Tips-and-Tricks.aspx">SharePoint Debugging and Logging Tips and Tricks</a> (Andrew Connell) </li>
</ul>
<h3>How to read log files</h3>
<p>You can use different tools to read and analyze SharePoint log files. All log file reading tools introduced here are third-party tools from <a href="http://www.codeplex.com/">CodePlex</a> and other sites. They work nice and if you find something you like you can try it. </p>
<h4><strong>Starznet WSS / MOSS Log File Reader</strong></h4>
<p><a href="http://wssmosslogfilereader.codeplex.com/">Starznet WSS / MOSS Log File Reader</a> is SharePoint solution that you can install to Central Administration web site. It adds new “Log File Viewer” selection under “Logging and Reporting” block. Following screenshot gives you some idea about what to expect. Most useful feature that Starznet offers is log files search. I know what a pain can be searching and reading log files using Notepad or some other simple text editor. </p>
<p align="center"><a href="http://sharepoint-weekly.com/wp-content/uploads/2009/08/starznetlogfileviewer.png"><img style="border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px" border="0" alt="Starznet Log File Viewer" src="http://sharepoint-weekly.com/wp-content/uploads/2009/08/starznetlogfileviewer_thumb.png" width="600" height="310" /></a>     <br /><em>Starzner WSS / MOSS Log File Reader. Screenshot shows file contents view.      <br />Click on image to enlarge.</em></p>
<p>I got it installed without any problems and it works nice. I found also one problem – Log File Reader is not able to read current log file because of file locks.&#160; </p>
<h4><strong>SPTraceView</strong></h4>
<p><img style="border-right-width: 0px;margin: 0px 0px 0px 10px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px" border="0" alt="SPTraceView notifying about new message" align="right" src="http://sharepoint-weekly.com/wp-content/uploads/2009/08/sptraceview.jpg" width="342" height="127" /> If you need something very simple to monitor your logs in real-time, you can use <a href="http://hristopavlov.wordpress.com/2008/06/19/sptraceview-lightweight-tool-for-monitoring-the-sharepoint-diagnostic-logging-in-real-time/">SPTraceView</a> utility by <a href="http://hristopavlov.wordpress.com/">Hristo Pavlov</a>. SPTraceView also offers table view of active log file and you can open it by double clicking on trace icon.</p>
<p>SPTraceView has also settings dialog where you can modify logging level and message filters. It is also possible to send selected messages to DebugView. I think SPTraceView may be useful tool for developers to track problems in test environment. It is faster than monitoring log files manually. </p>
<h4><strong>Microsoft Log Parser 2.2</strong></h4>
<p><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=890cd06b-abf8-4c25-91b2-f8d975cf8c07&amp;displaylang=en">Microsoft Log Parser</a> is command-line tool you can use to analyze ULS log files. Log Parser lets you execute queries against ULS log files and save output to another text file. Performance of this tool is pretty good. MSDN blog entry <a href="http://blogs.msdn.com/jimmiet/archive/2008/03/15/uls-log-file-data-mining.aspx">ULS Log File Data Mining</a> gives example of query that uses aggregate functions and that handles almost 1.5 million log lines with 77 seconds. </p>
<p>You can use this tool to execute your own SQL-like queries against log files to get out information you really need. There is one gotcha – Log Parser doesn’t know that log messages in ULS logs may take more than one line.</p>
<h4><strong>References</strong></h4>
<ul>
<li><a href="http://wssmosslogfilereader.codeplex.com/">Starznet WSS / Moss Log File Reader</a> (CodePlex) </li>
<li><a href="http://ulsviewer.codeplex.com/">SharePoint ULS Log Viewer</a>&#160; (CodePlex) </li>
<li><a href="http://hristopavlov.wordpress.com/2008/06/19/sptraceview-lightweight-tool-for-monitoring-the-sharepoint-diagnostic-logging-in-real-time/">SPTraceView – Lightweight Tool For Monitoring The SharePoint Diagnostic Logging In Real-Time</a> (Hristo Pavlov) </li>
<li><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=890cd06b-abf8-4c25-91b2-f8d975cf8c07&amp;displaylang=en">Microsoft Log Parser 2.2</a> (Microsoft) </li>
<li><a href="http://blogs.msdn.com/jimmiet/archive/2008/03/15/uls-log-file-data-mining.aspx">ULS Log File Data Mining</a> (MSDN blogs) </li>
</ul>
<h3>How to write to log files</h3>
<p>Writing to SharePoint log files from your is simple if your code has to run only on MOSS 2007. It takes only one line of code.</p>
<div style="font-family: courier new;background: white;color: black;font-size: 10pt">
<hr size="1" />
<p style="margin: 0px">Microsoft.Office.Server.Diagnostics.<span style="color: #2b91af">PortalLog</span>.LogString(<span style="color: #a31515">&quot;Logged!&quot;</span>);</p>
<hr size="1" /></div>
<p>That’s it. But if you are using WSS or you want logging solution that works for both of them, you need third-party libraries. Of course, you can write your own logging solution if you have time enough. There is third-party library called SharePoint.Diagnostics that let’s you do something like this.</p>
<div style="font-family: courier new;background: white;color: black;font-size: 10pt">
<hr size="1" />
<p style="margin: 0px"><span style="color: blue">using</span> System;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System.Runtime.InteropServices;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System.Web.UI;</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: blue">using</span> Microsoft.SharePoint.WebPartPages;</p>
<p style="margin: 0px"><span style="color: blue">using</span> SharePoint.Diagnostics;</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: blue">namespace</span> TestWebParts</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">&#160;&#160;&#160; [<span style="color: #2b91af">Guid</span>(<span style="color: #a31515">&quot;2d2e82e3-8f47-4764-1236-b1c06f104183&quot;</span>)]</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: #2b91af">LoggingWebPart</span> : <span style="color: #2b91af">WebPart</span></p>
<p style="margin: 0px">&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> Create all your controls here for rendering.</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> Try to avoid using the RenderWebPart() method.</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">protected</span> <span style="color: blue">override</span> <span style="color: blue">void</span> CreateChildControls()</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">try</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Trace</span>.LogMessage(<span style="color: #a31515">&quot;This message goes to SharePoint log!&quot;</span>,</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">TraceSeverity</span>.High,<span style="color: #a31515">&quot;LoggingWebPart&quot;</span>);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Controls.Add(<span style="color: blue">new</span> <span style="color: #2b91af">LiteralControl</span>(<span style="color: #a31515">&quot;No errors!&quot;</span>));</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">catch</span>(<span style="color: #2b91af">Exception</span> ex)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Controls.Add(<span style="color: blue">new</span> <span style="color: #2b91af">LiteralControl</span>(ex.ToString()));</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
<p style="margin: 0px">}</p>
</p></div>
<hr size="1" />
<p>There are some tricks to make it work. After downloading WSP change its extension to cab. Extract SharePoint.Diagnostics.dll and add reference to it to your project.</p>
<h4><strong>References</strong></h4>
<ul>
<li><a href="http://splogger.codeplex.com/">ULS Logger</a> (CodePlex) </li>
<li><a href="http://spdiagnostics.codeplex.com/">SharePoint.Diagnostics</a> (CodePlex) </li>
<li><a href="http://weblogs.asp.net/gunnarpeipman/archive/2009/02/25/sharepoint-writing-messages-to-uls-unified-logging-system.aspx">SharePoint: Writing messages to ULS (Unified Logging System)</a> (My ASP.NET blog) </li>
<li><a href="http://weblogs.asp.net/erobillard/archive/2008/07/31/sharepoint-trace-logs-and-the-unified-logging-service-uls.aspx">SharePoint Trace Logs and the Unified Logging Service (ULS)</a> (Eli Robillard) </li>
<li><a href="http://trentacular.com/2008/12/sharepoint-logging-and-microsofts-trace-log-provider/">SharePoint Logging and Microsoft’s Trace Log Provider</a> (Trentacular) </li>
<li><a href="http://msdn.microsoft.com/en-us/library/aa979590.aspx">Trace Logs</a> (MSDN Library) </li>
<li><a href="http://msdn.microsoft.com/en-us/library/aa979522.aspx">Trace Log Example</a> (MSDN Library) </li>
<li><a href="http://www.marc-antho-etc.net/blog/post/2009/01/05/SharePoint-Diagnostic-Logging-Quick-Summary.aspx">SharePoint Diagnostic Logging (ak ULS) Quick Summary</a> (Full Metal Architect) </li>
<li><a href="http://www.codeproject.com/KB/sharepoint/SPLogging.aspx">Implementation of Logging and Instrumentation Application Block in MOSS 2007</a> (CodeProject) </li>
</ul>
<h3>Epilogue</h3>
<p>ULS logs are powerful sources of information. Reading and writing SharePoint logs lies heavily on third-party and custom solutions right now. With free and open-source third-party tools it is easy to read and write SharePoint logs. Developers can easily write messages of their extensions to SharePoint logs and this makes extensions to fit better in SharePoint environment.</p>
<img src="http://feeds.feedburner.com/~r/SharepointWeekly/~4/mGA1n0BDVlE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sharepoint-weekly.com/2010/01/sharepoint-logs-read-write/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://sharepoint-weekly.com/2010/01/sharepoint-logs-read-write/</feedburner:origLink></item>
		<item>
		<title>Querying SharePoint lists</title>
		<link>http://feedproxy.google.com/~r/SharepointWeekly/~3/1HXV4mWMNR8/</link>
		<comments>http://sharepoint-weekly.com/2009/09/querying-sharepoint-lists/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 17:00:00 +0000</pubDate>
		<dc:creator>Viko</dc:creator>
				<category><![CDATA[Queries]]></category>
		<category><![CDATA[CAML]]></category>
		<category><![CDATA[Lists]]></category>

		<guid isPermaLink="false">http://sharepoint-weekly.com/?p=83</guid>
		<description><![CDATA[SharePoint lists are the most common toolset we use in our everyday SharePoint project. You can save documents or contact information; you can create lists for some control settings or even use some data to use in workflow activities. In this post i will introduce some query methods and options to get information out of [...]


Related posts:<ol><li><a href='http://sharepoint-weekly.com/2010/02/dissecting-sharepoint-content-approval/' rel='bookmark' title='Permanent Link: Dissecting SharePoint content approval'>Dissecting SharePoint content approval</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img src="/wp-content/themes/inove/img/queries.jpg" alt="Queries" title="Queries" align="left"  style="margin-right:10px;margin-top:0px;margin-bottom:10px" />SharePoint lists are the most common toolset we use in our everyday SharePoint project. You can save documents or contact information; you can create lists for some control settings or even use some data to use in workflow activities. In this post i will introduce some query methods and options to get information out of SharePoint list. <span id="more-83"></span></p>
<h3>Preface</h3>
<p>Before we start querying our first list you must understand SharePoint list structure. Every list in SharePoint contains some built-in fields what are created out-of-box and other fields you create your own purpose. Every field in this list has its own data type and may have been associated with special SharePoint field class (e.g <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldlookup.aspx">SPFieldLookup</a>, <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfielduser.aspx">SPFieldUser</a>), which you can use to get values or specify field’s metadata. Every item returned from the query is in <em>object</em> type and must be casted into right field type before usage. Every query you make to the list returns <em>SPListItemCollection</em> object where you can use indexer to get specific <em>SPListItem</em> or you can iterate the item collection using foreach<strong>.</strong></p>
<p>Every field in a item’s field collection contains two type of naming to programmatically use. There is field’s <em>internal name<strong> – </strong></em>this name will not be changed after creation, and is the best way to query specific field; and <em>display name</em> or <em>title<strong> – </strong></em>what you can change in the UI. <em>Display name</em> is not the best way to query fields in code, because when somebody changes it you will get an exception which is not very useful to debug and may take a lot of your time to find this bug. When you create a field in the UI, the new field will have the same name for the <em>internal name</em> and <em>display name</em>, when you modify a field in UI you only change a <em>display name. </em>To programmatically access this field you must use the field name you assigned first time. <em>&#160;</em>&#160;</p>
<h3>Query options</h3>
<p>To begin with querying list you have two options to get results out of list. You can use <em>SPList</em> object methods and properties to ask items from the collection or you can use <a href="http://msdn.microsoft.com/en-us/library/ms467521.aspx">CAML</a> (Collaborative Application Markup Language) to specify fields and filters. </p>
<p>NB! You should not use SPList.Items property with the large list, because it will return all the&#160; items in the list with all fields. Query results are not cached and it will be a performance hit to your server because every time you query some items, SharePoint will create a new collection for your items.</p>
<p>So to start with our first example I will show to you how you can get the first item’s field value from the Items collection using field’s <em>display name “</em>MyField<em>”</em>.</p>
<hr size="1" />
<div style="font-family: courier new;background: white;color: black;font-size: 10pt">
<div style="font-family: courier new;background: white;color: black;font-size: 10pt">
<p style="margin: 0px"><span style="color: #2b91af">SPSite</span> site = <span style="color: #2b91af">SPContext</span>.Current.Site;</p>
<p style="margin: 0px"><span style="color: #2b91af">SPWeb</span> web = <span style="color: blue">null</span>;</p>
<p style="margin: 0px"><span style="color: blue">try</span> {</p>
<p style="margin: 0px">&#160;&#160; web = site.OpenWeb();</p>
<p style="margin: 0px">&#160;&#160; <span style="color: blue">if</span> (web == <span style="color: blue">null</span>)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">//do something</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">return</span>;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">SPList</span> list = web.Lists[<span style="color: #a31515">&quot;MyList&quot;</span>]; </p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">SPListItemCollection</span> items = list.Items;</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; </span>&#160;&#160;&#160; <span style="color: blue">if</span> (items.Count != 0)</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; </span>&#160;&#160;&#160; {</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; </span>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Response.Write(items[0][<span style="color: #a31515">&quot;MyField&quot;</span>]);</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; </span>&#160;</p>
<p style="margin: 0px">&#160;<span style="color: #2b91af">&#160; </span>&#160;</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; </span>&#160;&#160;&#160; }</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; </span></p>
<p style="margin: 0px">} <span style="color: blue">catch</span> (<span style="color: #2b91af">SPException</span> ex)</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: green">//to somethingwith this exception</span></p>
<p style="margin: 0px">}</p>
<p style="margin: 0px"><span style="color: blue">finally</span></p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160;&#160;&#160; </span><span style="color: blue">if</span> (web != <span style="color: blue">null</span>)</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160; web.Dispose();</p>
<p style="margin: 0px">}</p>
</p></div>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; </span></p>
<hr size="1" /></div>
<p>To use internal name in this example we will create <em>SPField</em> object which will allows us to use all the field metadata. We will use <em>SPField</em> Id property to get item field value. </p>
<hr size="1" />
<div style="font-family: courier new;background: white;color: black;font-size: 10pt">
<p style="margin: 0px">&#160;<span style="color: #2b91af">SPField</span> field = items[0].Fields.GetFieldByInternalName(<span style="color: #a31515">&quot;MyField&quot;</span>);</p>
<p style="margin: 0px">Response.Write(items[field.Id].ToString());</p>
</p></div>
<hr size="1" />
<p>To get the best performance out of querying lists you should use <em>CAML queries<strong>.</strong></em> It will allow you to choose fields you want to show, result items count and filters. </p>
<p>Basic CAML query syntax is:</p>
<hr size="1" />
<div style="font-family: courier new;background: white;color: black;font-size: 10pt">
<div style="font-family: courier new;background: white;color: black;font-size: 10pt">
<p style="margin: 0px"><span style="color: blue">&lt;</span><span style="color: #a31515">Where</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160; &lt;</span><span style="color: #a31515">And</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160; &lt;</span><span style="color: #a31515">Eq</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">FieldRef</span><span style="color: blue"> </span><span style="color: red">Name</span><span style="color: blue">=</span>&quot;<span style="color: blue">MyField</span>&quot;<span style="color: blue">/&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">Value</span><span style="color: blue"> </span><span style="color: red">Type</span><span style="color: blue">=</span>&quot;<span style="color: blue">Text</span>&quot;<span style="color: blue">&gt;</span>MyValue<span style="color: blue">&lt;/</span><span style="color: #a31515">Value</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160; &lt;/</span><span style="color: #a31515">Eq</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160; &lt;/</span><span style="color: #a31515">And</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160; &lt;</span><span style="color: #a31515">Or</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160; &lt;</span><span style="color: #a31515">Lt</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">FieldRef</span><span style="color: blue"> </span><span style="color: red">Name</span><span style="color: blue">=</span>&quot;<span style="color: blue">MyField2</span>&quot;<span style="color: blue"> /&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">Value</span><span style="color: blue"> </span><span style="color: red">Type</span><span style="color: blue">=</span>&quot;<span style="color: blue">Number</span>&quot;<span style="color: blue">&gt;</span>3<span style="color: blue">&lt;/</span><span style="color: #a31515">Value</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160; &lt;/</span><span style="color: #a31515">Lt</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160; &lt;/</span><span style="color: #a31515">Or</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&lt;/</span><span style="color: #a31515">Where</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&lt;</span><span style="color: #a31515">OrderBy</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160; &lt;</span><span style="color: #a31515">FieldRef</span><span style="color: blue"> </span><span style="color: red">Name</span><span style="color: blue">=</span>&quot;<span style="color: blue">MyField</span>&quot;<span style="color: blue">/&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&lt;/</span><span style="color: #a31515">OrderBy</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&lt;</span><span style="color: #a31515">GroupBy</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160; &lt;</span><span style="color: #a31515">FieldRef</span><span style="color: blue"> </span><span style="color: red">Name</span><span style="color: blue">=</span>&quot;<span style="color: blue">MyField</span>&quot;<span style="color: blue">/&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&lt;/</span><span style="color: #a31515">GroupBy</span><span style="color: blue">&gt;</span></p>
</p></div>
<p style="margin: 0px">
<hr size="1" /></div>
<p>To use CAML in our queries we have to create <em>SPQuery</em> object. <em>SPQuery</em> object allows us to specify other parameters of query such as: ViewFields, RowLimit. </p>
<p>In our next example I will create CAML query to get list items where “Status” field value is “Archived”</p>
<hr size="1" />
<div style="font-family: courier new;background: white;color: black;font-size: 10pt">
<p style="margin: 0px"><span style="color: #2b91af">SPSite</span> site = <span style="color: #2b91af">SPContext</span>.Current.Site;</p>
<p style="margin: 0px"><span style="color: #2b91af">SPWeb</span> web = <span style="color: blue">null</span>;</p>
<p style="margin: 0px"><span style="color: blue">try</span> {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160; web = site.OpenWeb();</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160; <span style="color: blue">if</span> (web == <span style="color: blue">null</span>)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">//do something</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">return</span>;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160; <span style="color: #2b91af">SPList</span> list = web.Lists[<span style="color: #a31515">&quot;MyList&quot;</span>];</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160; <span style="color: #2b91af">SPQuery</span> query = <span style="color: blue">new</span> <span style="color: #2b91af">SPQuery</span>();</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160; query.Query = <span style="color: #a31515">&quot;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=&#8217;Status&#8217;/&gt;&lt;Value Type=&#8217;Text&#8217;&gt;Archived&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&quot;</span>;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160; <span style="color: #2b91af">SPListItemCollection</span> items = list.GetItems(query);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160; <span style="color: blue">if</span> (items.Count != 0)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">//Some code to show result</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">} <span style="color: blue">catch</span> (<span style="color: #2b91af">SPException</span> ex)</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160; <span style="color: green">//to somethingwith this exception</span></p>
<p style="margin: 0px">}</p>
<p style="margin: 0px"><span style="color: blue">finally</span></p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">if</span> (web != <span style="color: blue">null</span>)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; web.Dispose();</p>
<p style="margin: 0px">}</p>
</p></div>
<hr size="1" />
<p>To specify how many items to return you should add line:</p>
<hr size="1" />
<div style="font-family: courier new;background: white;color: black;font-size: 10pt">
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; </span>query.RowLimit = 5;</p>
</p></div>
<hr size="1" />
<p>To show only fields “Title” and “Status” you should add line:</p>
<hr size="1" />
<div style="font-family: courier new;background: white;color: black;font-size: 10pt">
<p style="margin: 0px">query.ViewFields = <span style="color: #a31515">&quot;&lt;FieldRef Name=&#8217;Title&#8217;/&gt;&lt;FieldRef Name=&#8217;Status&#8217;/&gt;&quot;</span>;</p>
</p></div>
<hr size="1" />
<h3>Exceptions</h3>
<p>You must choose a the type of query always carefully, because if there is some mistake in field’s <em>display name</em> or <em>internal name</em> SharePoint gives you the most generic message e.g “Value does not fall within the expected range” or “One or more field types are not installed properly. Go to the list settings page to delete these field” To avoid these exceptions you should always use internal name because it can’t be changed after creation. </p>
<p>To avoid field name mistakes you should always create list instance based on list template or list definition. It avoids mistakes that people can do when installing your solution and allows you to specify internal name you like.</p>
<h3>In Conclusion</h3>
<p>Lists are important tool in our everyday programming and it is important to know how to query items from lists. Using Items collection will help you quickly to get all the items in the list, but it will be a performance hit when you use it on a large list. To specify how many items to show, which fields to use, you should use <em>CAML</em> queries.</p>
<h3>References</h3>
<ul>
<li><a href="http://weblogs.asp.net/gunnarpeipman/archive/2008/09/27/sharepoint-for-developers-3-2-hands-on-getting-list-items.aspx">Getting List Items</a> </li>
<li><a href="http://sharepointmagazine.net/technical/development/writing-caml-queries-for-retrieving-list-items-from-a-sharepoint-list">CAML queries for getting list items</a> </li>
<li><a href="http://msdn.microsoft.com/en-us/library/ms467521.aspx">CAML Query Schema</a> </li>
<li><a href="http://weblogs.asp.net/gunnarpeipman/archive/2008/10/29/sharepoint-for-developers-3-3-hands-on-querying-lists.aspx">Querying lists using CAML</a> </li>
</ul>


<p>Related posts:<ol><li><a href='http://sharepoint-weekly.com/2010/02/dissecting-sharepoint-content-approval/' rel='bookmark' title='Permanent Link: Dissecting SharePoint content approval'>Dissecting SharePoint content approval</a></li>
</ol></p><img src="http://feeds.feedburner.com/~r/SharepointWeekly/~4/1HXV4mWMNR8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sharepoint-weekly.com/2009/09/querying-sharepoint-lists/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://sharepoint-weekly.com/2009/09/querying-sharepoint-lists/</feedburner:origLink></item>
		<item>
		<title>SharePoint development tools</title>
		<link>http://feedproxy.google.com/~r/SharepointWeekly/~3/lv8AqvgT42A/</link>
		<comments>http://sharepoint-weekly.com/2009/08/sharepoint-development-tools/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 19:25:05 +0000</pubDate>
		<dc:creator>Viko</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[Installer]]></category>
		<category><![CDATA[Package creator]]></category>
		<category><![CDATA[Solution package]]></category>

		<guid isPermaLink="false">http://sharepoint-weekly.com/?p=43</guid>
		<description><![CDATA[Before you start writing your first SharePoint application you should spend some time to choose your development tools. The right set of tools will help you to save time and you don’t have to do so much work manually. Generally you need tools that will help you analyze, create and deploy your solution into SharePoint. [...]


Related posts:<ol><li><a href='http://sharepoint-weekly.com/2010/01/moving-sharepoint-solutions-from-vsewss-to-wspbuilder/' rel='bookmark' title='Permanent Link: Moving SharePoint solutions from VSeWSS to WSPBuilder'>Moving SharePoint solutions from VSeWSS to WSPBuilder</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img src="/wp-content/themes/inove/img/tools.jpg" alt="Tools" title="Tools" align="left"  style="margin-right:10px;margin-top:0px;margin-bottom:10px" />Before you start writing your first SharePoint application you should spend some time to choose your development tools. The right set of tools will help you to save time and you don’t have to do so much work manually. Generally you need tools that will help you analyze, create and deploy your solution into SharePoint. I will discuss about three tools that will help you to analyze, package and install your application. These tools are only few that you can find. The choice is made mostly by my experience using different tools. <span id="more-43"></span></p>
<h3>WSPBuilder</h3>
<p>The most important tool in the SharePoint solution development lifecycle is a solution package creator. <a href="http://wspbuilder.codeplex.com/">WSPBuilder</a> is a simple solution package builder which will integrate with Visual Studio 2005 and 2008. It will allow you to create, install, upgrade and uninstall your solution package (WSP) and even create deployment folder which contains deployment scripts and installation program. After you install this tool it will create a new menu item and context menu into your Visual Studio (VS) environment.</p>
<p align="center"><a href="http://sharepoint-weekly.com/wp-content/uploads/2009/08/context.png"><img style="border-right-width: 0px;float: none;border-top-width: 0px;border-bottom-width: 0px;margin-left: auto;border-left-width: 0px;margin-right: auto" border="0" alt="WSPBuilder context menu" src="http://sharepoint-weekly.com/wp-content/uploads/2009/08/context_thumb.png" width="328" height="157" /></a></p>
<p>WSPBuilder is quite dynamic with its capabilities. You can start your project with a simple class library, it won’t add mysterious dependencies to project which won’t let you to open your project in another VS environment. Only requirement that WSPBuilder needs is that you have to create your project folder structure like in the SharePoint 12 hive <em>“C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12” </em></p>
<p align="center"><a href="http://sharepoint-weekly.com/wp-content/uploads/2009/08/Project.png"><img style="border-right-width: 0px;float: none;border-top-width: 0px;border-bottom-width: 0px;margin-left: auto;border-left-width: 0px;margin-right: auto" border="0" alt="WSPBuilder project structure" src="http://sharepoint-weekly.com/wp-content/uploads/2009/08/Project_thumb.png" width="244" height="244" /></a> </p>
<h3>SharePoint Solution Installer</h3>
<p>After you have created your project solution package you can use a nice <a href="http://www.codeplex.com/sharepointinstaller">installer</a>, which will help your application users to install the application. </p>
<p>It is much simpler than using SharePoint built-in administrative tool <em>stsadm.exe</em>. You can create custom End User Licence Agreement file and add it to installer. You can even specify which features will be activated. Before you can install your solution installer will check your system to meet te requirements (MOSS or WSS application, application installed or not).</p>
<p align="center"><a href="http://sharepoint-weekly.com/wp-content/uploads/2009/08/installer_system_check.png"><img style="border-right-width: 0px;float: none;border-top-width: 0px;border-bottom-width: 0px;margin-left: auto;border-left-width: 0px;margin-right: auto" border="0" alt="SharePoint installer Sytem Check window" src="http://sharepoint-weekly.com/wp-content/uploads/2009/08/installer_system_check_thumb.png" width="381" height="300" /></a> </p>
<p align="center"><a href="http://sharepoint-weekly.com/wp-content/uploads/2009/08/installer_EULA.png"><img style="border-right-width: 0px;float: none;border-top-width: 0px;border-bottom-width: 0px;margin-left: auto;border-left-width: 0px;margin-right: auto" border="0" alt="SharePoint installer EULA window" src="http://sharepoint-weekly.com/wp-content/uploads/2009/08/installer_EULA_thumb.png" width="379" height="299" /></a></p>
<h3>SharePoint Manager 2007</h3>
<p>Sometimes you need get some list item field internal name or you want to add some list definition into your project and make some modifications. Usually to get some property value from list or list item is impossible because property is hidden in the UI and you cant find the value from the site or list template. <a href="http://www.codeplex.com/spm">SharePoint Manager</a> will help you with these problems.</p>
<p>It is a nice tool what you can use to find properties, schemas, etc. from Site Collection, Web, List, etc. SPM will help you to check if your code run as expected and it did set the workflow association data. With SPM you can make even changes to some properties, but you must be careful with that and you have to know what are you changing and what value the property expects.</p>
<p align="center"><a href="http://sharepoint-weekly.com/wp-content/uploads/2009/08/SPM.png"><img style="border-right-width: 0px;float: none;border-top-width: 0px;border-bottom-width: 0px;margin-left: auto;border-left-width: 0px;margin-right: auto" border="0" alt="Sharepoint Manager Lists View" src="http://sharepoint-weekly.com/wp-content/uploads/2009/08/SPM_thumb.png" width="514" height="317" /></a></p>
<h3>Conclusion</h3>
<p>Every tool in this list has somehow helped me in my development. I’m using SP Installer because it is simple and it will allow change the installer experience by simply changing some property values in installer configuration. </p>
<p>SharePoint Manager is a create tool to check some property values, internal names, to get minimal list schema and it will allow me to do this without opening SharePoint site.</p>
<p>WSPBuilder is the simplest package creation tool I have seen, it allows me to create multi-project solution and simply referencing assemblies it will create a nice package with everything my application needs.</p>
<h4><strong>Other tools</strong></h4>
<ul>
<li><a href="http://www.microsoft.com/downloads/details.aspx?familyid=7BF65B28-06E2-4E87-9BAD-086E32185E68&amp;displaylang=en">Visual Studio Extensions For Windows SharePoint Services 1.2</a></li>
<li><a href="http://stsdev.codeplex.com/">Simple Tools For SharePoint 2007 Development</a></li>
</ul>


<p>Related posts:<ol><li><a href='http://sharepoint-weekly.com/2010/01/moving-sharepoint-solutions-from-vsewss-to-wspbuilder/' rel='bookmark' title='Permanent Link: Moving SharePoint solutions from VSeWSS to WSPBuilder'>Moving SharePoint solutions from VSeWSS to WSPBuilder</a></li>
</ol></p><img src="http://feeds.feedburner.com/~r/SharepointWeekly/~4/lv8AqvgT42A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sharepoint-weekly.com/2009/08/sharepoint-development-tools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://sharepoint-weekly.com/2009/08/sharepoint-development-tools/</feedburner:origLink></item>
	</channel>
</rss>
