<?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>Manpreet's SharePoint Developer Blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/malag/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/malag/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 04:00:51 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Error "operation is not valid due to the current state of the object" with custom event handler</title>
      <link>https://docs.microsoft.com/archive/blogs/malag/error-operation-is-not-valid-due-to-the-current-state-of-the-object-with-custom-event-handler</link>
      <pubDate>Mon, 16 May 2011 14:00:19 GMT</pubDate>
      <dc:creator><![CDATA[Manpreet_Alag]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/malag/2011/05/16/error-operation-is-not-valid-due-to-the-current-state-of-the-object-with-custom-event-handler/</guid>
      <description><![CDATA[Recently I had a customer who was hitting “Operation is not valid due to the current state of the...]]></description>
      <content:encoded><![CDATA[<p>Recently I had a customer who was hitting “<strong>Operation is not valid due to the current state of the object</strong>” error randomly on the document library where he had enabled his custom event handler (<a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spitemeventreceiver.itemupdated.aspx">ItemUpdated</a>). Event handler itself was pretty simple with just few lines of code to update the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitem.aspx">List Item</a>’s name to a calculated one.</p>  <p>&#160;</p>  <p>Interestingly, he was able to upload the XML, Doc and PDF files properly without any issues but it was failing only when he was trying to upload Adobe Portfolio or Zip files. This was interesting as Adobe Portfolio files are again PDF files only! Why would SharePoint not like Portfolio or Zip files?</p>  <p>&#160;</p>  <p>Reading further about Adobe Portfolio files, noticed that almost all these files are large in size ( &gt; 10-15 MB each), this lead to the thought that it has to do with the file size of the file being uploaded and not the type. I created&#160; a clean machine with SharePoint 2010 and installed the event handler for my document library. From the customer’s stack trace, I had seen that it was crashing at CheckIn method call. So enabled Check-in/Check-out on the document library.</p>  <p>&#160;</p>  <p>Now when I tried uploading small documents (1-5 MB each), it worked perfectly as it should and the event handler executed and updated the item name. Then I increased the file size of my DOCX file and made it 19 MB, now I am getting the crash consistently. So with all the file types with size of more than 20 MB or so caused the issue.</p>  <p>&#160;</p>  <p>Now the troubleshooting, as the customer was using <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spitemeventreceiver.itemupdated.aspx">ItemUpdated</a> event handler and then again calling <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitem.update.aspx">SPListItem.Update()</a> method within this event handler, it was causing the clash when <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfile.checkin.aspx">SPFile.CheckIn</a> was being called by the user from SharePoint UI. Now as the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spitemeventreceiver.itemupdated.aspx">ItemUpdated</a> event handler is asynchronous and the clash is happening.</p>  <p>&#160;</p>  <p>Now SharePoint 2010 gives us control over the post event handlers, if they should be asynchronous or synchronous. By default all post-event handlers (ending with –ed) are asynchronous. So went ahead and added the following line in ELEMENTS.XML file:</p>  <p><strong>&lt;Synchronization&gt;</strong><em>Synchronous</em><strong>&lt;/Synchronization&gt;</strong></p>  <p>Retracted the solution and deployed back again. Now the test time. Uploaded a 30 MB Word document and it went through without any errors. Tested again with different file sizes and different file types and it is working smoothly now. Just to make sure that it is the event synchronization that is working here, I removed the Synchronization element from the ELEMENTS.XML and redeployed the solution and I am back with the error.</p>  <p>&#160;</p>  <p>So effectively, Synchronization element saved the day in the end.</p>  <p>&#160;</p>  <p>This <a title="http://msdn.microsoft.com/en-us/library/ff512765.aspx" href="http://msdn.microsoft.com/en-us/library/ff512765.aspx">http://msdn.microsoft.com/en-us/library/ff512765.aspx</a> gives the Synchronization element details. </p>  <p>The article <a title="http://msdn.microsoft.com/en-us/library/ee536171.aspx" href="http://msdn.microsoft.com/en-us/library/ee536171.aspx">http://msdn.microsoft.com/en-us/library/ee536171.aspx</a> gives the details of event handler improvements in SharePoint 2010.</p>  <p>&#160;</p>  <p>Hope this helps in saving some of your time <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/05/73/metablogapi/4150.wlEmoticon-smile_78729CF5.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-05-73-metablogapi/4150.wlEmoticon_2D00_smile_5F00_78729CF5.png" /></p>  <p>&#160;</p>  <p>-Manpreet</p>]]></content:encoded>
    </item>
    <item>
      <title>BDC application definition file import error : cannot have more than 255 Parameters for a method.</title>
      <link>https://docs.microsoft.com/archive/blogs/malag/bdc-application-definition-file-import-error-cannot-have-more-than-255-parameters-for-a-method</link>
      <pubDate>Thu, 23 Dec 2010 17:28:21 GMT</pubDate>
      <dc:creator><![CDATA[Manpreet_Alag]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/malag/2010/12/23/bdc-application-definition-file-import-error-cannot-have-more-than-255-parameters-for-a-method/</guid>
      <description><![CDATA[&#160;  Recently got a customer who had created a BDC application definition file but when trying to...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p>Recently got a customer who had created a BDC application definition file but when trying to import it, he is getting error:</p>  <p><strong><em><font color="#ff0000">The following error occurred: cannot have more than 255 Parameters for a method .Error was encountered at or just before Line: '1414' and Position '14'.</font></em></strong></p>  <p>We checked and found that none of the methods had parameters north of 255. So this error was a little surprising.    <br />Another simple BDC app definition file was imported successfully in same server.    <br />Strangely, the AppDef file with error, was working on another SharePoint farm. In both the farms customer was at build 12.0.0.6421.</p>  <p>Now this is a surprise, same build number and same XML file and 1 farm would let it import and another would just refuse with a misleading error.    <br />    <br />So the obvious place to start was to find the root of the error from belly of SharePoint. Started digging into SharePoint RTM version’s source code and found the limit to be 30 parameters per method. Checked and found all the methods in customer’s XML which are causing issue are having more than 30 parameters. </p>  <p>True, this was a limit in RTM build of SharePoint but still the error message says “<strong>255</strong>” parameters, which is still a mystery. </p>  <p>Checking the further source code and found that somewhere around Build 12.0.0.6331 the limit was updated to 255 parameters for a method.</p>  <p>So that explains the number “<strong>255</strong>” in error but still none of the methods giving error in customer’s XML file were having more than 255 parameters. It was in range of about 35 parameters for each method.</p>  <p>It was clear now that the issue is in binaries.</p>  <p>Then it was time to go back to customer and ask how SharePoint was installed and what was the patch sequence.</p>  <p><em>The answer</em>: He installed <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyId=2E6E5A9C-EBF6-4F7F-8467-F4DE6BD6B831&amp;displaylang=en" target="_blank">SharePoint 2007 with SP2 Trial edition</a> and then upgraded to enterprise license. Also he confirmed that all the machines where he installed using the same installer, he is facing the issue with this particular BDC AppDef file. So it does look like binary files issue. The production farm was installed with SharePoint 2007 SP1 Enterprise and then upgraded to SP2.</p>  <p><em>The resolution</em>? Before we could troubleshoot further to find which binary is causing issue with SharePoint 2007 with SP2 Trial install, customer nuked the test server and rebuilt it again using the SharePoint 2007 SP1 Enterprise and upgraded to SP2 and issue was resolved !!</p>  <p>&#160;</p>  <p>Happy troubleshooting… <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/05/73/metablogapi/4426.wlEmoticon-smile_2.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-05-73-metablogapi/4426.wlEmoticon_2D00_smile_5F00_2.png" /></p>]]></content:encoded>
    </item>
    <item>
      <title>Operation requires user to be Service Application Administrator to be able to execute the code</title>
      <link>https://docs.microsoft.com/archive/blogs/malag/operation-requires-user-to-be-service-application-administrator-to-be-able-to-execute-the-code</link>
      <pubDate>Thu, 23 Dec 2010 13:33:49 GMT</pubDate>
      <dc:creator><![CDATA[Manpreet_Alag]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/malag/2010/12/23/operation-requires-user-to-be-service-application-administrator-to-be-able-to-execute-the-code/</guid>
      <description><![CDATA[Recently got a customer who was having a very simple code in an application page (in _layouts...]]></description>
      <content:encoded><![CDATA[<p>Recently got a customer who was having a very simple code in an application page (in _layouts folder) to find the crawled properties, which are mapped to a managed property in <a href="http://technet.microsoft.com/en-us/library/gg502597.aspx" target="_blank">Search Service Application</a> (in SharePoint 2010) as given below:</p>  <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> SPServiceContext context = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, SPSiteSubscriptionIdentifier.Default);</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> SearchServiceApplicationProxy searchProxy = context.GetDefaultProxy(<span style="color: #0000ff">typeof</span>(SearchServiceApplicationProxy)) <span style="color: #0000ff">as</span> SearchServiceApplicationProxy;</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> SearchServiceApplicationInfo ssai = searchProxy.GetSearchServiceApplicationInfo();</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> SearchServiceApplication application = Microsoft.Office.Server.Search.Administration.SearchService.Service.SearchApplications.GetValue&lt;SearchServiceApplication&gt;(ssai.SearchServiceApplicationId);</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> Schema sspSchema = <span style="color: #0000ff">new</span> Schema(application);</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span>&#160; </pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> ManagedPropertyCollection managedProperties = sspSchema.AllManagedProperties;</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8">   8:</span>&#160; </pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9">   9:</span> <span style="color: #0000ff">foreach</span> (ManagedProperty managedProperty <span style="color: #0000ff">in</span> managedProperties)</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10">  10:</span> {</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11">  11:</span>     <span style="color: #0000ff">string</span> managedPropertyName = managedProperty.Name;</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12">  12:</span>&#160; </pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13">  13:</span>     <span style="color: #008000">//check to see if the managed property is mapped to one of our crawled properties</span></pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14">  14:</span>     <span style="color: #0000ff">foreach</span> (CrawledProperty crawledProperty <span style="color: #0000ff">in</span> managedProperty.GetMappedCrawledProperties(managedProperty.GetMappings().Count))</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum15">  15:</span>     {</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum16">  16:</span>         <span style="color: #0000ff">if</span> (!mappings.ContainsKey(crawledProperty.Name))</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum17">  17:</span>         {</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum18">  18:</span>             <span style="color: #008000">//if it is and has not yet been added to the list of managed fields, add it</span></pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum19">  19:</span>             mappings.Add(crawledProperty.Name, managedPropertyName);</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum20">  20:</span>&#160; </pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum21">  21:</span>         }</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum22">  22:</span>     }</pre>
<!--crlf-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum23">  23:</span> }</pre>
<!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></!--crlf--></div>
</div>

<p>Now when we hit the line 14 (<a href="http://msdn.microsoft.com/en-us/library/microsoft.office.server.search.administration.managedproperty.getmappings.aspx" target="_blank">ManagedProperty.GetMappings()</a>.Count), it always returns 0 (zero) as Mappings count. Now I am the Farm Administrator and the Service Account but still I am not able to pull in the data.

  <br />

  <br />If I am logging into SharePoint Central Admin, I am able to see all the mappings from the SharePoint UI. So there must be something that SharePoint is doing which my custom application is not doing to get the data.</p>

<p>After searching on net for quite sometime and finding nothing, I started to dig into SharePoint’s source to see what is going on here and what is there behind the SharePoint’s UI, that makes it work.
  <br />

  <br />Tracing the code and following its path, I figured out that you need to provide your account an Administrator access to <a href="http://technet.microsoft.com/en-us/library/gg502597.aspx" target="_blank">Search Service Application</a>.

  <br />

  <br />Tried that and I added myself as Search Service Administrator under Central Administration Site -&gt; Application Management -&gt; Manage Service Applications -&gt; Search Service Application and click on Administrators button in the ribbon and add myself to the list with Full Control. Once that was done, I was able to get the results properly without any issues.

  <br />

  <br />But while adding myself to Search Service Application’s administrator, I noticed a line in the dialog box which said:

  <br />

  <br />”<em><font color="#9b00d3">Specify the users who have rights to manage this service application. These users will be given access to the Central Administration site and will be able to manage settings related to this service application.</font> <font color="#ff0000"><strong>Members of the Farm Administrators group always have rights to manage all service applications</strong>.</font></em>”</p>

<p>The line highlighted in RED, did not sound right. If I am already a <a href="http://technet.microsoft.com/en-us/library/cc263291.aspx" target="_blank">Farm Administrator</a>, I should have rights for this application. Then why I would need to add myself explicitly as Search Service Application administrator !!</p>

<p>This got me digging again and engaging my friendly escalation engineer onto it. After quite sometime studying the SharePoint’s code, a small line got our notice, which effectively said that (<em><font color="#c0504d">paraphrased</font></em>):

  <br />

  <br /><em><font color="#c0504d">If you are a Farm Administrator, you will have access to Search Service Application only from SharePoint’s Central Administration site. If you are not in Central Administration site, you would need to add yourself explicitly to the Search Service Application as administrator.</font></em></p>

<p>Basic message was, due to enhanced security in SharePoint 2010, you cannot execute this piece of code from a content web application (your team or publishing site) but <strong>ONLY from admin web application </strong>(aka SharePoint Central Administration website).</p>

<p>To validate this, I removed myself from Search Service Application’s administrator list. Now as my code was already there in _layouts folder, I accessed it using my Central Admin’s URL (<a href="http://sp2010a:2010/_layouts/testpage.aspx">http://sp2010a:2010/_layouts/testpage.aspx</a>) instead of my application’s URL (<a href="http://sp2010a/_layouts/testpage.aspx">http://sp2010a/_layouts/testpage.aspx</a>) and IT WORKED !</p>

<p>So the root issue was visible now, that lead us to define our options in this case and we came up with the following 4 options for the customer:</p>

<ol>
  <li>Access the page using the Central Admin application's URL (<em>may not be feasible due to security issues</em>)</li>

  <li>Add users as Search Service Administrators (<em>again, may not be feasible due to security issues</em>)</li>

  <li>Add the app pool account of content application as Search Service Administrator and use <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx" target="_blank">SPSecurity.RunWithElevatedPrivileges</a> to run the code in App Pool's context (<em>this could work, but again can cause security concerns</em>)</li>

  <li>Host a web service on Central Admin site and access it from the Content application hosted layouts page (<em>This would be the most preferred way to get it done</em>)</li>
</ol>

<p>Let me know if this helped you and which path did you choose.</p>

<p>Happy Coding… <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/05/73/metablogapi/8468.wlEmoticon-smile_2.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-05-73-metablogapi/8468.wlEmoticon_2D00_smile_5F00_2.png" /></p>

<p>&#160;</p>

<p>-Manpreet</p>]]></content:encoded>
    </item>
    <item>
      <title>Updating HTMLProp iFilter sample to work with MOSS 2007</title>
      <link>https://docs.microsoft.com/archive/blogs/malag/updating-htmlprop-ifilter-sample-to-work-with-moss-2007</link>
      <pubDate>Wed, 02 Jun 2010 14:20:00 GMT</pubDate>
      <dc:creator><![CDATA[Manpreet_Alag]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/malag/2010/06/02/updating-htmlprop-ifilter-sample-to-work-with-moss-2007/</guid>
      <description><![CDATA[What happened? Customer was using MOSS 2007 SP2 and was indexing a lot of content from external...]]></description>
      <content:encoded><![CDATA[<p><strong><span style="text-decoration: underline;">What happened? <br /></span></strong>Customer was using MOSS 2007 SP2 and was indexing a lot of content from external sites. These sites had date as information in the HTML meta fields. Customer wanted them to be indexed as Date/Time field in MOSS so that they can be queried like a Date rather than string.</p>
<p>Customer is trying to use <a href="http://msdn.microsoft.com/en-us/library/dd582939(office.11).aspx">HTMLProp iFilter sample</a> from the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=E15438AC-60BE-41BD-AA14-7F1E0F19CA0D&amp;displaylang=en">Platform SDK</a> to index the fields as Date/Time but it is not indexing them as Date/Time but still being indexed as string only.</p>
<p><strong><span style="text-decoration: underline;">Why it happened? <br /></span></strong>By default, SharePoint's HTML ifilter (nlhtml.dll) converts all the meta field information from crawling to string type rather than their particular data type. After troubleshooting found, that the HTMLProp's implementation available in SDK may not be compatible with MOSS 2007 ifilter implementation.</p>
<p>HTMLProp is implementing IPersistFile but MOSS 2007 expects IPersistStream to be available, so it is not working with MOSS (got this information by using iFilter Explorer, a 3rd party tool)</p>
<p><strong><span style="text-decoration: underline;">How was it resolved? <br /></span></strong>Studied how nlhtml.dll works and modified the HTMLProp sample to use IPersistStream along with IPersistFile and registered it with MOSS. You can use the <a target="_blank" href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/05/73/6175.HTMLProp_Updated_Sample.zip" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-05-73/6175.HTMLProp_5F00_Updated_5F00_Sample.zip">modified sample given</a> along with the instructions from <a href="http://msdn.microsoft.com/en-us/library/dd582939(office.11).aspx">http://msdn.microsoft.com/en-us/library/dd582939(office.11).aspx</a> to get it working.</p>
<p>To register the HTMLProp iFilter to work with MOSS, few registry entries need to be changed to make iFilter to load when indexing HTML and HTM files:</p>
<p>ADD your full dll path to following registry key: <br />HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ContentIndex\DLLsToRegister</p>
<p>For the following 2 keys, need to change the (Default) value to "{f4309e80-a1db-11d1-a8fb-00e098006ed3}"-- This is GUID of our HTMLProp IFilter <br /><br />Changed for MOSS <br />HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\12.0\Search\Setup\ContentIndexCommon\Filters\Extension\.htm <br />HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\12.0\Search\Setup\ContentIndexCommon\Filters\Extension\.html</p>
<p>Changed for WSS v3 <br />HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0\Search\Setup\ContentIndexCommon\Filters\Extension\.htm <br /><br />HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0\Search\Setup\ContentIndexCommon\Filters\Extension\.html</p>
<p><strong><span style="color: #ff0000;">Important NOTE:</span></strong> <em>Please make sure you take backup of registry keys before changing anything</em>.</p>
<p><strong>References:</strong> <br />IPersistFile - <a href="http://msdn.microsoft.com/en-us/library/ms687223(VS.85).aspx">http://msdn.microsoft.com/en-us/library/ms687223(VS.85).aspx</a> <br />IPersistStream - <a href="http://msdn.microsoft.com/en-us/library/ms690091(VS.85).aspx">http://msdn.microsoft.com/en-us/library/ms690091(VS.85).aspx</a> <br /><a href="http://blogs.msdn.com/ifilter/archive/2006/12/25/chronicles-of-an-ifilter-development-inception-to-deployment.aspx">http://blogs.msdn.com/ifilter/archive/2006/12/25/chronicles-of-an-ifilter-development-inception-to-deployment.aspx</a></p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/10/01/91/30/HTMLProp_Updated_Sample.zip" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-01-91-30/HTMLProp_5F00_Updated_5F00_Sample.zip">HTMLProp_Updated_Sample.zip</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Using custom OpenDocuments control to open custom file types in SharePoint</title>
      <link>https://docs.microsoft.com/archive/blogs/malag/using-custom-opendocuments-control-to-open-custom-file-types-in-sharepoint</link>
      <pubDate>Thu, 13 May 2010 02:16:00 GMT</pubDate>
      <dc:creator><![CDATA[Manpreet_Alag]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/malag/2010/05/13/using-custom-opendocuments-control-to-open-custom-file-types-in-sharepoint/</guid>
      <description><![CDATA[A customer was having a number of PDF files uploaded into their SharePoint sites. They were using...]]></description>
      <content:encoded><![CDATA[<P>A customer was having a number of PDF files uploaded into their SharePoint sites. They were using Adobe Acrobat to edit and create PDF files. What customer wanted was, to be able to edit the PDF files directly from SharePoint by getting "Edit with Adobe Acrobat" option in the ECB menu.</P>
<P>We edited the DOCICON.xml file located at <EM>&lt;drive&gt;\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\XML</EM> to add a new entry for PDF in the <STRONG><EM>&lt;ByExtension&gt;</EM></STRONG> section:</P>
<P><EM>&lt;Mapping Key="pdf" Value="pdf.gif"&nbsp; EditText="Adobe Acrobat" OpenControl="SharePoint.OpenDocuments"/&gt;</EM></P>
<P>After adding the above given entry and restarting the IIS, we got the entry in ECB menu to edit the PDF files but it was not opening the Adobe Acrobat product when clicked on it, but rather throwing a JavaScript error.</P>
<P>As customer also wanted some more control over how PDFs are being edited, we decided to go by the custom <A href="http://msdn.microsoft.com/en-us/library/ms454230.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ms454230.aspx">OpenDocuments</A> control.</P>
<P>A custom <A href="http://msdn.microsoft.com/en-us/library/ms454230.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ms454230.aspx">OpenDocuments</A> control was implemented using C# in an attempt to replicate the functionality provided by <A href="http://msdn.microsoft.com/en-us/library/ms454230.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ms454230.aspx">SharePoint.OpenDocuments</A> control. But with time, it was created into a generic control, that try to find out the application associated with the given file extension, on the client machine and try to do a <A href="http://msdn.microsoft.com/en-us/library/bb762153(VS.85).aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/bb762153(VS.85).aspx">ShellExecute</A> to open the file.</P>
<P>As the custom control is implemented as a COM control, you would need to register the control in the registry of the client machine. There are a couple of sample registry files in the attached zip archive, which can take care of registering and un-registering&nbsp; of the control. The sample registry files assume that the control is in the GAC of the client machine.</P>
<P>On the SharePoint end, you would need to change DOCICON.xml file to tell SharePoint to use your custom control when clicked on your custom extension, by changing the &lt;ByExtension&gt; section entry to:</P>
<P><EM>&lt;Mapping Key="pdf" Value="pdf.gif"&nbsp; EditText="Adobe Acrobat" OpenControl="<STRONG>Malag.OpenDocuments</STRONG>"/&gt;</EM></P>
<P>Notice that we have changed the “<STRONG>OpenControl</STRONG>” attribute of <STRONG>&lt;Mapping&gt;</STRONG> tag to point to our custom control.</P>
<P>The code for Malag.OpenDocuments control is attached. Hope this provides you with pointers to get you started on the path of created custom OpenDocuments control implementation.</P>
<P>Happy Coding… <IMG style="BORDER-BOTTOM-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP-STYLE: none; MARGIN-BOTTOM: -5px; BORDER-LEFT-STYLE: none" class="wlEmoticon wlEmoticon-smile" alt=Smile src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/malag/WindowsLiveWriter/HowtocreateacustomOpenDocumentscontrol_8CCD/wlEmoticon-smile_2.png" original-url="http://blogs.msdn.com/blogfiles/malag/WindowsLiveWriter/HowtocreateacustomOpenDocumentscontrol_8CCD/wlEmoticon-smile_2.png" mce_src="http://blogs.msdn.com/blogfiles/malag/WindowsLiveWriter/HowtocreateacustomOpenDocumentscontrol_8CCD/wlEmoticon-smile_2.png"></P>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/10/01/23/97/Malag.OpenDocuments.zip" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-01-23-97/Malag.OpenDocuments.zip">Malag.OpenDocuments.zip</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Code fails with “A Web Part or Web Form Control on this Page cannot be displayed or imported. The type could not be found or it is not registered as safe”</title>
      <link>https://docs.microsoft.com/archive/blogs/malag/code-fails-with-a-web-part-or-web-form-control-on-this-page-cannot-be-displayed-or-imported-the-type-could-not-be-found-or-it-is-not-registered-as-safe</link>
      <pubDate>Mon, 03 May 2010 16:47:23 GMT</pubDate>
      <dc:creator><![CDATA[Manpreet_Alag]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/malag/2010/05/03/code-fails-with-a-web-part-or-web-form-control-on-this-page-cannot-be-displayed-or-imported-the-type-could-not-be-found-or-it-is-not-registered-as-safe/</guid>
      <description><![CDATA[One of my customer’s came up with a peculiar issue. They were having a number of custom web parts on...]]></description>
      <content:encoded><![CDATA[<p>One of my customer’s came up with a peculiar issue. They were having a number of custom web parts on their SharePoint site and everything was working great from the browser. But they had also created a <a href="http://msdn.microsoft.com/en-us/library/cc406686.aspx" target="_blank">timer job</a> that enumerates web parts and it used to fail with these errors:     <br />    <br /><em>“A Web Part or Web Form Control on this Page cannot be displayed or imported. The type could not be found or it is not registered as safe.”&#160; <br /></em>    <br />-and-     <br />    <br /><em>“No Parameterless constructor is defined for this object.”</em></p>  <p>&#160;</p>  <p>All the web.config entries were proper and also the website was working properly from web browser. After some troubleshooting, found that customer is having the web part assemblies in the BIN folder of the web application (under &lt;drive&gt;:\Inetpub\wwwroot\wss\VirtualDirectories\&lt;port&gt;\bin). They had a dependency on a 3rd party assembly which was not signed, therefore cannot put their assemblies in the <a href="http://msdn.microsoft.com/en-us/library/yf1d93sz(VS.71).aspx" target="_blank">GAC</a>.</p>  <p>Now how does this translates to error from the <a href="http://msdn.microsoft.com/en-us/library/cc406686.aspx" target="_blank">custom timer job</a>? </p>  <p><a href="http://msdn.microsoft.com/en-us/library/cc406686.aspx" target="_blank">OWSTIMER</a> is where the timer job is running, and when it accesses the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webpartmanager.aspx" target="_blank">WebPartManager</a>, it tries to instantiate the web parts, and the web parts were deployed to the BIN directory of the web app. Since <a href="http://msdn.microsoft.com/en-us/library/cc406686.aspx" target="_blank">OWSTIMER</a> is not a web application and does not know where is the BIN folder hosted so eventually doesn't have access to the web part and get this error.</p>  <p>You can read more about Assembly Placement at <a href="http://msdn.microsoft.com/en-us/library/2h3sywsc(VS.85).aspx">http://msdn.microsoft.com/en-us/library/2h3sywsc(VS.85).aspx</a>.</p>  <p>&#160;</p>  <p>So what was the solution in this case?</p>  <ol>   <li>Deploy the web parts to the <a href="http://msdn.microsoft.com/en-us/library/yf1d93sz(VS.71).aspx" target="_blank">GAC</a>. This will require strong naming the assemblies, which was not possible in this situation. </li>    <li>Copy the web part assemblies in question to the 12 directory. This will provide access to the web part assemblies to <a href="http://msdn.microsoft.com/en-us/library/cc406686.aspx" target="_blank">OWSTIMER</a>. (Reference: <a href="http://msdn.microsoft.com/en-us/library/2h3sywsc(VS.85).aspx" target="_blank">Assembly Placement</a>) </li> </ol>  <p>&#160;</p>  <p>Hope this helps you save sometime while troubleshooting… as always… Happy Coding <img style="border-bottom-style: none; border-right-style: none; border-top-style: none; margin-bottom: -5px; border-left-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/malag/WindowsLiveWriter/78ce6bb14385_14CF7/wlEmoticon-smile_2.png" original-url="http://blogs.msdn.com/blogfiles/malag/WindowsLiveWriter/78ce6bb14385_14CF7/wlEmoticon-smile_2.png" /></p>]]></content:encoded>
    </item>
    <item>
      <title>How to Create new application pool and change App Pool of SharePoint Website</title>
      <link>https://docs.microsoft.com/archive/blogs/malag/how-to-create-new-application-pool-and-change-app-pool-of-sharepoint-website</link>
      <pubDate>Wed, 14 Apr 2010 17:39:08 GMT</pubDate>
      <dc:creator><![CDATA[Manpreet_Alag]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/malag/2010/04/14/how-to-create-new-application-pool-and-change-app-pool-of-sharepoint-website/</guid>
      <description><![CDATA[In OOTB SharePoint, you do not have anything which will allow you to create new application pools in...]]></description>
      <content:encoded><![CDATA[<p>In OOTB SharePoint, you do not have anything which will allow you to create new application pools in IIS and assign them to applications. Also nothing was found in STSADM. </p>  <p>If the application pool does not exist you can create it using the following code snippet:</p>  <div class="csharpcode">   <pre class="alt"><span class="lnum">   1:  </span>SPFarm farm = SPFarm.Local; </pre>

  <pre><span class="lnum">   2:  </span>SPWebService service = farm.Services.GetValue&lt;SPWebService&gt;(); </pre>

  <pre class="alt"><span class="lnum">   3:  </span>SPApplicationPool appPool = <span class="kwrd">new</span> SPApplicationPool(<span class="str">&quot;App Pool Title&quot;</span>, service); </pre>

  <pre><span class="lnum">   4:  </span>appPool.CurrentIdentityType = IdentityType.SpecificUser; </pre>

  <pre class="alt"><span class="lnum">   5:  </span>appPool.Username = <span class="str">&quot;domain\\username&quot;</span>; </pre>

  <pre><span class="lnum">   6:  </span>appPool.Password = <span class="str">&quot;password&quot;</span>; </pre>

  <pre class="alt"><span class="lnum">   7:  </span>appPool.Update(); </pre>

  <pre><span class="lnum">   8:  </span>appPool.Deploy();</pre>
</div>
<style type="text/css">






.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>Be aware that application pools you created in IIS directly cannot be used with the SharePoint object model. The reason is that these are not known in the Config DB and they could also be with different configuration on different WFE's in the farm.</p>

<p>So you have to ensure that the application pool has been created using the method above. Once the application pool is created or it already exists you can look it up using the following code snippet and assign to the SharePoint application:</p>

<div class="csharpcode">
  <pre class="alt"><span class="lnum">   1:  </span>SPFarm farm = SPFarm.Local;</pre>

  <pre><span class="lnum">   2:  </span>SPWebService service = farm.Services.GetValue&lt;SPWebService&gt;();</pre>

  <pre class="alt"><span class="lnum">   3:  </span>SPApplicationPool appPool = service.ApplicationPools[<span class="str">&quot;App Pool Title&quot;</span>];</pre>

  <pre><span class="lnum">   4:  </span></pre>

  <pre class="alt"><span class="lnum">   5:  </span>SPSite site = <span class="kwrd">new</span> SPSite(<span class="str">&quot;http://url-to-your-sitecollection&quot;</span>);</pre>

  <pre><span class="lnum">   6:  </span>SPWebApplication webApp = site.WebApplication;</pre>

  <pre class="alt"><span class="lnum">   7:  </span>webApp.ApplicationPool = appPool;</pre>

  <pre><span class="lnum">   8:  </span>webApp.Update();</pre>

  <pre class="alt"><span class="lnum">   9:  </span>webApp.ProvisionGlobally();</pre>
</div>
<style type="text/css">






.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<br />

<br />

<p>Hope this helps you to elevate some issues… Happy Coding…<img style="margin-top: -10px" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/malag/WindowsLiveWriter/Createnewapplicationpoolandchange_3234/wlEmoticon-smile_2.png" original-url="http://blogs.msdn.com/blogfiles/malag/WindowsLiveWriter/Createnewapplicationpoolandchange_3234/wlEmoticon-smile_2.png" /></p>]]></content:encoded>
    </item>
    <item>
      <title>Incoming Email settings link disappears from document library settings</title>
      <link>https://docs.microsoft.com/archive/blogs/malag/incoming-email-settings-link-disappears-from-document-library-settings</link>
      <pubDate>Mon, 15 Feb 2010 17:18:42 GMT</pubDate>
      <dc:creator><![CDATA[Manpreet_Alag]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/malag/2010/02/15/incoming-email-settings-link-disappears-from-document-library-settings/</guid>
      <description><![CDATA[One of my customer had created a custom document library deriving from OOTB document library. They...]]></description>
      <content:encoded><![CDATA[<p>One of my customer had created a custom document library deriving from OOTB document library. They are able to create their document library from custom list definition properly without any issues. But when in the document library created using custom list definition, if you go to list settings page, it does not show &quot;Incoming Email settings&quot; link under &quot;Communications&quot; column. Incoming Email settings are setup properly and OOTB document library has got incoming email settings link and it is getting emails properly. Just libraries created from their custom list definition does not have Incoming Email settings link!    <br /></p>  <p>So what is causing the issue?    <br />Digging into SharePoint, found that this is hard-coded and SharePoint will only show Incoming Email settings link for OOTB lists of type Announcements, Event, Document Library, Picture Library, XML Form, Discussion Board, Posts.     <br /></p>  <p>Then what is the solution?    <br />If you create a custom list, you need to create a custom email event handler and attach to your list and then Incoming Email settings link will be available. But that would also mean you miss out on the default settings like security, save original email etc. which are provided by OOTB incoming email settings page. With custom list, you are able to set just that whether list is allowed to received email and if yes, what is the alias.     <br />    <br />If you are creating your own email event handler and attaching to a list, you would need to handle everything else yourself like email attachments, save the original email, security etc. which is by-default handled by SharePoint otherwise.</p>  <p>Here is a sample code for an Email event handler which you can use as a building block:</p>  <div class="csharpcode">   <pre class="alt"><span class="lnum">   1:  </span><span class="kwrd">using</span> System;</pre>

  <pre><span class="lnum">   2:  </span><span class="kwrd">using</span> System.Collections.Generic;</pre>

  <pre class="alt"><span class="lnum">   3:  </span><span class="kwrd">using</span> System.Text;</pre>

  <pre><span class="lnum">   4:  </span><span class="kwrd">using</span> System.IO;</pre>

  <pre class="alt"><span class="lnum">   5:  </span><span class="kwrd">using</span> Microsoft.SharePoint;</pre>

  <pre><span class="lnum">   6:  </span><span class="kwrd">using</span> Microsoft.SharePoint.Utilities;</pre>

  <pre class="alt"><span class="lnum">   7:  </span>&#160;</pre>

  <pre><span class="lnum">   8:  </span><span class="kwrd">namespace</span> SimpleEmailHandler</pre>

  <pre class="alt"><span class="lnum">   9:  </span>{</pre>

  <pre><span class="lnum">  10:  </span>    <span class="kwrd">public</span> <span class="kwrd">class</span> EmailHandler : SPEmailEventReceiver</pre>

  <pre class="alt"><span class="lnum">  11:  </span>    {</pre>

  <pre><span class="lnum">  12:  </span>        <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">void</span> EmailReceived(SPList list, Microsoft.SharePoint.Utilities.SPEmailMessage emailMessage, <span class="kwrd">string</span> receiverData)</pre>

  <pre class="alt"><span class="lnum">  13:  </span>        {</pre>

  <pre><span class="lnum">  14:  </span>            <span class="kwrd">base</span>.EmailReceived(list, emailMessage, receiverData);</pre>

  <pre class="alt"><span class="lnum">  15:  </span>&#160;</pre>

  <pre><span class="lnum">  16:  </span>            <span class="rem">// Add the whole email to the document library as .eml file</span></pre>

  <pre class="alt"><span class="lnum">  17:  </span>            SPFile mFile = list.RootFolder.Files.Add(DateTime.Now.ToLongDateString() + <span class="str">&quot;--&quot;</span> + DateTime.Now.ToLongTimeString().Replace(<span class="str">&quot;:&quot;</span>, <span class="str">&quot;-&quot;</span>) + <span class="str">&quot;.eml&quot;</span>, emailMessage.GetMessageStream());</pre>

  <pre><span class="lnum">  18:  </span>&#160;</pre>

  <pre class="alt"><span class="lnum">  19:  </span>            <span class="rem">// Get the SPListItem from the file just added</span></pre>

  <pre><span class="lnum">  20:  </span>            SPListItem item = mFile.Item;</pre>

  <pre class="alt"><span class="lnum">  21:  </span>&#160;</pre>

  <pre><span class="lnum">  22:  </span>            <span class="rem">// Update the title, from and subject fields</span></pre>

  <pre class="alt"><span class="lnum">  23:  </span>            <span class="rem">// Make sure your list have got From and Subject fields in it</span></pre>

  <pre><span class="lnum">  24:  </span>            item[<span class="str">&quot;Title&quot;</span>] = <span class="str">&quot;Recvd:&quot;</span> + DateTime.Now.ToString();</pre>

  <pre class="alt"><span class="lnum">  25:  </span>            item[<span class="str">&quot;From&quot;</span>] = emailMessage.Headers[<span class="str">&quot;From&quot;</span>];</pre>

  <pre><span class="lnum">  26:  </span>            item[<span class="str">&quot;Subject&quot;</span>] = emailMessage.Headers[<span class="str">&quot;Subject&quot;</span>];</pre>

  <pre class="alt"><span class="lnum">  27:  </span>&#160;</pre>

  <pre><span class="lnum">  28:  </span>            <span class="rem">// Update the item so that change made above are saved</span></pre>

  <pre class="alt"><span class="lnum">  29:  </span>            item.Update();</pre>

  <pre><span class="lnum">  30:  </span>&#160;</pre>

  <pre class="alt"><span class="lnum">  31:  </span>            <span class="rem">// Now we will add the attachments in the email to the document library</span></pre>

  <pre><span class="lnum">  32:  </span>            <span class="kwrd">foreach</span> (SPEmailAttachment attachment <span class="kwrd">in</span> emailMessage.Attachments)</pre>

  <pre class="alt"><span class="lnum">  33:  </span>            {</pre>

  <pre><span class="lnum">  34:  </span>                <span class="kwrd">byte</span>[] attachmentArray = <span class="kwrd">new</span> <span class="kwrd">byte</span>[attachment.ContentStream.Length];</pre>

  <pre class="alt"><span class="lnum">  35:  </span>                attachment.ContentStream.Read(attachmentArray, 0, (<span class="kwrd">int</span>)attachment.ContentStream.Length);</pre>

  <pre><span class="lnum">  36:  </span>                list.RootFolder.Files.Add(DateTime.Now.ToLongTimeString().Replace(<span class="str">&quot;:&quot;</span>, <span class="str">&quot;-&quot;</span>).Replace(<span class="str">&quot;/&quot;</span>, <span class="str">&quot;-&quot;</span>) + <span class="str">&quot;--&quot;</span> + attachment.FileName, attachmentArray);</pre>

  <pre class="alt"><span class="lnum">  37:  </span>            }</pre>

  <pre><span class="lnum">  38:  </span>&#160;</pre>

  <pre class="alt"><span class="lnum">  39:  </span>            <span class="rem">// Send an EventLog entry saying that we are done with the email processing...</span></pre>

  <pre><span class="lnum">  40:  </span>            System.Diagnostics.EventLog.WriteEntry(<span class="str">&quot;SimpleEmailEventHandler&quot;</span>, <span class="str">&quot;Simple Email event handler called...&quot;</span>);</pre>

  <pre class="alt"><span class="lnum">  41:  </span>        }</pre>

  <pre><span class="lnum">  42:  </span>    }</pre>

  <pre class="alt"><span class="lnum">  43:  </span>}</pre>
</div>
<style type="text/css">




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<br />

<p>&#160;</p>

<p>As always… Happy Coding <img style="margin-top: -10px" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/malag/WindowsLiveWriter/IncomingEmailsettingslinkdisappears_5837/wlEmoticon-smile_2.png" original-url="http://blogs.msdn.com/blogfiles/malag/WindowsLiveWriter/IncomingEmailsettingslinkdisappears_5837/wlEmoticon-smile_2.png" /></p>]]></content:encoded>
    </item>
    <item>
      <title>List Field added using InfoPath does not filter on [Me]</title>
      <link>https://docs.microsoft.com/archive/blogs/malag/list-field-added-using-infopath-does-not-filter-on-me</link>
      <pubDate>Fri, 01 Jan 2010 17:23:49 GMT</pubDate>
      <dc:creator><![CDATA[Manpreet_Alag]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/malag/2010/01/01/list-field-added-using-infopath-does-not-filter-on-me/</guid>
      <description><![CDATA[A Customer had created a custom InfoPath form to add a new item in the list. It gets added, but when...]]></description>
      <content:encoded><![CDATA[<p>A Customer had created a custom InfoPath form to add a new item in the list. It gets added, but when he is trying to filter it using the field value =[Me], the filter does not work and all the items are shown to everyone.</p>  <p>Basically they are pulling in the items from User Information list from SharePoint and adding them to a drop down in InfoPath form, from where the user selects the user and the final item is added to their custom list.</p>  <p>But why filtering is not happening? When checking their list, found that they have used “Single line of text” as their field type to store the username !!</p>  <p>SharePoint does not know how to compare or validate a user inside a “Single line of text” field, so it just ignores the formula given in the View and displays all the records. </p>  <p>Now a very visible thing looks like we need to change the field type from “Single line of text” to <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spuser.aspx" target="_blank">“Person or Group”</a> type which will allow filtering of data on [Me] filter. But on other hand, InfoPath does not know how to handle the “Person or Group” type field, so it is still sending out the plain text.</p>  <p>Then it was ascertained that we need an event handler which will sit in-between and capture each item being added. That event handler will pull in the username from the item being submitted and convert it to the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spuser.aspx" target="_blank">SPUser</a> format that “Person or Group” field understand.</p>  <p>So the code was written to get the data from InfoPath form and create a “Person or Group” field value from there on.</p>  <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; height: 258px; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; height: 259px; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">void</span> ItemAdded(SPItemEventProperties properties)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     <span style="color: #0000ff">using</span> (SPSite site = <span style="color: #0000ff">new</span> SPSite(<span style="color: #006080">&quot;http://myMOSSsite/&quot;</span>))</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>     {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>         <span style="color: #0000ff">using</span> (SPWeb web = site.OpenWeb())</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span>         {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span>             SPList list = web.Lists[properties.ListId];</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8">   8:</span>             SPListItem item = list.Items[properties.ListItem.UniqueId];</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9">   9:</span>             <span style="color: #0000ff">string</span> assignedTo = properties.ListItem[<span style="color: #006080">&quot;Assigned To&quot;</span>].ToString();</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10">  10:</span>             SPPrincipalInfo userInfo = SPUtility.ResolvePrincipal(web, assignedTo, SPPrincipalType.All, SPPrincipalSource.All, <span style="color: #0000ff">null</span>, <span style="color: #0000ff">false</span>);</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11">  11:</span>             SPFieldUserValue userValue = <span style="color: #0000ff">new</span> SPFieldUserValue(web, userInfo.PrincipalId, userInfo.DisplayName);</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12">  12:</span>             item[<span style="color: #006080">&quot;Assigned&quot;</span>] = userValue;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13">  13:</span>             item.Update();</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14">  14:</span>         }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum15">  15:</span>     }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum16">  16:</span> }</pre>
<!--CRLF--></div>
</div>

<p>Happy Coding and have fun… <img style="margin-bottom: -5px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/malag/WindowsLiveWriter/ImpersonationdoesnotworkwithUserProfileM_43EA/1_3CA5PNSJK_thumb.gif" original-url="http://blogs.msdn.com/blogfiles/malag/WindowsLiveWriter/ImpersonationdoesnotworkwithUserProfileM_43EA/1_3CA5PNSJK_thumb.gif" width="22" height="22" /></p>]]></content:encoded>
    </item>
    <item>
      <title>Alerts not moved when moving sites</title>
      <link>https://docs.microsoft.com/archive/blogs/malag/alerts-not-moved-when-moving-sites</link>
      <pubDate>Fri, 01 Jan 2010 16:58:29 GMT</pubDate>
      <dc:creator><![CDATA[Manpreet_Alag]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/malag/2010/01/01/alerts-not-moved-when-moving-sites/</guid>
      <description><![CDATA[A friend on mine recently came to me asking for a solution. They had an old site which was being...]]></description>
      <content:encoded><![CDATA[<p>A friend on mine recently came to me asking for a solution. They had an old site which was being used by a lot of people, then they decided to move it. As they did not had any kind of custom solutions or any other kind of customizations, <a href="http://technet.microsoft.com/en-us/library/cc261956.aspx" target="_blank">STSADM</a> export and import seemed to the straight forward way and that’s what they did.</p>  <p>But what happened? They lost the alert settings that everyone had for themselves over those hundreds of lists in the site and their sub-sites !! That too it was noticed after a day or so when some content has already been changed in the the sites.</p>  <p>I pointed him directly to the <a href="http://technet.microsoft.com/en-us/library/cc706866.aspx" target="_blank">Technet article</a> which tells about the issues that could happen with <a href="http://technet.microsoft.com/en-us/library/cc261956.aspx" target="_blank">STSADM</a> export and import and what is not saved. But he never read it and moved everything.</p>  <p>Now they wanted the alerts back but do not want to do their last days work again, which rules out a restore option from a day old backup. Finally, we settled that we will restore backup to a different sub-site in a farm and then write the code to copy over the alert information to the new site.</p>  <p>But where is the code?? Well, it is given below !!&#160; Just provide 2 <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.aspx" target="_blank">SPWeb</a> objects, giving the source and destination and it will copy over your alert information.</p>  <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; height: 371px; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; height: 366px; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Copy(SPWeb sourceWeb, SPWeb destinationWeb)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     SPAlertCollection alerts = sourceWeb.Alerts;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>     <span style="color: #0000ff">foreach</span> (SPAlert alert <span style="color: #0000ff">in</span> alerts)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>     {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span>         SPList list = destinationWeb.Lists[alert.List.Title];</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span>         Guid guid = destinationWeb.Alerts.Add(list, alert.EventType,</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8">   8:</span>         alert.AlertFrequency);</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9">   9:</span>         SPAlert newAlert = destinationWeb.Alerts[guid];</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10">  10:</span>         SPAlertTemplate template = <span style="color: #0000ff">new</span> SPAlertTemplate();</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11">  11:</span>         template = alert.AlertTemplate;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12">  12:</span>         template.Name = alert.AlertTemplate.Name;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13">  13:</span>         newAlert.AlertTemplate = template;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14">  14:</span>         newAlert.AlwaysNotify = alert.AlwaysNotify;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum15">  15:</span>         newAlert.DynamicRecipient = alert.DynamicRecipient;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum16">  16:</span>         newAlert.EventTypeBitmask = alert.EventTypeBitmask;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum17">  17:</span>         newAlert.Filter = alert.Filter;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum18">  18:</span>         newAlert.Title = alert.Title;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum19">  19:</span>         newAlert.Status = alert.Status;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum20">  20:</span>         newAlert.User = alert.User;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum21">  21:</span>         newAlert.Update();</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum22">  22:</span>     }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum23">  23:</span> }</pre>
<!--CRLF--></div>
</div>

<p>&#160;</p>

<p>As always, Happy Coding <img style="margin-bottom: -5px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/malag/WindowsLiveWriter/ImpersonationdoesnotworkwithUserProfileM_43EA/1_3CA5PNSJK_thumb.gif" original-url="http://blogs.msdn.com/blogfiles/malag/WindowsLiveWriter/ImpersonationdoesnotworkwithUserProfileM_43EA/1_3CA5PNSJK_thumb.gif" width="22" height="22" /></p>]]></content:encoded>
    </item>
  </channel>
</rss>