<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Robin's SharePoint blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/rmeure/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/rmeure/feed.xml</link>
    <description>This is my view as a SharePoint enthusiastic.. and yes.. accidently I&amp;#039;m also a PFE :)</description>
    <lastBuildDate>Tue, 16 Apr 2019 05:26:40 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Supported way of eliminating (large) JS files for SharePoint 2010</title>
      <link>https://docs.microsoft.com/archive/blogs/rmeure/supported-way-of-eliminating-large-js-files-for-sharepoint-2010</link>
      <pubDate>Tue, 17 Jan 2012 10:48:21 GMT</pubDate>
      <dc:creator><![CDATA[Robin Meuré]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/rmeure/2012/01/17/supported-way-of-eliminating-large-js-files-for-sharepoint-2010/</guid>
      <description><![CDATA[During an onsite visit at a customer who were very busy at creating an Internet facing website using...]]></description>
      <content:encoded><![CDATA[<p>During an onsite visit at a customer who were very busy at creating an Internet facing website using SharePoint 2010,&#160; I was asked if the technique that was described by my buddy <a href="http://www.sharepointnutsandbolts.com/" target="_blank">Chris O’Brien</a> to prevent the loading of unnecessary .js files was supported yes or not. And if not, if Microsoft had an alternative. Needless to say that the approach that Chris took was not really that supported by Microsoft (modifying the HttpContext and using Reflection are not really that great to be supporting right ;) </p>  <p>If you are really wondering what this post is about, I strongly recommend reading Chris’s post “<a title="Eliminating large JS files to optimize SharePoint 2010 internet sites" href="http://www.sharepointnutsandbolts.com/2011/01/eliminating-large-js-files-to-optimize.html">Eliminating large JS files to optimize SharePoint 2010 internet sites</a>“ on why you don’t want to load the all .js that are used by SharePoint 2010 files for anonymous facing websites.     <br /></p>  <h1>How this stuff works within Microsoft?</h1>  <p>However, it took some challenges to figure this one out. I would like to give you an insight how stuff works within Microsoft on how to get something like this be officially supported yes/no.    <br />First of all, the only team responsible for saying that something is supported or not, is the Product Group (PG). </p>  <p>To get such a statement the following happens:</p>  <ul>   <li>PFE (that’s me) researches if there is a related (kb) article to support the question of the answer, if nothing found, he escalates this to the Account Manager of the customer who then raises a ticket for a Request for Collaboration. </li>    <li>Technical Lead will craft a <strong>R</strong>equest <strong>f</strong>or <strong>C</strong>ollaboration with the PG </li>    <li>RFC goes to an Escalation Engineer that maintains this communication with the PG </li>    <li>PG responds with an answer, while they are extremely busy with developing the next version of SharePoint </li>    <li>RFC goes back to the Escalation Engineer and he/she communicates this with the Technical Lead and the involved on-site engineer (that’s me) to see if the answer is the desired one </li> </ul>  <p>As you may have noticed, I (as a Premier Field Engineer) don’t have a direct line with the PG. It’s not that I can call the developer lead of the WCM piece of the platform to give me an answer to something like this or why something is implemented as it is, this is of course for good reason ;)    <br />I just wanted to point out how many steps are involved and that such a process can take up quite the time to be finished.</p>  <p>&#160;</p>  <h1></h1>  <h1>The solution</h1>  <p>Sorry to have keep you waiting, however, below is the code by utilizing Chris’s solution, to prevent the registration and downloading of the .js files.</p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Consolas"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><font color="#0000ff"><font style="font-size: 9.5pt">protected</font></font></span><font style="font-size: 9.5pt"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"> </span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><font color="#0000ff">override</font></span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"> </span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><font color="#0000ff">void</font></span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"> OnPreRender(</span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><font color="#2b91af">EventArgs</font></span></font><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><font style="font-size: 9.5pt"> e)</font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><font face="Consolas"><font style="font-size: 9.5pt">{</font></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Consolas"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><span style="mso-spacerun: yes"><font style="font-size: 9.5pt">&#160;&#160;&#160; </font></span></span><font style="font-size: 9.5pt"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><font color="#0000ff">if</font></span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"> (!</span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><font color="#2b91af">HttpContext</font></span></font><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><font style="font-size: 9.5pt">.Current.User.Identity.IsAuthenticated)</font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><font face="Consolas"><span style="mso-spacerun: yes"><font style="font-size: 9.5pt">&#160;&#160;&#160; </font></span><font style="font-size: 9.5pt">{</font></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Consolas"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><span style="mso-spacerun: yes"><font style="font-size: 9.5pt">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span></span><font style="font-size: 9.5pt"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><font color="#0000ff">this</font></span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white">.Controls.Add(</span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><font color="#0000ff">new</font></span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"> </span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><font color="#2b91af">LiteralControl</font></span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white">(</span><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><font color="#a31515">&quot;&lt;script type='text/javascript'&gt;SP.SOD.set_prefetch(0);&lt;/script&gt;&quot;</font></span></font><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><font style="font-size: 9.5pt">));</font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><font face="Consolas"><span style="mso-spacerun: yes"><font style="font-size: 9.5pt">&#160;&#160;&#160; </font></span><font style="font-size: 9.5pt">}</font></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><font face="Consolas"><font style="font-size: 9.5pt">&#160;</font></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Consolas"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><span style="mso-spacerun: yes"><font style="font-size: 9.5pt">&#160;&#160;&#160; </font></span></span><font style="font-size: 9.5pt"><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><font color="#0000ff">base</font></span></font><span style="background-image: none; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><font style="font-size: 9.5pt">.OnPreRender(e);</font></span></font></p>  <p style="line-height: 13pt; margin: 0in 0in 10pt" class="MsoNormal"><span style="background-image: none; line-height: 11pt; background-attachment: scroll; background-repeat: repeat; font-family: ; background-position: 0% 0%; color: ; mso-highlight: white"><font face="Consolas"><font style="font-size: 9.5pt">}</font></font></span></p>  <p style="line-height: 13pt; margin: 0in 0in 10pt" class="MsoNormal">There you have it, by just calling a (yet) undocumented SharePoint JSOM call, will result in SharePoint not loading and registering the .js files. This method is however a public API which you can use for this particular reason.    <br />The only you need to make sure is that this control is near the <strong>bottom</strong> of the page and not on top of the page like Chris explains in his post.</p>  <h1>Really?</h1>  <p>Yes, really, this is the solution. The question is, what does it actually do?    <br />Well, it just stops the <strong>pre</strong>fetching from happening. The only time the .js files are loaded is when a control is asking for it, meaning that you really should test if <strong>everything</strong> still works on your page when implementing this and you use a control that is dependent on a SharePoint .js file. Furthermore there is maybe a performance penalty you need to pay when you are 'synchronously’ downloading that particular .js file.     <br />    <br />Also, please make note, like Chris is also explaining in his post, it’s not just the downloading of the .js files that is the issue, it’s also the manipulating of the DOM that is being prevented which results in a page that is loaded quicker and feels ‘snappier’ as well.</p>  <p>As confirmed by both <a href="http://www.sharepointnutsandbolts.com" target="_blank">Chris O’Brien</a> and <a href="http://blog.mastykarz.nl/" target="_blank">Waldek Mastykarz</a> who are (to me at least :) the WCM gurus.</p>]]></content:encoded>
    </item>
    <item>
      <title>Optimizing SQL for SharePoint</title>
      <link>https://docs.microsoft.com/archive/blogs/rmeure/optimizing-sql-for-sharepoint</link>
      <pubDate>Fri, 23 Dec 2011 01:53:10 GMT</pubDate>
      <dc:creator><![CDATA[Robin Meuré]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/rmeure/2011/12/23/optimizing-sql-for-sharepoint/</guid>
      <description><![CDATA[Introduction  When I do Risk Assessments (that’s the proactive side of my job, rather than fixing...]]></description>
      <content:encoded><![CDATA[<h1>Introduction</h1>  <p>When I do Risk Assessments (that’s the proactive side of my job, rather than fixing issues, I’m trying to prevent issues from happening :) at customers, certain things always popup when it comes to the configuration of SQL server and I wanted to share these things with you so hopefully this things won’t be flagged when I come along for a Risk Assessment at your place&#160; ;) I will cover the top two SharePoint-SQL ‘issues’ I find most at customers:</p>  <ol>   <li>MAXDOP </li>    <li>AUTO_UPDATE_STATISTICS &amp; AUTO_CREATE_STATISTICS </li> </ol>  <h1>MAXDOP</h1>  <p>MAXDOP should be set to 1 on the SQL Server instance.. why? Because the SharePoint Product Group says so.. ! But Robin hang on.. WTH is MAXDOP? MAXDOP stands for Max Degree of Parallelism, let me quote a MSDN article which describes this setting best:</p>  <blockquote>   <p>When SQL Server runs on a computer with more than one microprocessor or CPU, it detects the best degree of parallelism, that is, <strong>the number of processors employed to run a single statement, for each parallel plan execution</strong>. You can use the max degree of parallelism option to limit the number of processors to use in parallel plan execution. To enable the server to determine the maximum degree of parallelism, set this option to 0, the default value. Setting maximum degree of parallelism to 0 allows SQL Server to use all the available processors up to 64 processors. To suppress parallel plan generation, set max degree of parallelism to 1. Set the value to a number greater than 1 to restrict the maximum number of processors used by a single query execution. The maximum value for the degree of parallelism setting is controlled by the edition of SQL Server, CPU type, and operating system. If a value greater than the number of available processors is specified, the actual number of available processors is used. If the computer has only one processor, the max degree of parallelism value is ignored. Source : <a title="http://msdn.microsoft.com/en-us/library/ms181007.aspx" href="http://msdn.microsoft.com/en-us/library/ms181007.aspx">http://msdn.microsoft.com/en-us/library/ms181007.aspx</a>&#160;</p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/0576.image_54C6B4CA.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/0576.image_5F00_54C6B4CA.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/1731.image_thumb_655EAFB8.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/1731.image_5F00_thumb_5F00_655EAFB8.png" width="539" height="484" /></a></p> </blockquote>  <p>Makes sense? In very short it comes down that SQL Server can utilize the amount of processors that are available to execute the queries in parallel and thus very efficiently. Now this does sound like a very cool nifty feature eh? It actually is.. however, sometimes SharePoint tries to produce some ad-hoc SQL queries where SQL Server has no clue what the most optimal path could be and thus it could lead to bad performance when it tries to utilize all the processors that are available. Furthermore, the PG has tested a lot with variable settings and came to the conclusion to <strong>NOT </strong>to use MAXDOP&#160; is the most stable and performing way. And, when MAXDOP can be helpful, it is stated in the stored procedure itself.&#160; <br />    <br />Now, why this is not done at most installations is most probably because a) it’s the default setting when installing SQL Server and b) although it is listed in TechNet article, it is just an one-liner in the section called “Set SQL Server options” at “Storage and SQL Server capacity and configuration (SharePoint Server 2010)” which you can read about here <a title="http://technet.microsoft.com/en-us/library/cc298801.aspx" href="http://technet.microsoft.com/en-us/library/cc298801.aspx">http://technet.microsoft.com/en-us/library/cc298801.aspx</a> and c) setting MAXDOP to be 0 (or any number other 1) is actually a SQL Best Practice, hence the default value.</p>  <p>And here is a blog post proofing that MAXDOP set to 0 was not good idea and by setting it to 1 solved the issue (please note that this post is about SharePoint 2007) <a title="http://blogs.msdn.com/b/grahamk/archive/2009/06/15/troubleshooting-sql-server-deadlocks-and-performance-when-running-sharepoint.aspx" href="http://blogs.msdn.com/b/grahamk/archive/2009/06/15/troubleshooting-sql-server-deadlocks-and-performance-when-running-sharepoint.aspx">http://blogs.msdn.com/b/grahamk/archive/2009/06/15/troubleshooting-sql-server-deadlocks-and-performance-when-running-sharepoint.aspx</a>&#160;</p>  <p>&#160;</p>  <h1>AUTO_UPDATE_STATISTICS &amp; AUTO_CREATE_STATISTICS</h1>  <p>There is lot of confusion and discussion about these two settings that are set per database. The reason for the confusion is, that these settings are different per SharePoint version, for SharePoint 2007 it is recommended to enable AUTO_UPDATE_STATISTICS &amp; AUTO_CREATE_STATISTICS.. <strong>However</strong>, since the release of SP2 for SharePoint 2007, the product team introduced a new timerjob called “Database statistics” which itself takes care in <strong>updating</strong> the statistics for the databases. This timerjob is also available in SharePoint 2010 therefore we recommended <strong>disabling</strong> AUTO_UPDATE_STATISTICS. When a new content database is created, the AUTO_CREATE_STATISTICS is set to be <strong>disabled</strong> which is the recommendation. It can happen, after a migration from SharePoint 2007 to 2010, that this option is still enabled and therefore should be set to <strong>disabled</strong> as well.</p>  <p>In short, SharePoint 2010, both should be set to be <strong>disabled. </strong>For SharePoint 2007, it is recommended to have them both <strong>enabled</strong>. </p>  <p>And just to be clear, it is all about “<strong>AUTO</strong>”, it does not mean that the statistics are never updated. It’s just that SQL Server itself is not responsible anymore to do the updating, instead we have SharePoint that is responsible for it.</p>  <p>For more detail and information, please read this post <a title="http://blogs.msdn.com/b/chunliu/archive/2011/11/17/auto-update-statistics-and-auto-create-statistics-on-or-off-for-sharepoint-2010-databases.aspx" href="http://blogs.msdn.com/b/chunliu/archive/2011/11/17/auto-update-statistics-and-auto-create-statistics-on-or-off-for-sharepoint-2010-databases.aspx">http://blogs.msdn.com/b/chunliu/archive/2011/11/17/auto-update-statistics-and-auto-create-statistics-on-or-off-for-sharepoint-2010-databases.aspx</a> that covers all the information on the SharePoint 2010 databases side.</p>  <p>&#160;</p>  <h1></h1>  <h1>Recommended reading</h1>  <ul>   <li>Database Maintenance for Microsoft SharePoint 2010 Products <a title="http://www.microsoft.com/download/en/details.aspx?id=24282" href="http://www.microsoft.com/download/en/details.aspx?id=24282">http://www.microsoft.com/download/en/details.aspx?id=24282</a> by Bill Bear and Bryan Porter </li> </ul>]]></content:encoded>
    </item>
    <item>
      <title>Qx events in the Developer Dashboard</title>
      <link>https://docs.microsoft.com/archive/blogs/rmeure/qx-events-in-the-developer-dashboard</link>
      <pubDate>Tue, 13 Dec 2011 14:32:01 GMT</pubDate>
      <dc:creator><![CDATA[Robin Meuré]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/rmeure/2011/12/13/qx-events-in-the-developer-dashboard/</guid>
      <description><![CDATA[Introduction  What’s one the first things you will turn on when you are troubleshooting performance...]]></description>
      <content:encoded><![CDATA[<h1>Introduction</h1>  <p>What’s one the first things you will turn on when you are troubleshooting performance problems? Right.. the awesomely Developer Dashboard! (honestly, I cannot comprehend on how troubleshooting was done in the 2003/2007 time.. respect! :)    <br />I actually assuming that you know what it is, so I won’t go over what it actually is other than it helps you in finding out if the performance problems are:</p>  <ol>   <li>in SharePoint or custom code </li>    <li>in SQL </li>    <li>on the client (if the dashboard is saying it’s done within 50ms and your browser (IE + Developer Toolbar or Firefox + Firebug) or Netmon that it is taking +150ms than its something between the WFE and the client..) </li> </ol>  <p>&#160;</p>  <h1></h1>  <h1></h1>  <h1>Qx events?</h1>  <p>While being on-site this week, the first priority was to check for some performance problems they were having on one of their environments. So, first thing I asked was, if they could turn on the Developer Dashboard. When browsing to some sites I indeed noticed the slow performance and to my surprise saw some events that I’ve never seen before in the dashboard. Maybe you also haven’t (or if you were me and try searched for it and found nothing) you’re in luck now ;)    <br /></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/8547.image_3478C26A.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/8547.image_5F00_3478C26A.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/2262.image_thumb_338010E6.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/2262.image_5F00_thumb_5F00_338010E6.png" width="798" height="351" /></a></p>  <p>Just to set the right expectation, I’m not talking about Audi’s Q3 or Q5 or even the Q7.. I’m talking about the Q2 and Q3 events that are listed in the screenshot above, 21205ms is quite a long time to be spent in the database right? Luckily, in a strange sort of way, reproducing this was quite easy since every page request resulted in such long running database queries. Therefore, we could setup a SQL Profiler trace to see what was going on behind the scenes.. however, I found <strong>nothing </strong>in the trace that corresponded to the 20s the developer dashboard was telling me with the Q2 message.     <br />So I fired up the ULSViewer again, this time to check more thoroughly what exactly was happening by using the correlation ID. What I found was the following:</p>  <ul>   <li>Last message <strong>before</strong> the 20s delay&#160; : Current user before SqlConnection.Open: Name: DOMAIN\USERNAME SID: S-X-X-XX-XXXXXXXXX-XXXXXXXXX-XXXXXXXX-XXXXX ImpersonationLevel: None </li>    <li>First message <strong>after</strong> the 20s delay : System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) </li>    <li>More detailed message&#160; : Failure checking user access permissions for User Profile Application Proxy 'User Profile Service Proxy'. Exception: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) </li> </ul>  <p>That’s why we have such slow pages, a request is being made to a SQL Server from a environment which cannot be reached because of VLAN configuration. Since this was a QA farm, it was accidently pointing to a Production farm due to a misconfiguration in the QA farm. Problem fixed ;)</p>  <p>In the meantime, I got word from the one of the developers of the Developer Dashboard (that’s really one of the coolest things of working for Microsoft ;) stating that whenever a ‘Q’ message is listed it is because of the following :</p>  <blockquote>   <p>Q stands for query.&#160; Sometimes, we know that there has been a SQL query, but don’t want to store the SQL text or callstack.&#160; For example, if you have a page with more than 50 SQL queries, that’s your problem.&#160; Getting details on the 51<sup>st</sup> query just isn’t worth the server processing costs.       <br />Plus, we fall to a catch block which <strong>omits </strong>the detailed logging information <strong>if the connection fails</strong>.</p> </blockquote>  <h1>Conclusion</h1>  <p>So there you have it! Once more a proof that the developer dashboard is awesome and the answer to what the Qx messages mean ;)</p>]]></content:encoded>
    </item>
    <item>
      <title>SharePoint Search and performance</title>
      <link>https://docs.microsoft.com/archive/blogs/rmeure/sharepoint-search-and-performance</link>
      <pubDate>Tue, 13 Sep 2011 23:00:47 GMT</pubDate>
      <dc:creator><![CDATA[Robin Meuré]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/rmeure/2011/09/13/sharepoint-search-and-performance/</guid>
      <description><![CDATA[Introduction  During a CritSit, I came across a very interesting problem that was related to the...]]></description>
      <content:encoded><![CDATA[<h3></h3>  <h2>Introduction</h2>  <p>During a CritSit, I came across a very interesting problem that was related to the Search Service. Before I arrived onsite, this was the scope to solve the issue:</p>  <blockquote>   <p>We will consider this case solved and ready to be closed once we provide the information on how the numbers of items crawled will affect your search web part.</p> </blockquote>  <p>Ok, so if you have some experience using search in your custom code, you are aware of the fact that the search is actually pretty well performing no matter the amount of items in the index right? I mean, it’s the thing I evangelize at customers when they want to aggregate data because it’s <strong>the </strong>way to get data from everywhere (cross sitecollection/webapplication) in your environment in a very fast way, security trimmed and all! </p>  <p>But….. there are some things you should think about when dealing with LARGE amount of data. When dealing with 10.000+ items as result sets, it becomes (even) more important to create efficient queries and try to avoiding using “Order By” on non optimized fields (just consider the Order by to be EVIL ;)</p>  <h2>Testing SharePoint Search</h2>  <p>Let’s take a look at the performance of the following query against different number of items in the index by using the following test scenario :</p>  <ul>   <li>An announcement List that holds an x amount of announcements, where x will be 1000, 10.000, 100.000;      <ul>       <li>Order by Rank query :&#160; <ul>           <li>Select Title, Rank, Size, Description, Write, Path, contentclass              <br />FROM Scope() where contentclass = 'STS_ListItem_Announcements'               <br />Order by 'Rank' </li>         </ul>       </li>        <li>Order by Write query :          <ul>Select Title, Rank, Size, Description, Write, Path, contentclass            <br />FROM Scope() where contentclass = 'STS_ListItem_Announcements'             <br />Order by 'Write'</ul>       </li>        <li>No order by query :          <ul>Select Title, Rank, Size, Description, Write, Path, contentclass            <br />FROM Scope() where contentclass = 'STS_ListItem_Announcements'             <br /></ul>       </li>     </ul>   </li> </ul>  <p>   <br />First, I’ve added 1000 items to the list and then performed each query 10 times in a row.</p>  <table style="border-collapse: collapse" border="0" cellspacing="0" cellpadding="0" width="569"><colgroup><col style="width: 96pt; mso-width-source: userset; mso-width-alt: 4681" width="128" /><col style="width: 116pt; mso-width-source: userset; mso-width-alt: 5668" width="155" /><col style="width: 94pt; mso-width-source: userset; mso-width-alt: 4571" width="125" /></colgroup><tbody>     <tr style="height: 15pt" height="20">       <td style="border-bottom: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; background-color: #eeece1; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; padding-top: 1px" class="xl70" height="20" width="157"><strong>Search Query</strong></td>        <td style="border-bottom: windowtext 0.5pt solid; background-color: #eeece1; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; padding-top: 1px" class="xl71" width="131"><strong>1000 Order by Rank</strong></td>        <td style="border-bottom: windowtext 0.5pt solid; background-color: #eeece1; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; padding-top: 1px" class="xl71" width="153"><strong>1000 (Order by &quot;Write&quot;)</strong></td>        <td style="border-bottom: windowtext 0.5pt solid; background-color: #eeece1; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl72" width="127"><strong>1000 (No Order by)</strong></td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20" width="157">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="131" align="right">321</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="153" align="right">470</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" width="127" align="right">338</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20" width="157">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="131" align="right">320</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="153" align="right">438</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" width="127" align="right">304</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20" width="157">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="131" align="right">449</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="153" align="right">421</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" width="127" align="right">331</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20" width="157">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="131" align="right">326</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="153" align="right">363</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" width="127" align="right">288</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20" width="157">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="131" align="right">326</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="153" align="right">392</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" width="127" align="right">298</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20" width="157">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="131" align="right">372</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="153" align="right">389</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" width="127" align="right">361</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20" width="157">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="131" align="right">325</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="153" align="right">417</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" width="127" align="right">291</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20" width="157">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="131" align="right">339</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="153" align="right">410</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" width="127" align="right">310</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20" width="157">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="131" align="right">361</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="153" align="right">370</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" width="127" align="right">334</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20" width="157">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="131" align="right">354</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="153" align="right">393</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" width="127" align="right">338</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-bottom: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; padding-top: 1px" class="xl67" height="20" width="157"><strong>Average duration (in ms)</strong></td>        <td style="border-bottom: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; padding-top: 1px" class="xl68" width="131" align="right">349.3</td>        <td style="border-bottom: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; padding-top: 1px" class="xl68" width="153" align="right">406.3</td>        <td style="border-bottom: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl69" width="127" align="right">319.3</td>     </tr>   </tbody></table>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/5850.image_638,4.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/5850.image_5F00_6382C004.png"><img style="display: inline" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/3223.image_thumb_025933E3.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/3223.image_5F00_thumb_5F00_025933E3.png" width="481" height="289" /></a></p>  <p>Then I added 9000 items more, which results in 10.000 items in one list. After the crawl and then by rerunning the same query, the following outcome was the result:</p>  <table style="border-collapse: collapse" border="0" cellspacing="0" cellpadding="0" width="584"><colgroup><col style="width: 96pt; mso-width-source: userset; mso-width-alt: 4681" width="128" /><col style="width: 116pt; mso-width-source: userset; mso-width-alt: 5668" width="155" /><col style="width: 94pt; mso-width-source: userset; mso-width-alt: 4571" width="125" /></colgroup><tbody>     <tr style="height: 15pt" height="20">       <td style="border-bottom: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; background-color: #ddd9c4; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; padding-top: 1px" class="xl70" height="20" width="128"><strong>Search Query</strong></td>        <td style="border-bottom: windowtext 0.5pt solid; background-color: #ddd9c4; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; padding-top: 1px" class="xl71" width="154"><strong>10000 Order by Rank</strong></td>        <td style="border-bottom: windowtext 0.5pt solid; background-color: #ddd9c4; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; padding-top: 1px" class="xl71" width="172"><strong>10000 Order by &quot;Write)</strong></td>        <td style="border-bottom: windowtext 0.5pt solid; background-color: #ddd9c4; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl72" width="128"><strong>10000 No Order by</strong></td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">243</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="172" align="right">1705</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" width="128" align="right">266</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">261</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="172" align="right">1529</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" width="128" align="right">380</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">247</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="172" align="right">1411</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" width="128" align="right">248</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">270</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="172" align="right">1418</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" width="128" align="right">263</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">242</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="172" align="right">1507</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" width="128" align="right">252</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">303</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="172" align="right">1705</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" width="128" align="right">282</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">256</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="172" align="right">1693</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" width="128" align="right">255</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">261</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="172" align="right">1697</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" width="128" align="right">285</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">236</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="172" align="right">1699</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" width="128" align="right">242</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">277</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" width="172" align="right">1625</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" width="128" align="right">301</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-bottom: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; padding-top: 1px" class="xl67" height="20"><strong>Average duration</strong></td>        <td style="border-bottom: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; padding-top: 1px" class="xl68" align="right">259.6</td>        <td style="border-bottom: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; padding-top: 1px" class="xl68" width="172" align="right">1598.9</td>        <td style="border-bottom: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl69" width="128" align="right">277.4</td>     </tr>   </tbody></table>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/1134.image_212FA7C1.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/1134.image_5F00_212FA7C1.png"><img style="display: inline" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/6332.image_thumb_6DF36E57.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/6332.image_5F00_thumb_5F00_6DF36E57.png" width="481" height="289" /></a></p>  <p>&#160;</p>  <p>Then when adding an additional 90.000 items to have 100.000 items in the list, we get the following results </p>  <table style="border-collapse: collapse" border="0" cellspacing="0" cellpadding="0" width="558"><colgroup><col style="width: 96pt; mso-width-source: userset; mso-width-alt: 4681" width="128" /><col style="width: 106pt; mso-width-source: userset; mso-width-alt: 5156" width="141" /><col style="width: 120pt; mso-width-source: userset; mso-width-alt: 5851" width="160" /><col style="width: 97pt; mso-width-source: userset; mso-width-alt: 4717" width="129" /></colgroup><tbody>     <tr style="height: 15pt" height="20">       <td style="border-bottom: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; background-color: #ddd9c4; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; padding-top: 1px" class="xl70" height="20" width="128"><strong>Search Query</strong></td>        <td style="border-bottom: windowtext 0.5pt solid; background-color: #ddd9c4; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; padding-top: 1px" class="xl71" width="141"><strong>100000 Order by Rank</strong></td>        <td style="border-bottom: windowtext 0.5pt solid; background-color: #ddd9c4; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; padding-top: 1px" class="xl71" width="160"><strong>100000 Order by &quot;Write)</strong></td>        <td style="border-bottom: windowtext 0.5pt solid; background-color: #ddd9c4; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl72" width="129"><strong>100000 No Order by</strong></td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">317</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">3666</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" align="right">156</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">314</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">3654</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" align="right">189</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">309</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">3948</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" align="right">205</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">294</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">3689</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" align="right">197</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">300</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">3735</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" align="right">196</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">289</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">3971</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" align="right">175</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">341</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">3736</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" align="right">172</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">329</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">3608</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" align="right">163</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">356</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">3748</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" align="right">169</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" class="xl65" height="20">&#160;</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">359</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; padding-top: 1px" align="right">3701</td>        <td style="padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl66" align="right">164</td>     </tr>      <tr style="height: 15pt" height="20">       <td style="border-bottom: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; padding-top: 1px" class="xl67" height="20"><strong>Average duration</strong></td>        <td style="border-bottom: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; padding-top: 1px" class="xl68" align="right">320.8</td>        <td style="border-bottom: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; padding-top: 1px" class="xl68" align="right">3745.6</td>        <td style="border-bottom: windowtext 0.5pt solid; padding-left: 1px; padding-right: 1px; vertical-align: bottom; border-top: windowtext 0.5pt solid; border-right: windowtext 0.5pt solid; padding-top: 1px" class="xl69" align="right">178.6</td>     </tr>   </tbody></table>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/4375.image_30EF3CC5.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/4375.image_5F00_30EF3CC5.png"><img style="display: inline" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/3386.image_thumb_4FC5B0A3.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/3386.image_5F00_thumb_5F00_4FC5B0A3.png" width="481" height="289" /></a></p>  <p>&#160;</p>  <p>As you can see in the tables and the graphs, the search results coming back from the “Order by Rank” and “No Order by” stay relatively the same. However, there is quite a big difference in the performance when we are using another column for the ‘Order by’. The reason for this is, even though we set a RowLimit, this RowLimit is only important for the amount of results being returned. In order to give back a good search result, the entire index has to be queried and those results are ‘ordered by’ internally using the specified column. Because this column is not very optimized (it’s like doing a string compare on every row returned) it’s takes a lot of time for the results to be returned. </p>  <p>To prove my point, here is the graph of the Backend Query Latency, where it shows that most of the time is spent in the Property Store</p>  <p style="line-height: 13pt; margin: 0in 0in 10pt" class="MsoNormal"><span style="z-index: 251669504; position: absolute; margin-top: 201px; width: 109px; height: 50px; margin-left: 91px; mso-ignore: vglayout"></span><span style="mso-no-proof: yes"></span><span style="mso-no-proof: yes"></span><span style="mso-no-proof: yes"></span></p>  <p style="line-height: 13pt; margin: 0in 0in 10pt" class="MsoNormal"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/5758.image_4A76C9F2.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/5758.image_5F00_4A76C9F2.png"><img style="display: inline" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/2625.image_thumb_218BB4E9.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/2625.image_5F00_thumb_5F00_218BB4E9.png" width="634" height="492" /></a></p>  <p>So, what can we do about it? There are two basic things:</p>  <ol>   <li><strong>Refactor the Query</strong>. Most of the time, if we don’t really care about the relevance of the result, we want to order the results on DateTime like&#160; ‘last modified’. Now, this means that we don’t actually need every record from the index that was like uploaded three years ago right? (it’s like the same as going to page 503 on the search results page of your favorite online search engine :). So we are going to narrow down the results that will be returned by appending this to the query “AND Write &gt; '2011-1-1' AND Write &lt; ‘2011-2-1’ “ will narrow down the results to only get the items from 1st of January 2011 and 1st of February 2011 (or ‘last month’). Likewise we can do same for something like ‘last week’ by using this “AND Write &gt; '2011-1-1' AND Write &lt; ‘2011-1-7’” (depending on the culture settings, the notation of the datetime is like this : Year-Month-Day')       <br />In our test scenario, I used the following query “<em>SELECT Title, Rank, Write, Path, contentclass FROM Scope() where contentclass = 'STS_ListItem_Announcements' AND write = '2011-8-29 12:29:00' ORDER BY write</em>”<strong>. This query gave me back 1000 items with an average of <strong>180ms</strong>(!!!), quite a big performance gain right? ;) </strong>(The reason for the specific time is because I used ProcessBatchdata to add my announcement items, meaning that using only the date will still return 100.000 items) </li>    <li><strong>Do the ordering/sorting in memory, </strong>a second option is to use the Rank for getting the results back based on their relevancy and <strong>then</strong> do ordering/sorting in memory in code like you would when sorting/ordering a custom collection or DataTable. <strong>But please note</strong> that doing this might affect the data integrity since the results were not ordered on that column/field but on the Rank column. </li>    <li><strong>Have dedicated disks (SSD) for every Property Store Database, </strong>if you didn’t already knew, the search databases are the databases that actually require the most disk i/o throughput so it maybe worth looking into how good the disks on SQL Server are doing. A good read on the whole SAN discussion can be found at Ryan Campbell’s blogpost <a title="http://blogs.technet.com/b/rycampbe/archive/2011/08/23/virtualization-the-san-and-why-one-big-raid-5-array-is-wrong.aspx" href="http://blogs.technet.com/b/rycampbe/archive/2011/08/23/virtualization-the-san-and-why-one-big-raid-5-array-is-wrong.aspx">http://blogs.technet.com/b/rycampbe/archive/2011/08/23/virtualization-the-san-and-why-one-big-raid-5-array-is-wrong.aspx</a> </li> </ol>  <p>&#160;</p>  <h2>Conclusion</h2>  <p>So, to conclude, this is how provided the customer with the facts on how the number of&#160; items being crawled can impact the performance of SharePoint Search if you use another column/field for doing the Order By on. The recommendation was to refactor the query I just mentioned and also to talk to the SAN team since they were claiming performance that wasn’t met when we did the testing.</p>]]></content:encoded>
    </item>
    <item>
      <title>Unexpected Query Execution Failure</title>
      <link>https://docs.microsoft.com/archive/blogs/rmeure/unexpected-query-execution-failure</link>
      <pubDate>Fri, 10 Jun 2011 05:45:52 GMT</pubDate>
      <dc:creator><![CDATA[Robin Meuré]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/rmeure/2011/06/10/unexpected-query-execution-failure/</guid>
      <description><![CDATA[If you use your favorite search engine to search on the following error     Unexpected query...]]></description>
      <content:encoded><![CDATA[<p>If you use your favorite search engine to search on the following error</p>  <blockquote>   <p>Unexpected query execution failure, error code 282. Additional error information from SQL Server is included below. &quot;The 'proc_GetTpWebMetaDataAndListMetaData' procedure attempted to return a status of NULL, which is not allowed. A status of 0 will be returned instead.&quot; Query text (if available): &quot;{?=call proc_GetTpWebMetaDataAndListMetaData(?,'33B57EA5-A6C2-43EF-9647-7273C62A485E',?,NULL,1,?,?,6187)}&quot;&#160;&#160;&#160;&#160; </p> </blockquote>  <p>you most likely find blog/forum posts that are about SSRS integration. However, there is also another thing that can cause this issue to be reported in the ULS. Before we cover that, let’s take a look at the stored procedure. If you take a look at the following article <a title="http://msdn.microsoft.com/en-us/library/dd302800(PROT.13).aspx" href="http://msdn.microsoft.com/en-us/library/dd302800(PROT.13).aspx">http://msdn.microsoft.com/en-us/library/dd302800(PROT.13).aspx</a> that describes what the Stored Procedure proc_GetTpWebMetaDataAndListMetaData is all about. The thing that we are interested in, is the return value, it states “<em>The proc_GetTpWebMetaDataAndListMetaData stored procedure returns an integer return code ,which MUST be in the following table</em>”<em>, </em>now in our case, for some unknown reason a NULL value is returned instead of a integer. That’s why SQL is complaining and thus we are getting the error in the ULS.</p>  <p>So, how do we get the error in the ULS? If you take a look at the following piece of code:</p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#2b91af"><font style="font-size: 10pt">SPSite</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> site = <span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">SPSite</font></span>(<span style="color: "><font color="#a31515">&quot;http://test&quot;</font></span>);</font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#2b91af"><font style="font-size: 10pt">SPWeb</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> web = site.OpenWeb();</font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><span style="mso-spacerun: yes"><font face="Courier New"><font style="font-size: 10pt">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></font></span></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#2b91af"><font style="font-size: 10pt">SPListItem</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> firstItem = web.GetListItem(<span style="color: "><font color="#a31515">&quot;/Shared Documents/test.txt&quot;</font></span>);</font></span></font></p>  <p style="line-height: 13pt; margin: 0in 0in 10pt" class="MsoNormal"><font face="Courier New"><span style="line-height: 12pt; font-family: ; color: ; mso-no-proof: yes"><font color="#2b91af"><font style="font-size: 10pt">SPListItem</font></font></span><span style="line-height: 12pt; font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> secondItem = web.GetListItem(<span style="color: "><font color="#a31515">&quot;/Shared Documents/test.txt&quot;</font></span>);</font></span></font></p>  <p>We get the following error in the ULS:</p>  <p>0x15D0&#160;&#160;&#160; Windows SharePoint Services&#160;&#160;&#160;&#160;&#160;&#160; Database&#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; 6f8g&#160;&#160;&#160; Unexpected&#160;&#160;&#160; Unexpected query execution failure, error code 282. Additional error information from SQL Server is included below. &quot;The 'proc_GetTpWebMetaDataAndListMetaData' procedure attempted to return a status of NULL, which is not allowed. A status of 0 will be returned instead.&quot; Query text (if available): &quot;{?=call proc_GetTpWebMetaDataAndListMetaData(?,'33B57EA5-A6C2-43EF-9647-7273C62A485E',?,NULL,1,?,?,6187)}&quot;</p>  <p>Let’s see what’s happening on the SQL Server side by running a profile trace..</p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">exec</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> proc_GetTpWebMetaDataAndListMetaData <span style="color: "><font color="#ff0000">'AB835D50-E8E0-43EA-9DA9-98E63240D661'</font></span><span style="color: "><font color="#808080">,NULL,</font></span>N<span style="color: "><font color="#ff0000">'Shared Documents/test.txt'</font></span><span style="color: "><font color="#808080">,NULL,</font></span>1<span style="color: "><font color="#808080">,-</font></span>1<span style="color: "><font color="#808080">,</font></span>0x0105000000000005150000000965EBB84367A5FC5C4CD895F4010000<span style="color: "><font color="#808080">,</font></span>59</font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">exec</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> proc_GetListFields <span style="color: "><font color="#ff0000">'33B57EA5-A6C2-43EF-9647-7273C62A485E'</font></span><span style="color: "><font color="#808080">,</font></span></font><span style="color: "><font style="font-size: 10pt" color="#ff0000">'56FE5542-ED10-4D4B-B248-9009525BB736'</font></span></span></font></p>  <p style="line-height: 13pt; margin: 0in 0in 10pt" class="MsoNormal"><font face="Courier New"><span style="line-height: 12pt; font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">exec</font></font></span><span style="line-height: 12pt; font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> proc_GetTpWebMetaDataAndListMetaData <span style="color: "><font color="#ff0000">'AB835D50-E8E0-43EA-9DA9-98E63240D661'</font></span><span style="color: "><font color="#808080">,</font></span><span style="color: "><font color="#ff0000">'33B57EA5-A6C2-43EF-9647-7273C62A485E'</font></span><span style="color: "><font color="#808080">,</font></span>N<span style="color: "><font color="#ff0000">'Shared Documents/test.txt'</font></span><span style="color: "><font color="#808080">,NULL,</font></span>1<span style="color: "><font color="#808080">,</font></span>0<span style="color: "><font color="#808080">,</font></span>0x0105000000000005150000000965EBB84367A5FC5C4CD895F4010000<span style="color: "><font color="#808080">,</font></span>6187</font></span></font></p>  <p style="line-height: 13pt; margin: 0in 0in 10pt" class="MsoNormal">&#160;</p>  <p style="line-height: 13pt; margin: 0in 0in 10pt" class="MsoNormal">Now, unfortunately I’m not part of the product team so explaining why by calling the same method twice results in two different stored procedure calls is quite difficult. My only guess is that the first procedure set’s everything in place for any other calls that are made in the context we have.    <br />If I run the stored procedures (<strong>which you should never do!)</strong>&#160; this is difference between the two:</p>  <p style="line-height: 13pt; margin: 0in 0in 10pt" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">exec</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> proc_GetTpWebMetaDataAndListMetaData <span style="color: "><font color="#ff0000">'AB835D50-E8E0-43EA-9DA9-98E63240D661'</font></span><span style="color: "><font color="#808080">,NULL,</font></span>N<span style="color: "><font color="#ff0000">'Shared Documents/test.txt'</font></span><span style="color: "><font color="#808080">,NULL,</font></span>1<span style="color: "><font color="#808080">,-</font></span>1<span style="color: "><font color="#808080">,</font></span>0x0105000000000005150000000965EBB84367A5FC5C4CD895F4010000<span style="color: "><font color="#808080">,</font></span>59</font></span></font></p>  <p style="line-height: 13pt; margin: 0in 0in 10pt" class="MsoNormal"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/4035.image_54D62ACD.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/4035.image_5F00_54D62ACD.png"><img style="display: inline" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/2705.image_thumb_29BDF12E.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/2705.image_5F00_thumb_5F00_29BDF12E.png" width="640" height="417" /></a></p>  <p><font face="Courier New"><span style="line-height: 12pt; font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">exec</font></font></span><span style="line-height: 12pt; font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> proc_GetTpWebMetaDataAndListMetaData <span style="color: "><font color="#ff0000">'AB835D50-E8E0-43EA-9DA9-98E63240D661'</font></span><span style="color: "><font color="#808080">,</font></span><span style="color: "><font color="#ff0000">'33B57EA5-A6C2-43EF-9647-7273C62A485E'</font></span><span style="color: "><font color="#808080">,</font></span>N<span style="color: "><font color="#ff0000">'Shared Documents/test.txt'</font></span><span style="color: "><font color="#808080">,NULL,</font></span>1<span style="color: "><font color="#808080">,</font></span>0<span style="color: "><font color="#808080">,</font></span>0x0105000000000005150000000965EBB84367A5FC5C4CD895F4010000<span style="color: "><font color="#808080">,</font></span>6187</font></span></font></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/2620.image_43EE3485.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/2620.image_5F00_43EE3485.png"><img style="display: inline" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/1727.image_thumb_3D5AB4F5.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/1727.image_5F00_thumb_5F00_3D5AB4F5.png" width="640" height="83" /></a></p>  <p>Quite a different result right? So what happens if we modify the source code to get the context instead of creating our own..</p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#2b91af"><font style="font-size: 10pt">SPWeb</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> web = <span style="color: "><font color="#2b91af">SPContext</font></span>.Current.Web;</font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#2b91af"><font style="font-size: 10pt">SPListItem</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> firstItem = web.GetListItem(<span style="color: "><font color="#a31515">&quot;/Shared Documents/test.txt&quot;</font></span>);</font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#2b91af"><font style="font-size: 10pt">SPListItem</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> secondItem = web.GetListItem(<span style="color: "><font color="#a31515">&quot;/Shared Documents/test.txt&quot;</font></span>);</font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font size="2" face="Courier New"><span style="font-family: ; mso-no-proof: yes"></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal">&#160;</p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal">When running the profiler again, we get this stored procedures that are called:</p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal">&#160;</p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="line-height: 12pt; font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">exec</font></font></span><span style="line-height: 12pt; font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> proc_GetTpWebMetaDataAndListMetaData <span style="color: "><font color="#ff0000">'AB835D50-E8E0-43EA-9DA9-98E63240D661'</font></span><span style="color: "><font color="#808080">,</font></span><span style="color: "><font color="#ff0000">'33B57EA5-A6C2-43EF-9647-7273C62A485E'</font></span><span style="color: "><font color="#808080">,</font></span>N<span style="color: "><font color="#ff0000">'Shared Documents/test.txt'</font></span><span style="color: "><font color="#808080">,NULL,</font></span>1<span style="color: "><font color="#808080">,</font></span>0<span style="color: "><font color="#808080">,</font></span>0x0105000000000005150000000965EBB84367A5FC5C4CD895F4010000<span style="color: "><font color="#808080">,</font></span>6187</font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="line-height: 12pt; font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">exec</font></font></span><span style="line-height: 12pt; font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> proc_GetTpWebMetaDataAndListMetaData <span style="color: "><font color="#ff0000">'AB835D50-E8E0-43EA-9DA9-98E63240D661'</font></span><span style="color: "><font color="#808080">,</font></span><span style="color: "><font color="#ff0000">'33B57EA5-A6C2-43EF-9647-7273C62A485E'</font></span><span style="color: "><font color="#808080">,</font></span>N<span style="color: "><font color="#ff0000">'Shared Documents/test.txt'</font></span><span style="color: "><font color="#808080">,NULL,</font></span>1<span style="color: "><font color="#808080">,</font></span>0<span style="color: "><font color="#808080">,</font></span>0x0105000000000005150000000965EBB84367A5FC5C4CD895F4010000<span style="color: "><font color="#808080">,</font></span>6187</font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font size="2" face="Courier New"><span style="line-height: 12pt; font-family: ; mso-no-proof: yes"></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal">&#160;</p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal">Makes sense right? Since we already got the context, there is no need to set it, so far the theory is correct. But to my surprise now I got two errors in the ULS log.. </p>  <p>06/10/2011 11:41:21.13&#160;&#160;&#160;&#160; w3wp.exe (0x1C8C)&#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; 0x1BFC&#160;&#160;&#160; Windows SharePoint Services&#160;&#160;&#160;&#160;&#160;&#160; Database&#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; 6f8g&#160;&#160;&#160; Unexpected&#160;&#160;&#160; Unexpected query execution failure, error code 282. Additional error information from SQL Server is included below. &quot;The 'proc_GetTpWebMetaDataAndListMetaData' procedure attempted to return a status of NULL, which is not allowed. A status of 0 will be returned instead.&quot; Query text (if available): &quot;{?=call proc_GetTpWebMetaDataAndListMetaData(?,'33B57EA5-A6C2-43EF-9647-7273C62A485E',?,NULL,1,?,?,6187)}&quot;&#160;&#160;&#160;&#160; <br />06/10/2011 11:41:21.13&#160;&#160;&#160;&#160; w3wp.exe (0x1C8C)&#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; 0x1BFC&#160;&#160;&#160; Windows SharePoint Services&#160;&#160;&#160;&#160;&#160;&#160; Database&#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; 6f8g&#160;&#160;&#160; Unexpected&#160;&#160;&#160; Unexpected query execution failure, error code 282. Additional error information from SQL Server is included below. &quot;The 'proc_GetTpWebMetaDataAndListMetaData' procedure attempted to return a status of NULL, which is not allowed. A status of 0 will be returned instead.&quot; Query text (if available): &quot;{?=call proc_GetTpWebMetaDataAndListMetaData(?,'33B57EA5-A6C2-43EF-9647-7273C62A485E',?,NULL,1,?,?,6187)}&quot;&#160;&#160;&#160;&#160; </p>  <p>&#160;</p>  <p>In a way, this also makes sense, since the same stored procedure is executed twice.. so the question is, what is wrong with the values that are passed on by the stored procedure once the context has been set that SQL throws this error?    <br />What does SQL itself say when we run the stored procedure.. ?    <br /></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/7103.image_3BA9E921.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/7103.image_5F00_3BA9E921.png"><img style="display: inline" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/1346.image_thumb_1D0FF878.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/1346.image_5F00_thumb_5F00_1D0FF878.png" width="640" height="83" /></a></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/1323.image_1A545378.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/1323.image_5F00_1A545378.png"><img style="display: inline" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/0247.image_thumb_5A5ABD32.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/0247.image_5F00_thumb_5F00_5A5ABD32.png" width="640" height="107" /></a></p>  <p>&#160;</p>  <p>This means that something is returning a NULL value within the stored procedure.. So let’s take a look at <a title="http://msdn.microsoft.com/en-us/library/dd302800(v=PROT.13).aspx" href="http://msdn.microsoft.com/en-us/library/dd302800(v=PROT.13).aspx">http://msdn.microsoft.com/en-us/library/dd302800(v=PROT.13).aspx</a> that explains what all the different result sets can be.. By looking at what kind of results we got from SQL, we can identify the result set that is being returned is the List Identifier one (see <a title="http://msdn.microsoft.com/en-us/library/dd303701(v=PROT.13).aspx" href="http://msdn.microsoft.com/en-us/library/dd303701(v=PROT.13).aspx">http://msdn.microsoft.com/en-us/library/dd303701(v=PROT.13).aspx</a>) . To translate, the first column is the GUID of the List, the second column is the Type and the third one is the Row Identifier of the ListItem. By knowing this, we can look into the stored procedure and find out what section of the procedure is causing the NULL value to be returned.     <br />The piece of SQL below is the one responsible of returning the result set, if you look closely you will notice the following “<span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><span style="mso-spacerun: yes"><font style="font-size: 10pt"></font></span><font style="font-size: 10pt"><span style="color: "><font color="#0000ff">RETURN</font></span> @ret” </font></font></span>return statement… in my test case I took this piece of SQL and used the values that were passed on to the stored procedure like showed above and guess what..&#160; the @ret value was NULL .. so we found the cause! :)</p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @ret </font><span style="color: "><font style="font-size: 10pt" color="#0000ff">int</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @WebUrl <span style="color: "><font color="#0000ff">nvarchar</font></span><span style="color: "><font color="#808080">(</font></span>256</font><span style="color: "><font style="font-size: 10pt" color="#808080">)</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @WebDirName <span style="color: "><font color="#0000ff">nvarchar</font></span><span style="color: "><font color="#808080">(</font></span>256</font><span style="color: "><font style="font-size: 10pt" color="#808080">)</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @WebLeafName <span style="color: "><font color="#0000ff">nvarchar</font></span><span style="color: "><font color="#808080">(</font></span>128</font><span style="color: "><font style="font-size: 10pt" color="#808080">)</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @UserId </font><span style="color: "><font style="font-size: 10pt" color="#0000ff">int</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @UrlDirName <span style="color: "><font color="#0000ff">nvarchar</font></span><span style="color: "><font color="#808080">(</font></span>256</font><span style="color: "><font style="font-size: 10pt" color="#808080">)</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @UrlLeafName <span style="color: "><font color="#0000ff">nvarchar</font></span><span style="color: "><font color="#808080">(</font></span>128</font><span style="color: "><font style="font-size: 10pt" color="#808080">)</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @WebIdSelected </font><span style="color: "><font style="font-size: 10pt" color="#0000ff">uniqueidentifier</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @ListIdSelected </font><span style="color: "><font style="font-size: 10pt" color="#0000ff">uniqueidentifier</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @ItemLevelSelected </font><span style="color: "><font style="font-size: 10pt" color="#0000ff">tinyint</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @UrlIsListItem </font><span style="color: "><font style="font-size: 10pt" color="#0000ff">bit</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @RootWebId </font><span style="color: "><font style="font-size: 10pt" color="#0000ff">uniqueidentifier</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @UserInfoListId </font><span style="color: "><font style="font-size: 10pt" color="#0000ff">uniqueidentifier</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @TypeSelected </font><span style="color: "><font style="font-size: 10pt" color="#0000ff">int</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @ItemIdSelected </font><span style="color: "><font style="font-size: 10pt" color="#0000ff">int</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @WebSiteId </font><span style="color: "><font style="font-size: 10pt" color="#0000ff">uniqueidentifier</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @WebId </font><span style="color: "><font style="font-size: 10pt" color="#0000ff">uniqueidentifier</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @Url <span style="color: "><font color="#0000ff">nvarchar</font></span><span style="color: "><font color="#808080">(</font></span>260</font><span style="color: "><font style="font-size: 10pt" color="#808080">)</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @ListId </font><span style="color: "><font style="font-size: 10pt" color="#0000ff">uniqueidentifier</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @RunUrlToWebUrl <span style="color: "><font color="#0000ff">bit</font></span> </font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @DGCacheVersion </font><span style="color: "><font style="font-size: 10pt" color="#0000ff">bigint</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @SystemId tSystemId</font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">DECLARE</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @MetadataFlags <span style="color: "><font color="#0000ff">int</font></span> </font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">SET</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @UserId <span style="color: "><font color="#808080">=</font></span> 0</font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">SET</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @UrlIsListItem <span style="color: "><font color="#808080">=</font></span> 0</font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">SET</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @RootWebId <span style="color: "><font color="#808080">=</font></span> <span style="color: "><font color="#808080">NULL</font></span></font><span style="mso-tab-count: 1"><font style="font-size: 10pt">&#160;&#160; </font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">SET</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @WebSiteId<span style="mso-spacerun: yes">&#160; </span><span style="color: "><font color="#808080">=</font></span> </font><span style="color: "><font style="font-size: 10pt" color="#ff0000">'AB835D50-E8E0-43EA-9DA9-98E63240D661'</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">SET</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @WebId<span style="mso-spacerun: yes">&#160; </span><span style="color: "><font color="#808080">=</font></span> </font><span style="color: "><font style="font-size: 10pt" color="#ff0000">'33B57EA5-A6C2-43EF-9647-7273C62A485E'</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">SET</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @Url <span style="color: "><font color="#808080">=</font></span> N</font><span style="color: "><font style="font-size: 10pt" color="#ff0000">'Shared Documents/test.txt'</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">SET</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @ListId <span style="color: "><font color="#808080">=</font></span> </font><span style="color: "><font style="font-size: 10pt" color="#808080">NULL</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">SET</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @RunUrlToWebUrl<span style="mso-spacerun: yes">&#160; </span><span style="color: "><font color="#808080">=</font></span> 1</font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">SET</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @DGCacheVersion<span style="mso-spacerun: yes">&#160; </span><span style="color: "><font color="#808080">=</font></span> 0</font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">SET</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @SystemId <span style="color: "><font color="#808080">=</font></span> 0x0105000000000005150000000965EBB84367A5FC5C4CD895F4010000</font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">SET</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @MetadataFlags<span style="mso-spacerun: yes">&#160; </span><span style="color: "><font color="#808080">=</font></span> 6187</font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><font style="font-size: 10pt">&#160;</font></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">EXEC</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> proc_SplitUrl @Url<span style="color: "><font color="#808080">,</font></span> @UrlDirName <span style="color: "><font color="#0000ff">OUTPUT</font></span><span style="color: "><font color="#808080">,</font></span> @UrlLeafName </font><span style="color: "><font style="font-size: 10pt" color="#0000ff">OUTPUT</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">IF</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @UserId <span style="color: "><font color="#808080">=</font></span> 0</font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; color: ; mso-no-proof: yes"><font face="Courier New"><font style="font-size: 10pt" color="#0000ff">BEGIN</font></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&#160;&#160;&#160; </font></span><span style="color: "><font style="font-size: 10pt" color="#0000ff">SELECT</font></span></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span><font style="font-size: 10pt">@UserId <span style="color: "><font color="#808080">=</font></span> UserInfo<span style="color: "><font color="#808080">.</font></span>tp_Id</font></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&#160;&#160;&#160; </font></span><span style="color: "><font style="font-size: 10pt" color="#0000ff">FROM</font></span></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span><font style="font-size: 10pt">UserInfo <span style="color: "><font color="#0000ff">WITH</font></span><span style="color: "><font color="#808080">(</font></span>NOLOCK</font><span style="color: "><font style="font-size: 10pt" color="#808080">)</font></span></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&#160;&#160;&#160; </font></span><span style="color: "><font style="font-size: 10pt" color="#0000ff">WHERE</font></span></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span><font style="font-size: 10pt">UserInfo<span style="color: "><font color="#808080">.</font></span>tp_SiteId <span style="color: "><font color="#808080">=</font></span> @WebSiteId </font><span style="color: "><font style="font-size: 10pt" color="#808080">AND</font></span></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span><font style="font-size: 10pt">UserInfo<span style="color: "><font color="#808080">.</font></span>tp_SystemId <span style="color: "><font color="#808080">=</font></span> @SystemId</font></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; color: ; mso-no-proof: yes"><font face="Courier New"><font style="font-size: 10pt" color="#0000ff">END</font></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">SELECT</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> <span style="color: "><font color="#0000ff">TOP</font></span> 1</font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&#160;&#160;&#160; </font></span><font style="font-size: 10pt">@ListIdSelected <span style="color: "><font color="#808080">=</font></span> ListId</font><span style="color: "><font style="font-size: 10pt" color="#808080">,</font></span></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&#160;&#160;&#160; </font></span><font style="font-size: 10pt">@TypeSelected <span style="color: "><font color="#808080">=</font></span> <span style="color: "><font color="#0000ff">Type</font></span></font><span style="color: "><font style="font-size: 10pt" color="#808080">,</font></span></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&#160;&#160;&#160; </font></span><font style="font-size: 10pt">@WebIdSelected <span style="color: "><font color="#808080">=</font></span> WebId</font><span style="color: "><font style="font-size: 10pt" color="#808080">,</font></span></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&#160;&#160;&#160; </font></span><font style="font-size: 10pt">@ItemIdSelected <span style="color: "><font color="#808080">=</font></span> DocLibRowId</font><span style="color: "><font style="font-size: 10pt" color="#808080">,</font></span></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&#160;&#160;&#160; </font></span><font style="font-size: 10pt">@ItemLevelSelected <span style="color: "><font color="#808080">=</font></span> </font><span style="color: "><font style="font-size: 10pt" color="#0000ff">Level</font></span></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; color: ; mso-no-proof: yes"><font face="Courier New"><font style="font-size: 10pt" color="#0000ff">FROM</font></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&#160;&#160;&#160; </font></span><font style="font-size: 10pt">Docs <span style="color: "><font color="#0000ff">WITH</font></span><span style="color: "><font color="#808080">(</font></span>NOLOCK</font><span style="color: "><font style="font-size: 10pt" color="#808080">)</font></span></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; color: ; mso-no-proof: yes"><font face="Courier New"><font style="font-size: 10pt" color="#0000ff">WHERE</font></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&#160;&#160;&#160; </font></span><font style="font-size: 10pt">SiteId <span style="color: "><font color="#808080">=</font></span> @WebSiteId </font><span style="color: "><font style="font-size: 10pt" color="#808080">AND</font></span></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&#160;&#160;&#160; </font></span><font style="font-size: 10pt">DirName <span style="color: "><font color="#808080">=</font></span> @UrlDirName </font><span style="color: "><font style="font-size: 10pt" color="#808080">AND</font></span></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&#160;&#160;&#160; </font></span><font style="font-size: 10pt">LeafName <span style="color: "><font color="#808080">=</font></span> @UrlLeafName </font><span style="color: "><font style="font-size: 10pt" color="#808080">AND</font></span></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&#160;&#160;&#160; </font></span><font style="font-size: 10pt"><span style="color: "><font color="#808080">(</font></span><span style="color: "><font color="#0000ff">Level</font></span> <span style="color: "><font color="#808080">=</font></span> 255 <span style="color: "><font color="#808080">AND</font></span> LTCheckoutUserId <span style="color: "><font color="#808080">=</font></span> @UserId </font><span style="color: "><font style="font-size: 10pt" color="#808080">OR</font></span></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&#160;&#160;&#160;&#160; </font></span><font style="font-size: 10pt"><span style="color: "><font color="#0000ff">Level</font></span> <span style="color: "><font color="#808080">&lt;&gt;</font></span> 255 <span style="color: "><font color="#808080">AND</font></span> <span style="color: "><font color="#808080">(</font></span>LTCheckoutUserId <span style="color: "><font color="#808080">IS</font></span> <span style="color: "><font color="#808080">NULL</font></span> <span style="color: "><font color="#808080">OR</font></span> LTCheckoutUserId <span style="color: "><font color="#808080">&lt;&gt;</font></span> @UserId</font><span style="color: "><font style="font-size: 10pt" color="#808080">))</font></span></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">ORDER</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> </font><span style="color: "><font style="font-size: 10pt" color="#0000ff">BY</font></span></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&#160;&#160;&#160; </font></span><font style="font-size: 10pt"><span style="color: "><font color="#0000ff">Level</font></span> </font><span style="color: "><font style="font-size: 10pt" color="#0000ff">DESC</font></span></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><strong><font style="background-color: #ffff00"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">IF</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @WebIdSelected <span style="color: "><font color="#808080">&lt;&gt;</font></span> @WebId</font></span></font></strong></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; color: ; mso-no-proof: yes"><font face="Courier New"><font style="background-color: #ffff00; font-size: 10pt" color="#0000ff"><strong>BEGIN</strong></font></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><strong><font style="background-color: #ffff00"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&#160;&#160;&#160; </font></span><font style="font-size: 10pt"><span style="color: "><font color="#0000ff">SET</font></span> @ret <span style="color: "><font color="#808080">=</font></span> 1</font></font></strong></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; mso-no-proof: yes"><font face="Courier New"><strong><font style="background-color: #ffff00"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&#160;&#160; </font></span><font style="font-size: 10pt"><span style="mso-spacerun: yes">&#160;</span><span style="color: "><font color="#0000ff">RETURN</font></span> @ret</font></font></strong></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; color: ; mso-no-proof: yes"><font face="Courier New"><font style="background-color: #ffff00; font-size: 10pt" color="#0000ff"><strong>END</strong></font></font></span></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">SELECT</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> @ListIdSelected<span style="color: "><font color="#808080">,</font></span> @TypeSelected<span style="color: "><font color="#808080">,</font></span> @ItemIdSelected</font></span></font></p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Courier New"><span style="font-family: ; color: ; mso-no-proof: yes"><font color="#0000ff"><font style="font-size: 10pt">IF</font></font></span><span style="font-family: ; mso-no-proof: yes"><font style="font-size: 10pt"> <span style="color: "><font color="#808080">(</font></span>@ListIdSelected <span style="color: "><font color="#808080">IS</font></span> <span style="color: "><font color="#808080">NOT</font></span> <span style="color: "><font color="#808080">NULL</font></span> <span style="color: "><font color="#808080">AND</font></span> @ItemIdSelected <span style="color: "><font color="#808080">IS</font></span> <span style="color: "><font color="#808080">NOT</font></span> </font><span style="color: "><font style="font-size: 10pt" color="#808080">NULL)</font></span></span></font></p>  <p style="line-height: 13pt; margin: 0in 0in 10pt" class="MsoNormal"><span style="line-height: 12pt; font-family: ; mso-no-proof: yes"><font face="Courier New"><span style="mso-spacerun: yes"><font style="font-size: 10pt">&#160;&#160;&#160; </font></span><font style="font-size: 10pt"><span style="color: "><font color="#0000ff">SET</font></span> @UrlIsListItem <span style="color: "><font color="#808080">=</font></span> 1</font></font></span></p>  <p style="line-height: 13pt; margin: 0in 0in 10pt" class="MsoNormal"><span style="line-height: 12pt; font-family: ; mso-no-proof: yes"><font size="2" face="Courier New"></font></span></p>  <p style="line-height: 13pt; margin: 0in 0in 10pt" class="MsoNormal">&#160;</p>  <p style="line-height: 13pt; margin: 0in 0in 10pt" class="MsoNormal">So there you go, if you come across this error in your ULS then you now know what the problem might also be.. Btw, this is fixed in SP2010 where the @ret value is by default set 0 ;)<span style="font-family: ; mso-no-proof: yes"><font size="2" face="Courier New"></font></span></p>]]></content:encoded>
    </item>
    <item>
      <title>Modifying an alert e-mail for discussion lists</title>
      <link>https://docs.microsoft.com/archive/blogs/rmeure/modifying-an-alert-e-mail-for-discussion-lists</link>
      <pubDate>Tue, 17 May 2011 01:08:40 GMT</pubDate>
      <dc:creator><![CDATA[Robin Meuré]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/rmeure/2011/05/17/modifying-an-alert-e-mail-for-discussion-lists/</guid>
      <description><![CDATA[This post is about discussion lists and customizing their alerts, maybe it’s not the most shocking...]]></description>
      <content:encoded><![CDATA[<p>This post is about discussion lists and customizing their alerts, maybe it’s not the most shocking topic in the world but it took me some time to get it all working and there are not a lost of posts around, so hence this one.. ;)</p>  <p>I was at a customer last week week who had some interesting questions, one of the questions was “<strong>Is it possible to modify the alerts that are sent from a discussion list, since the link is to the item itself, rather than the discussion it’s part of</strong>?” </p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/3755.image_0DE147D1.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/3755.image_5F00_0DE147D1.png"><img style="display: inline" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/8484.image_thumb_615817EA.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/8484.image_5F00_thumb_5F00_615817EA.png" width="640" height="276" /></a></p>  <p>See the above picture? I’m talking about the “View When will SP1 be released” link, by default, this points to <em>Lists/&lt;ListName&gt;/DispForm.aspx?ID=&lt;ID&gt;</em>. But, the discussion list is a bit different from other lists in SharePoint. For starters the list uses two content types, <em>Discussion</em> and <em>Message</em>. When you start a new discussion, you are actually creating a folder. Then each reply to that discussion is being stored in that folder.&#160; If you look closely at the URL when displaying a discussion, there is no dispform.aspx being used to render the page but instead there is a Threaded.aspx or Flat.aspx (depending on the view that is choosen). Next, when you look even more close, it accepts a parameter called RootFolder that is a server relative URL that looks like this “<em>RootFolder=/sites/&lt;siteCollection&gt;/Lists/&lt;ListName&gt;/&lt;DiscussionName&gt;</em>” or as in my example it shows “<em>/sites/alert/Lists/Team Discussion/When will SP1 be released</em>”.&#160; In order to prove that every discussion is a folder, I came up with the following piece of code:</p>  <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal">   <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Consolas"><span style="font-family: ; color: "><font color="#2b91af">SPList</font></span><span style="font-family: "> list = web.Lists.TryGetList(<span style="color: "><font color="#a31515">&quot;Team Discussion&quot;</font></span>);</span></font></p>    <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Consolas"><span style="font-family: ; color: "><font color="#0000ff">foreach</font></span><span style="font-family: "> (<span style="color: "><font color="#2b91af">SPListItem</font></span> dicussion <span style="color: "><font color="#0000ff">in</font></span> list.Folders)</span></font></p>    <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas">{</font></span></p>    <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160; </span><span style="color: "><font color="#2b91af">Literal</font></span> literal = <span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">Literal</font></span>();</font></span></p>    <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160; </span>literal.Text = </font></span></p>    <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#a31515">&quot;&lt;BR&gt;&quot;</font></span>+</font></span></p>    <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#a31515">&quot;Discussion : &quot;</font></span>+ dicussion.Name.ToString() + <span style="color: "><font color="#a31515">&quot;&lt;BR&gt;&quot;</font></span> +</font></span></p>    <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#a31515">&quot;Replies : &quot;</font></span> + dicussion.Folder.ItemCount.ToString();</font></span></p>    <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160; </span><span style="color: "><font color="#0000ff">this</font></span>.Controls.Add(literal);</font></span></p>    <p style="line-height: normal; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas">}</font></span></p> </p>  <p>Which results in</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/6330.image_70AB79F9.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/6330.image_5F00_70AB79F9.png"><img style="display: inline" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/2110.image_thumb_4FB80752.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/2110.image_5F00_thumb_5F00_4FB80752.png" width="240" height="73" /></a></p>  <p>And here is the actual list (to prove my point ;)</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/6242.image_5C45B46E.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/6242.image_5F00_5C45B46E.png"><img style="display: inline" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/6758.image_thumb_1ACB0215.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/6758.image_5F00_thumb_5F00_1ACB0215.png" width="640" height="135" /></a></p>  <p>Back to the question, to show the discussion instead of the reply, we have to change the URL from <em>Dispform.aspx?&lt;ListItemId&gt;</em> to <em>RootFolder?&lt;Server-relativeUrl-of-discussion&gt;.. </em>seems pretty easy right? So, let’s get to it!</p>  <p>This was actually for me the first time I’ve ever looked at into modifying alerts. I knew this was possible by editing the alerttemplates.xml file but like I said, this was my first time with customizing alerts. So I went on searching for some articles and I found this blogpost from a few years ago from the <a href="http://blogs.msdn.com/b/sharepointdeveloperdocs">Developer Documentation</a> team called <a href="http://blogs.msdn.com/b/sharepointdeveloperdocs/archive/2007/12/07/customizing-alert-notifications-and-alert-templates-in-windows-sharepoint-services-3-0.aspx">Customizing Alert Notifications and Alert Templates in Windows SharePoint Services 3.0</a> and while reading through, the last paragraph called my attention since it said “In my next post I'll talk about <a href="http://blogs.msdn.com/sharepointdeveloperdocs/archive/2007/12/14/how-to-customizing-alert-emails-using-ialertnotificationhandler.aspx">how to use the IAlertNotifyHandler interface</a> to customize alerts.” That seemed like something was something was possible using the Object Model (yes!) instead of modifying the XML.. </p>  <p>Essentially that approach is about three steps</p>  <ol>   <li>Create a custom handler that intercepts the email.      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Consolas"><span style="font-family: ; color: "><font color="#0000ff">public</font></span><span style="font-family: "> <span style="color: "><font color="#0000ff">class</font></span> <span style="color: "><font color="#2b91af">SPAlertNotification</font></span> : <font color="#2b91af"><span style="color: ">IAlertNotifyHandler</span></font></span></font></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas">{</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160; </span><span style="color: "><font color="#0000ff">public</font></span> <span style="color: "><font color="#0000ff">bool</font></span> OnNotification(<span style="color: "><font color="#2b91af">SPAlertHandlerParams</font></span> ahp)</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160; </span>{</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#008000">//Makes life easier when debugging</font></span></font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Consolas"><span style="font-family: ; color: "><font color="#0000ff"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>#if</font></span><span style="font-family: "> (DEBUG)</span></font></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#2b91af">Debugger</font></span>.Break();</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: ; color: "><font face="Consolas"><font color="#0000ff"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>#endif</font></font></span><span style="font-family: "></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas">&#160;</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#0000ff">string</font></span> rootFolder = <span style="color: "><font color="#0000ff">string</font></span>.Empty;</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#0000ff">string</font></span> viewName = <span style="color: "><font color="#a31515">&quot;Flat.aspx&quot;</font></span>; <span style="color: "><font color="#008000">// or &quot;Threaded.aspx&quot;</font></span></font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><span style="mso-spacerun: yes"><font face="Consolas">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#0000ff">using</font></span> (<span style="color: "><font color="#2b91af">SPSite</font></span> site = <span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">SPSite</font></span>(ahp.siteId))</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>{</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#0000ff">using</font></span> (<span style="color: "><font color="#2b91af">SPWeb</font></span> web = site.OpenWeb(ahp.webId))</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>{</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#008000">//In case of add (1) or a change (2) we modify the body of the message</font></span></font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#0000ff">if</font></span> (ahp.eventData[0].eventType == 1 || ahp.eventData[0].eventType == 2)</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>{</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#2b91af">SPList</font></span> list = web.Lists[ahp.a.ListID];</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas">&#160;</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#2b91af">SPListItem</font></span> item = list.GetItemByIdSelectedFields(ahp.eventData[0].itemId, <span style="color: "><font color="#a31515">&quot;ContentType&quot;</font></span>, <span style="color: "><font color="#a31515">&quot;Url&quot;</font></span>);</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas">&#160;</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#008000">//Each discussion is a folder in the discussion list, the RootItem being of ContentType Dicussion</font></span></font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#0000ff">if</font></span> (item.ContentTypeId.Parent.Equals(<span style="color: "><font color="#2b91af">SPBuiltInContentTypeId</font></span>.Discussion))</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>rootFolder = item.Folder.ServerRelativeUrl;</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas">&#160;</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#008000">//Each reply in a discussion is a listItem in the folder, the ContentType of a reply is Message</font></span></font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#0000ff">if</font></span> (item.ContentTypeId.Parent.Equals(<span style="color: "><font color="#2b91af">SPBuiltInContentTypeId</font></span>.Message))</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>rootFolder = web.GetFolder(item.Url).ParentFolder.ServerRelativeUrl;</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas">&#160;</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#008000">//Instead of returning the DispForm.aspx, we are returning the url of the view (Flat.aspx) </font></span></font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#008000">//which requires the rootfolder of the discussion.</font></span></font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>ahp.body = ahp.body.Replace(<span style="color: "><font color="#a31515">&quot;DispForm.aspx?ID=&quot;</font></span> + item.ID.ToString(), </font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#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;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>viewName +<span style="color: "><font color="#a31515">&quot;?RootFolder=&quot;</font></span> + rootFolder);</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>}</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas">&#160;</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#008000">//Send the email the alert</font></span></font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#2b91af">SPUtility</font></span>.SendEmail(web, <span style="color: "><font color="#0000ff">true</font></span>, <span style="color: "><font color="#0000ff">false</font></span>, ahp.headers[<span style="color: "><font color="#a31515">&quot;to&quot;</font></span>].ToString(), ahp.headers[<span style="color: "><font color="#a31515">&quot;subject&quot;</font></span>], ahp.body);</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>}</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>}</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas">&#160;</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#0000ff">return</font></span> <span style="color: "><font color="#0000ff">false</font></span>;<span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span></font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160; </span>}</font></span></p>     <span style="line-height: 13pt; list-style-type: disc; font-family: ; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><font face="Consolas">}</font></span> </li>    <li>Create our own AlertTemplates.xml file, (creating a copy of the existing one and using the copy is the easiest) </li>    <ul>     <li>Per&#160; type of list, you can add a reference to your custom handler. In this case, we are only interested in modifying the email that is sent for discussion lists. Let’s see how an alerttemplate looks like        <br />&lt;AlertTemplate Type=&quot;List&quot;&#160; Name=&quot;SPAlertTemplateType.DiscussionBoard&quot;&gt;         <br />&#160; &lt;EventTypes IsVisible=&quot;True&quot;/&gt;         <br />&#160; &lt;Format&gt;…. &lt;/Format&gt;         <br /><strong>&#160; &lt;Properties&gt;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;!--This is our custom handler being defined here –&gt;          <br />&#160;&#160;&#160;&#160;&#160;&#160; &lt;NotificationHandlerAssembly&gt;SP.DiscussionAlert, Version=1.0.0.0, Culture=neutral, PublicKeyToken=dc834ccbbe356fc6&lt;/NotificationHandlerAssembly&gt;          <br />&#160;&#160;&#160;&#160;&#160;&#160; &lt;NotificationHandlerClassName&gt;SP.DiscussionAlert.SPAlertNotification&lt;/NotificationHandlerClassName&gt;          <br />&#160;&#160;&#160;&#160;&#160;&#160; &lt;NotificationHandlerProperties&gt;&lt;/NotificationHandlerProperties&gt;&#160; <br />&#160; &lt;/Properties&gt;</strong>         <br />&#160; &lt;Filters IsVisible=&quot;True&quot;&gt; ….&lt;/Filters&gt;         <br />&lt;/AlertTemplate&gt; </li>   </ul>    <li>Register the customized alerttemplate file to the WebApplication of your choice, now this can be done using STSADM but that’s old fashioned ;) So why not register it using the OM and let the IT Pro just click on “Activate” when the solution is deployed eh? Much more fancy imo.. therefore let’s create a WebApplication-scoped FeatureReceiver like this:      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Consolas"><span style="font-family: ; color: "><font color="#808080">///</font></span><span style="font-family: ; color: "><font color="#008000"> </font></span><span style="font-family: ; color: "><font color="#808080">&lt;summary&gt;</font></span></font><span style="font-family: "></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Consolas"><span style="font-family: ; color: "><font color="#808080">///</font></span><span style="font-family: ; color: "><font color="#008000"> Adds the modified alert templates file to the webapplication</font></span></font><span style="font-family: "></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Consolas"><span style="font-family: ; color: "><font color="#808080">///</font></span><span style="font-family: ; color: "><font color="#008000"> </font></span><span style="font-family: ; color: "><font color="#808080">&lt;/summary&gt;</font></span></font><span style="font-family: "></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Consolas"><span style="font-family: ; color: "><font color="#808080">///</font></span><span style="font-family: ; color: "><font color="#008000"> </font></span><span style="font-family: ; color: "><font color="#808080">&lt;param name=&quot;properties&quot;&gt;&lt;/param&gt;</font></span></font><span style="font-family: "></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Consolas"><span style="font-family: ; color: "><font color="#0000ff">public</font></span><span style="font-family: "> <span style="color: "><font color="#0000ff">override</font></span> <span style="color: "><font color="#0000ff">void</font></span> FeatureActivated(<span style="color: "><font color="#2b91af">SPFeatureReceiverProperties</font></span> properties)</span></font></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas">{</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160; </span><span style="mso-spacerun: yes">&#160;</span><span style="color: "><font color="#2b91af">SPWebApplication</font></span> webApplication = </font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>(<span style="color: "><font color="#2b91af">SPWebApplication</font></span>) properties.Feature.Parent;</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><span style="mso-spacerun: yes"><font face="Consolas">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160; </span><span style="color: "><font color="#2b91af">SPAlertTemplateCollection</font></span> alertTemplateCollection = </font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">SPAlertTemplateCollection</font></span>(</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>(<span style="color: "><font color="#2b91af">SPWebService</font></span>)(webApplication.Parent));</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas">&#160;</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas">&#160;</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160; </span>alertTemplateCollection.InitAlertTemplatesFromFile(</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#2b91af">SPUtility</font></span>.GetGenericSetupPath(<span style="color: "><font color="#a31515">&quot;TEMPLATE\\XML&quot;</font></span>) + </font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#a31515">&quot;\\CustomizedAlertTemplates.xml&quot;</font></span>);<span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span></font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas">}</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas">&#160;</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Consolas"><span style="font-family: ; color: "><font color="#808080">///</font></span><span style="font-family: ; color: "><font color="#008000"> </font></span><span style="font-family: ; color: "><font color="#808080">&lt;summary&gt;</font></span></font><span style="font-family: "></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Consolas"><span style="font-family: ; color: "><font color="#808080">///</font></span><span style="font-family: ; color: "><font color="#008000"> Puts the original alert templates file back to the webapplication </font></span></font><span style="font-family: "></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Consolas"><span style="font-family: ; color: "><font color="#808080">///</font></span><span style="font-family: ; color: "><font color="#008000"> </font></span><span style="font-family: ; color: "><font color="#808080">&lt;/summary&gt;</font></span></font><span style="font-family: "></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Consolas"><span style="font-family: ; color: "><font color="#808080">///</font></span><span style="font-family: ; color: "><font color="#008000"> </font></span><span style="font-family: ; color: "><font color="#808080">&lt;param name=&quot;properties&quot;&gt;&lt;/param&gt;</font></span></font><span style="font-family: "></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><font face="Consolas"><span style="font-family: ; color: "><font color="#0000ff">public</font></span><span style="font-family: "> <span style="color: "><font color="#0000ff">override</font></span> <span style="color: "><font color="#0000ff">void</font></span> FeatureDeactivating(<span style="color: "><font color="#2b91af">SPFeatureReceiverProperties</font></span> properties)</span></font></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas">{</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160; </span><span style="color: "><font color="#2b91af">SPWebApplication</font></span> webApplication = </font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>(<span style="color: "><font color="#2b91af">SPWebApplication</font></span>)properties.Feature.Parent;</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><span style="mso-spacerun: yes"><font face="Consolas">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160; </span><span style="color: "><font color="#2b91af">SPAlertTemplateCollection</font></span> alertTemplateCollection = </font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">SPAlertTemplateCollection</font></span>(</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>(<span style="color: "><font color="#2b91af">SPWebService</font></span>)(webApplication.Parent));</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas">&#160;</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas">&#160;</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160; </span>alertTemplateCollection.InitAlertTemplatesFromFile(</font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: "><font color="#2b91af">SPUtility</font></span>.GetGenericSetupPath(<span style="color: "><font color="#a31515">&quot;TEMPLATE\\XML&quot;</font></span>) </font></span></p>      <p style="line-height: normal; list-style-type: disc; margin: 0in 0in 0pt; text-autospace: ; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "><font face="Consolas"><span style="mso-spacerun: yes">&#160; </span><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160; </span>+ <span style="color: "><font color="#a31515"><a href="file://\\alerttemplates.xml">\\alerttemplates.xml</a></font></span>);</font></span></p>     <span style="line-height: 13pt; list-style-type: disc; font-family: ; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><font face="Consolas">}</font></span></li> </ol>  <p>&#160;</p>  <p>So there you have it.. I hope the inner workings with discussion list is a bit more clear now. I still haven’t covered the difference between the Threaded and Flat view and how SharePoint is doing that but maybe that’s another post..</p>  <p>Let me know if you find the alert modification useful :)</p>]]></content:encoded>
    </item>
    <item>
      <title>Want to have SharePoint code approved by Microsoft?</title>
      <link>https://docs.microsoft.com/archive/blogs/rmeure/want-to-have-sharepoint-code-approved-by-microsoft</link>
      <pubDate>Fri, 13 May 2011 05:01:01 GMT</pubDate>
      <dc:creator><![CDATA[Robin Meuré]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/rmeure/2011/05/13/want-to-have-sharepoint-code-approved-by-microsoft/</guid>
      <description><![CDATA[If you ever wanted to know if your SharePoint code is good enough, then look no further than MSOCAF...]]></description>
      <content:encoded><![CDATA[<p>If you ever wanted to know if your SharePoint code is good enough, then look no further than MSOCAF which stands for <strong>M</strong>icro<strong>s</strong>oft <strong>O</strong>nline <strong>C</strong>ode <strong>A</strong>nalysis <strong>F</strong>ramework. This tool was primarily build to validate custom SharePoint code that will run in BPOS-D farms (SharePoint online dedicated) however nothing is stopping you from downloading the tool and validate your own WSP to see what Microsoft thinks of it! ;) </p>  <blockquote>   <p>Code analysis within MSOCAF focuses on areas like memory management, security vulnerabilities, exception management, object model usage, quality gates for unsupported features and reporting. The framework leverages existing tools like FxCop, CAT.Net, and SPDisposeCheck to analyze custom solutions. </p> </blockquote>  <p>So how does it work? Well, first you need to download the tool from <a href="https://caf.sharepoint.microsoftonline.com/Default.aspx" target="_blank">https://caf.sharepoint.microsoftonline.com/Default.aspx</a>, then start it up, you will get this screen (looks nice and shiny eh?):</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/4048.image_2B63DB1F.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/4048.image_5F00_2B63DB1F.png"><img style="display: inline" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/3542.image_thumb_0F72A627.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/3542.image_5F00_thumb_5F00_0F72A627.png" width="640" height="459" /></a></p>  <p>Next, click on Analyze. It will tell you how the folder structure of your deployment must look like:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/8420.image_04F1D207.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/8420.image_5F00_04F1D207.png"><img style="display: inline" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/1884.image_thumb_4CEFDE23.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/1884.image_5F00_thumb_5F00_4CEFDE23.png" width="640" height="449" /></a></p>  <p>Click on Next to move on, there you will be told which rules will be used to check the code:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/1488.image_0F9F038F.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/1488.image_5F00_0F9F038F.png"><img style="display: inline" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/2577.image_thumb_1A0FB1E2.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/2577.image_5F00_thumb_5F00_1A0FB1E2.png" width="640" height="451" /></a></p>  <p>Now, probably a lot of ‘standard’ rules will not really apply to your code. I mean, personally, I’ve never used any P/Invokes (at least, not that I’m aware off ;) so the chances are unlikely that the “Move P/Invokes to NativeMethods class” rule in the Design section will be fired. So instead, focus on the rules that are defined in the custom rule set and the Memory Management one.</p>  <p>After reviewing the rules, click on Next to get the screen where you can locate the folder structure that holds your solution</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/3073.image_6522ACA4.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/3073.image_5F00_6522ACA4.png"><img style="display: inline" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/2084.image_thumb_233BC756.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/2084.image_5F00_thumb_5F00_233BC756.png" width="640" height="453" /></a></p>  <p>Now, let me share that will be reviewed.. and be aware this is <strong>bad</strong> code!</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/4150.image_6154E207.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/4150.image_5F00_6154E207.png"><img style="display: inline" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/3580.image_thumb_37916714.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/3580.image_5F00_thumb_5F00_37916714.png" width="512" height="480" /></a></p>  <p>Curious what the tool will be say of this? So am I! </p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/1004.image_7AACBF74.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/1004.image_5F00_7AACBF74.png"><img style="display: inline" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/8666.image_thumb_61150C7A.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/8666.image_5F00_thumb_5F00_61150C7A.png" width="640" height="381" /></a></p>  <p>And here we are, as a surprise, my code did not succeed in passing the rules. And the cool thing is that you can also where exactly (line number) the code was bad, and also in most cases there is a resolution you can click on.    <br />In this case, it’s giving me the solution to fix this and also a helpful link to a blogpost every SharePoint developer should know better than the date he/she got married..</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/4643.image_334743B5.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/4643.image_5F00_334743B5.png"><img style="display: inline" title="image" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/44/77/metablogapi/0246.image_thumb_76431222.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-77-metablogapi/0246.image_5F00_thumb_5F00_76431222.png" width="640" height="340" /></a></p>  <p>There you have it.. you might wonder what the audience is for this tool. I believe that it’s good for both developer and IT Pro.. it gives the developers a nice little framework on which they can validate their code own. On the other hand, it gives the IT Pro a better understanding if the customization that has been given to them is really that good as the developers say it is. And if something is wrong with it, they can go back to the developers and demand an explanation why they should put into production.</p>  <p>&#160;</p>  <p>Let me know what you think about it!</p>]]></content:encoded>
    </item>
    <item>
      <title>Living the PFE life</title>
      <link>https://docs.microsoft.com/archive/blogs/rmeure/living-the-pfe-life</link>
      <pubDate>Tue, 26 Apr 2011 03:50:32 GMT</pubDate>
      <dc:creator><![CDATA[Robin Meuré]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/rmeure/2011/04/26/living-the-pfe-life/</guid>
      <description><![CDATA[First of all, welcome back if already know me. If you don’t know me; Hi, I’m Robin,&#160; I’ve been...]]></description>
      <content:encoded><![CDATA[<p>First of all, welcome back if already know me. If you don’t know me; Hi, I’m Robin,&#160; I’ve been a SharePoint developer/consultant for the last six years and to bring you up to speed, I have an old blog from my previous employer that I would like to invite you to take a look at <a href="http://community.zevenseas.com/blogs/robin">http://community.zevenseas.com/blogs/robin</a> </p>  <p>What is PFE? It stands for Premier Field Engineer and in short, the main purpose is to provide reactive and proactive support to Microsoft customers. For more info check out <a title="https://careers.microsoft.com/JobDetails.aspx?ss=&amp;pg=3&amp;so=&amp;rw=50&amp;jid=33767&amp;jlang=EN" href="https://careers.microsoft.com/JobDetails.aspx?ss=&amp;pg=3&amp;so=&amp;rw=50&amp;jid=33767&amp;jlang=EN">https://careers.microsoft.com/</a></p>  <p>So, how is my life any different than working as SharePoint consultant/developer? Well, for starters, the duration of engagements I have with customers is brought down to a maximum of 4 to 5 days, most of the time it’s just 1 or 2 days. So that’ s quite different than the 3-6 month engagements I was used to. And actually this is one of the things I really do like, the variety amongst the customers, the traveling and the experience of dealing with different cultures in such a fast pace.</p>  <p>In this post I wanted to share my experiences with the <em>infamous</em> (<a href="https://www.youtube.com/watch?v=GIGtHhAfe8w">https://www.youtube.com/watch?v=GIGtHhAfe8w</a>) critsits. What does a critsit actually mean? Well, its stands for “Critical Situation” and it means that whenever you’re on-call, you will get an IM/e-mail/phone-call that you have to go as quickly as possible to the customer to solve their problem. For me it means, getting in contact with the internal travel desk to arrange a flight (if I need to fly) and hotel and then just <strong>go</strong>. Does this mean that the critsit will begin when I arrive on-site? No! Way before we even get called there is another group of engineers working on the case. They are called the&#160; Escalation Engineers, these guys are the real heroes, since they are figuring everything out behind the scenes. Giving us, the PFE, an action plan what to do when we arrive on-site and how to solve the problem if we are lost. Also, the data we gather as PFE, is being send these guys to work on behind the scenes. So, to give you some examples, here are two experiences where I couldn’t solve the problem without them.</p>  <p>Critsit #1 : “Search crawler hangs”    <br />At this one, I was send to a customer who was facing problems with their crawler. They had some dashboards to showed information that were search driven so it was mission critical for them to solve the hanging crawler because the dashboards were showing outdated information. So, first things first, I took a look at their Search Administration page and indeed, the crawler was running for 145hours and nothing was happening. Then I did what almost everyone would do in that situation, check the EventViewer and the ULS logs.. and it showed NOTHING related to the search service..<strong> Aargh#1</strong>     <br />So, I tried restarting the search service and see what would happen. Well, as you would have guessed, once it was running, it returned to the exact same state the crawler was in previously..<strong> Aargh#2      <br /></strong>At this time I was having a call with the Escalation Engineer what to do next, and he pointed me in the direction of looking at SQL. Determining if maybe there is a deadlock&#160; between two processes. And guess what, there was a deadlock! Now I will not going into much detail here but it turned out that a stored procedure was in an infinite loop (<strong>remember, you should never ever touch the database!</strong> ;).     <br />To fix this, we modified this particular stored procedure to able to break out of the loop. Restarted the search service, did a reset of the index, stopped the search service. Restored the stored procedure, started the search service, did a full crawl and everything was working again and the crawl completed within 1 hour.     <br />And everyone was happy.. Now, did it feel dirty? <strong>YES! </strong>Did it feel unnatural? <strong>YES! </strong>Why? Well, I was doing something that <strong>is</strong> on the list of forbidden things to do, even when working for Microsoft, we were still very hesitant to do this action.&#160; And it was a last resort action we had to perform..</p>  <p>Critsit #2 : “w3wp process crashes randomly”    <br />When I read the problem description, I immediately thought of custom code that had some ‘dispose’ problems. So, I asked for the custom code, to look at it in my hotel room. And, unfortunately for me, the code was perfectly fine, meaning that something else was crashing the w3wp process. The question of course was.. what was it? After excluding some scenario’s and checking the ULS –, IIS logs and the EventViewer to find out if there was a correlation between all these three. According to the ULS logs, ‘nothing’ was wrong at the moment of crashing. Next thing was maybe the amount of memory being consumed what caused the crash, while the process was peaking at 1.2gb’s of memory, it crashed at 600mb. So that couldn’t be the problem.     <br />Yet again it was time to call the escalation engineer again to help out. Now, I’m not going into a lot of detail again but it turned out to be something was corrupting the memory heap and the garbage collector was detecting this and therefore it crashed (gracefully) the w3wp process. How did we managed to get so far? Well, there is a tool called windbg (check out <a title="Download and Install Debugging Tools for Windows" href="http://www.google.nl/url?sa=t&amp;source=web&amp;cd=1&amp;ved=0CB4QFjAA&amp;url=http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Fwindows%2Fhardware%2Fgg463009&amp;ei=UJu2TdH3NpOd4Ab18LQJ&amp;usg=AFQjCNFQJgYHFtxbqsRFrnquFGbuVM1Nwg">Download and Install Debugging Tools for Windows</a>) , and you attach this debugger to a process. In our case the ‘faulty’ w3wp process and then set a breakpoint on which it crashed all the time. Then when it hits the breakpoint, we create a dump of the memory and then some magic happens here at Microsoft and it turned out to be another thread was doing this, this thread being the garbage collector thread.    <br />Now to give you some background, this customer was running SharePoint 2007 with a custom implementation of EBS (the predecessor of RBS), which has some known issues but none of them were applicable here. So, we couldn’t work this out, meaning that the customer has to upgrade to the latest CU and then the Product Group is going to take a look at it.. <strong>Aargh#3 </strong>Conclusion : problem not solved yet, will keep you posted on the outcome!</p>  <p>   <br />Now for me, these two critsits were awesome. I mean, I only heard of the tool windbg, I did not know what a corrupt memory heap was, and now I know! Although at times, it felt like being a puppet in a way, I did learn a lot from this. And that’s the thing I wanted to get across, even after being a SharePoint developer for six years, I’m still learning SharePoint! :)</p>]]></content:encoded>
    </item>
  </channel>
</rss>