<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://didierdanse.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>didierdanse.net - Development News : Dev</title><link>http://didierdanse.net/blogs/dev_en/archive/tags/Dev/default.aspx</link><description>Tags: Dev</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>SharePoint: How to run a long running operation?</title><link>http://didierdanse.net/blogs/dev_en/archive/2011/03/21/sharepoint-how-to-run-a-long-running-operation.aspx</link><pubDate>Mon, 21 Mar 2011 08:45:01 GMT</pubDate><guid isPermaLink="false">30b92a27-2adf-4ac9-9a55-506f6f2b3817:433</guid><dc:creator>Didier Danse</dc:creator><slash:comments>62</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://didierdanse.net/blogs/dev_en/rsscomments.aspx?PostID=433</wfw:commentRss><comments>http://didierdanse.net/blogs/dev_en/archive/2011/03/21/sharepoint-how-to-run-a-long-running-operation.aspx#comments</comments><description>&lt;p&gt;Sometimes, we need to run long operations using a synchronous mode. As SharePoint is based on a web technology, performing a long operation can be complex without having timeouts and so on. In SharePoint, we have the possibility to declare an operation as a long running operation.&lt;/p&gt;  &lt;p&gt;During the operation (or a set of operations), page is displayed with the classic &lt;em&gt;loading&lt;/em&gt; logo with your own message (in the following screenshot, values are default ones) :&lt;/p&gt;  &lt;p&gt;&lt;img src="http://3.bp.blogspot.com/_g-JN_WB_wo4/S89wWt_bmAI/AAAAAAAAAbo/tWH4XWe3m3c/s640/Processing.png" width="585" height="210" alt="" /&gt;&lt;/p&gt;  &lt;p&gt;This can be done using this simple code:&lt;/p&gt;  &lt;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:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;   &lt;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:&amp;#39;Courier New&amp;#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"&gt;     &lt;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:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; (SPLongOperation operation = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; SPLongOperation(&lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.Page))&lt;/pre&gt;


    &lt;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:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;{&lt;/pre&gt;


    &lt;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:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    operation.LeadingHTML = &lt;span style="color:#006080;"&gt;&amp;quot;Performing operations ...&amp;quot;&lt;/span&gt;;&lt;/pre&gt;


    &lt;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:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    operation.TrailingHTML = &lt;span style="color:#006080;"&gt;&amp;quot;Please wait while the operations are performed.&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt; This can last a few minutes.&amp;quot;&lt;/span&gt;;&lt;/pre&gt;


    &lt;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:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    operation.Begin();&lt;/pre&gt;


    &lt;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:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;                    &lt;/pre&gt;


    &lt;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:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    &lt;span style="color:#008000;"&gt;// Operations that have to be performed&lt;/span&gt;&lt;/pre&gt;


    &lt;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:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;      &lt;/pre&gt;


    &lt;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:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    operation.End(&lt;span style="color:#006080;"&gt;&lt;a href="http://yourserver/destinationpage.aspx"&gt;http://yourserver/destinationpage.aspx&lt;/a&gt;&lt;/span&gt;);&lt;/pre&gt;


    &lt;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:&amp;#39;Courier New&amp;#39;, courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;That’s all for today!&lt;/p&gt;

&lt;p&gt;____&lt;/p&gt;

&lt;p&gt;Didier Danse – &lt;a href="http://didierdanse.net"&gt;http://didierdanse.net&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Microsoft Most Valuable Professional SharePoint 
  &lt;br /&gt;&lt;a href="http://www.devoteam.lu"&gt;Devoteam Luxembourg&lt;/a&gt; – &lt;a href="http://www.devoteam.com"&gt;Devoteam Group&lt;/a&gt;&lt;/p&gt;&lt;img src="http://didierdanse.net/aggbug.aspx?PostID=433" width="1" height="1"&gt;</description><category domain="http://didierdanse.net/blogs/dev_en/archive/tags/SharePoint/default.aspx">SharePoint</category><category domain="http://didierdanse.net/blogs/dev_en/archive/tags/English/default.aspx">English</category><category domain="http://didierdanse.net/blogs/dev_en/archive/tags/Dev/default.aspx">Dev</category><category domain="http://didierdanse.net/blogs/dev_en/archive/tags/.NET/default.aspx">.NET</category></item><item><title>SharePoint: How to limit available site templates for site creation</title><link>http://didierdanse.net/blogs/dev_en/archive/2009/09/15/sharepoint-how-to-limit-available-site-templates-for-site-creation.aspx</link><pubDate>Tue, 15 Sep 2009 18:19:22 GMT</pubDate><guid isPermaLink="false">30b92a27-2adf-4ac9-9a55-506f6f2b3817:261</guid><dc:creator>Didier Danse</dc:creator><slash:comments>10</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://didierdanse.net/blogs/dev_en/rsscomments.aspx?PostID=261</wfw:commentRss><comments>http://didierdanse.net/blogs/dev_en/archive/2009/09/15/sharepoint-how-to-limit-available-site-templates-for-site-creation.aspx#comments</comments><description>&lt;p&gt;Once again, a colleague ask me if there is some possibilities to remove some site templates from the site creation page as she don’t want to allow power users to create sites based on custom site templates.&lt;/p&gt;  &lt;p&gt;The easiest way to do this is to click on &lt;em&gt;Page Layouts and Site Templates&lt;/em&gt; on the &lt;em&gt;Site Settings&lt;/em&gt; page. This link points at &lt;a href="http://&amp;lt;yoursharepointurl&amp;gt;/&amp;lt;sitename&amp;gt;/_Layouts/AreaTemplateSettings.aspx"&gt;//_Layouts/AreaTemplateSettings.aspx&amp;quot;&amp;gt;//_Layouts/AreaTemplateSettings.aspx&amp;quot;&amp;gt;http://&amp;lt;yoursharepointurl&amp;gt;/&amp;lt;sitename&amp;gt;/_Layouts/AreaTemplateSettings.aspx&lt;/a&gt; page. This link is only available at the root site of the site collection but you can navigate to the page using the previous link. &lt;/p&gt;  &lt;p&gt;On this page, you will be able able to select site templates from available site templates list:&amp;#160; &lt;br /&gt;&lt;img src="http://img398.imageshack.us/img398/9307/84265112sx0.jpg" alt="" /&gt;&lt;/p&gt;  &lt;p&gt;From a developer or an administrator perspective, there is also the possibility to use some code to manage available site templates.&lt;/p&gt;  &lt;p&gt;Here is a example of this code:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; SetAvailableTemplates(List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; templateNames)
{
     SetAvailableTemplates(templateNames, 0);
}

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; SetAvailableTemplates(List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; templateNames, &lt;span class="kwrd"&gt;uint&lt;/span&gt; lcid)
{
    &lt;span class="kwrd"&gt;using&lt;/span&gt; (SPSite site = &lt;span class="kwrd"&gt;new&lt;/span&gt; SPSite(&lt;span class="str"&gt;&amp;quot;http://&amp;lt;yoursharepointurl&amp;gt;/&amp;lt;sitename&amp;gt;&amp;quot;&lt;/span&gt;))
    {
        &lt;span class="kwrd"&gt;using&lt;/span&gt; (SPWeb web = site.OpenWeb())
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (lcid == 0) lcid = web.Language;
            Collection&amp;lt;SPWebTemplate&amp;gt; availablesTemplates = &lt;span class="kwrd"&gt;new&lt;/span&gt; Collection&amp;lt;SPWebTemplate&amp;gt;;
            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (SPWebTemplate template &lt;span class="kwrd"&gt;in&lt;/span&gt; site.GetWebTemplates(lcid))
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (templateNames.Keys.Contains(template.Name))
                    availablesTemplates.Add(template);
        
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (availablesTemplates.Count &amp;gt; 0)
            {
               &lt;span class="rem"&gt;// Code is different if site is a publishing site or not as some properties and methods are not exposed directly&lt;/span&gt;
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (PublishingWeb.IsPublishingWeb(web))
                {
                    PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (lcid == 0) publishingWeb.SetAvailableCrossLanguageWebTemplates(availablesTemplates, &lt;span class="kwrd"&gt;false&lt;/span&gt;);
                    &lt;span class="kwrd"&gt;else&lt;/span&gt; publishingWeb.SetAvailableWebTemplates(availablesTemplates, lcid, &lt;span class="kwrd"&gt;false&lt;/span&gt;);
                }
                &lt;span class="kwrd"&gt;else&lt;/span&gt;
                {
                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (lcid == 0) web.SetAvailableCrossLanguageWebTemplates(availablesTemplates);
                    &lt;span class="kwrd"&gt;else&lt;/span&gt; web.SetAvailableWebTemplates(availablesTemplates, lcid);
                    web.AllProperties[&lt;span class="str"&gt;&amp;quot;__InheritWebTemplates&amp;quot;&lt;/span&gt;] = &lt;span class="kwrd"&gt;false&lt;/span&gt;.ToString();
                    web.Update();
                }
            }
        }
    }
}&lt;/pre&gt;

&lt;p&gt;Now you can package this as a STSADM extension, a feature or anything else that can be imagined to manipulate your SharePoint.&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px;padding:0px 0px 0px 0px;"&gt;&lt;br /&gt;&lt;br /&gt;

&lt;/div&gt;&lt;img src="http://didierdanse.net/aggbug.aspx?PostID=261" width="1" height="1"&gt;</description><category domain="http://didierdanse.net/blogs/dev_en/archive/tags/STSADM/default.aspx">STSADM</category><category domain="http://didierdanse.net/blogs/dev_en/archive/tags/SharePoint/default.aspx">SharePoint</category><category domain="http://didierdanse.net/blogs/dev_en/archive/tags/English/default.aspx">English</category><category domain="http://didierdanse.net/blogs/dev_en/archive/tags/Dev/default.aspx">Dev</category></item><item><title>SharePoint: How to use SPWebConfigModification class</title><link>http://didierdanse.net/blogs/dev_en/archive/2009/09/11/sharepoint-how-to-use-spwebconfigmodification-class.aspx</link><pubDate>Fri, 11 Sep 2009 07:13:24 GMT</pubDate><guid isPermaLink="false">30b92a27-2adf-4ac9-9a55-506f6f2b3817:259</guid><dc:creator>Didier Danse</dc:creator><slash:comments>15</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://didierdanse.net/blogs/dev_en/rsscomments.aspx?PostID=259</wfw:commentRss><comments>http://didierdanse.net/blogs/dev_en/archive/2009/09/11/sharepoint-how-to-use-spwebconfigmodification-class.aspx#comments</comments><description>&lt;p&gt;SharePoint provides a API that allows developers to &lt;strong&gt;modify web.config on all web front-end servers at the same time&lt;/strong&gt;. This is really a nice concept as soon as it is used the correct way. &lt;strong&gt;All web.config modifications should (I could stay &lt;em&gt;must&lt;/em&gt;) be performed through the API&lt;/strong&gt;. Any direct change to web.config files can result in changes lost as this API will override entries in the config file.&lt;/p&gt;  &lt;p&gt;Like for all classes and APIs, developers should have a look to documentation to be able to use the API without bringing any mistakes in their code. Unfortunately, &lt;strong&gt;this API is poorly documented&lt;/strong&gt;. The best documentation is coming from blog posts. There is a lot of posts all over the Internet but you have to read a lot of them if you want a global overview of use of this API. So have a look to this simple feature.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;SPWebConfigModification usual members&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;First of all, a web config modification is described with a &lt;strong&gt;name&lt;/strong&gt;, an &lt;strong&gt;owner&lt;/strong&gt; name, an &lt;strong&gt;xpath value&lt;/strong&gt; to define location of the change and a &lt;strong&gt;value&lt;/strong&gt;. &lt;/p&gt;  &lt;p&gt;So if you want to add&lt;em&gt;&amp;#160;&lt;/em&gt;an entry in the web.config file, you have to know how we can define a unique identifier for the entry. As an example, you want to add &amp;lt;action param1=’value1’ param2=’value2’ param3=’value3’ /&amp;gt; and you know that only &lt;em&gt;param3&lt;/em&gt; should be changed, you have to define &lt;strong&gt;Name&lt;/strong&gt; parameter to &lt;em&gt;action [@param1=’value1’] [@param2=’value2’]&lt;/em&gt;. This part is the most obscure part of the SPWebConfigModification class and it is really important to understand why you have to use a correct name so let’s have the explanation: &lt;strong&gt;When applying modifications, API will read the web.config file and look for a entry with identifier. If it find such an entry, SPWebConfigModification will replace the current value. If not, it will add an new entry. So, if Name doesn’t fit with config entry, you will have duplicate value in the API.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Owner property is also really useful. We will use it to know which entries we have to delete when deactivating the feature.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Feature sample&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;In this feature, we will add two entries in the web.config file and remove them when deactivating the feature.If you don’t know how to create a feature, please refer to MSDN Documentation. &lt;/p&gt;  &lt;p&gt;&lt;em&gt;Feature.xml&lt;/em&gt;&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="html"&gt;xml&lt;/span&gt; &lt;span class="attr"&gt;version&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;encoding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt;?&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Feature&lt;/span&gt;  &lt;span class="attr"&gt;Id&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1625EAF0-F3EB-4c4a-AB8A-36FDBD878AE8&amp;quot;&lt;/span&gt;
          &lt;span class="attr"&gt;Title&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Company_FeatureName&amp;quot;&lt;/span&gt;
          &lt;span class="attr"&gt;Description&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Used to add some entries in the web.config&amp;quot;&lt;/span&gt;
          &lt;span class="attr"&gt;Version&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;12.0.0.0&amp;quot;&lt;/span&gt;
          &lt;span class="attr"&gt;Hidden&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;FALSE&amp;quot;&lt;/span&gt;
          &lt;span class="attr"&gt;Scope&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;WebApplication&amp;quot;&lt;/span&gt;
          &lt;span class="attr"&gt;DefaultResourceFile&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;core&amp;quot;&lt;/span&gt;
          &lt;span class="attr"&gt;ReceiverAssembly&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Company.FeatureName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0a1bc23456d78ef9&amp;quot;&lt;/span&gt;
          &lt;span class="attr"&gt;ReceiverClass&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Company.FeatureName.WebConfigModificatorFeatureReceiver&amp;quot;&lt;/span&gt;
          &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/sharepoint/&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ElementManifests /&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Feature&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;em&gt;Feature receiver&lt;/em&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;class&lt;/span&gt; WebConfigModificatorFeatureReceiver : SPFeatureReceiver
    {
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; SPWebConfigModificationOwner = &lt;span class="str"&gt;&amp;quot;OwnerName&amp;quot;&lt;/span&gt;;

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; FeatureActivated(SPFeatureReceiverProperties properties)
        {
            &lt;span class="kwrd"&gt;string&lt;/span&gt; name, xpath, &lt;span class="kwrd"&gt;value&lt;/span&gt;;

            SPWebApplication webApp = (SPWebApplication)properties.Feature.Parent;

            &lt;span class="preproc"&gt;#region&lt;/span&gt; ..: appSettings :..
            name = &lt;span class="str"&gt;&amp;quot;add[@key=&amp;#39;TrustedGroup&amp;#39;]&amp;quot;&lt;/span&gt;;
            xpath = &lt;span class="str"&gt;&amp;quot;configuration/appSettings&amp;quot;&lt;/span&gt;;
            &lt;span class="kwrd"&gt;value&lt;/span&gt; = &lt;span class="str"&gt;&amp;quot;&amp;lt;add key=&amp;#39;TrustedGroup&amp;#39; value=&amp;#39;Trusted&amp;#39; /&amp;gt;&amp;quot;&lt;/span&gt;;
            ModifyWebConfig(webApp, name, xpath, &lt;span class="kwrd"&gt;value&lt;/span&gt;, SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode);

            name = &lt;span class="str"&gt;&amp;quot;add[@key=&amp;#39;KeyName&amp;#39;]&amp;quot;&lt;/span&gt;;
            xpath = &lt;span class="str"&gt;&amp;quot;configuration/appSettings&amp;quot;&lt;/span&gt;;
            &lt;span class="kwrd"&gt;value&lt;/span&gt; = &lt;span class="str"&gt;&amp;quot;&amp;lt;add key=&amp;#39;KeyName&amp;#39; value=&amp;#39;Value&amp;#39; /&amp;gt;&amp;quot;&lt;/span&gt;;
            ModifyWebConfig(webApp, name, xpath, &lt;span class="kwrd"&gt;value&lt;/span&gt;, SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode);
            &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
 
            &lt;span class="kwrd"&gt;try&lt;/span&gt;
            {
                webApp.Farm.Services.GetValue&amp;lt;SPWebService&amp;gt;().ApplyWebConfigModifications();
            }
            &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
            {
                RemoveAllModifications(properties);
                &lt;span class="kwrd"&gt;throw&lt;/span&gt; ex;
            }
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            RemoveAllModifications(properties);

            &lt;span class="kwrd"&gt;try&lt;/span&gt;
            {
                SPWebApplication webApp = (SPWebApplication)properties.Feature.Parent;
                webApp.Farm.Services.GetValue&amp;lt;SPWebService&amp;gt;().ApplyWebConfigModifications();
            }
            &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
            {
                System.Diagnostics.EventLog eventLog = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Diagnostics.EventLog();
                eventLog.Source = SPWebConfigModificationOwner;
                eventLog.WriteEntry(ex.Message);
                &lt;span class="kwrd"&gt;throw&lt;/span&gt; ex;
            }
        }

        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; RemoveAllModifications(SPFeatureReceiverProperties properties)
        { 
            SPWebApplication webApp = (SPWebApplication)properties.Feature.Parent;

            List&amp;lt;SPWebConfigModification&amp;gt; modificationsToRemove = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;SPWebConfigModification&amp;gt;();

            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (SPWebConfigModification modification &lt;span class="kwrd"&gt;in&lt;/span&gt; webApp.WebConfigModifications)
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (modification.Owner == SPWebConfigModificationOwner)
                    modificationsToRemove.Add(modification);

            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (SPWebConfigModification modification &lt;span class="kwrd"&gt;in&lt;/span&gt; modificationsToRemove)
                webApp.WebConfigModifications.Remove(modification);

            webApp.Update();
        }

        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ModifyWebConfig(SPWebApplication webApp, String nameModif, String pathModif, String valueModif, SPWebConfigModification.SPWebConfigModificationType typeModif)
        {
            SPWebConfigModification modification = &lt;span class="kwrd"&gt;new&lt;/span&gt; SPWebConfigModification(nameModif, pathModif);
            modification.Value = valueModif;
            modification.Sequence = 0;
            modification.Type = typeModif;
            modification.Owner = SPWebConfigModificationOwner;

            &lt;span class="kwrd"&gt;try&lt;/span&gt;
            {
                webApp.WebConfigModifications.Add(modification);
                webApp.Update();
            }
            &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
            {
                System.Diagnostics.EventLog eventLog = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Diagnostics.EventLog();
                eventLog.Source = SPWebConfigModificationOwner;
                eventLog.WriteEntry(ex.Message);

                &lt;span class="kwrd"&gt;throw&lt;/span&gt; ex;
            }
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; FeatureInstalled(SPFeatureReceiverProperties properties) { }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; FeatureUninstalling(SPFeatureReceiverProperties properties) { }
    }&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Catching exception during ApplyWebConfigModifications&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you run two ApplyWebConfigModifications simultaneously, an exception will be thrown during the second operation and modifications are not sent (I know, I said&lt;em&gt;&amp;#160; simultaneously&lt;/em&gt;, I should say &lt;em&gt;if you execute a ApplyWeConfigModifications before the end of another ApplyWebConfigModifications&lt;/em&gt;). Unfortunately, modifications are already in the modifications list but not applied in the web.config files and we will add them again during the next feature activation. Because of this, we will remove all the modifications ourselves before throwing the exception to caller.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scope of modifications&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What about the scope? Web config modifications can be applied by web application&lt;/strong&gt;. To be more precise, this is a web application and all its extensions. It is not possible to apply modifications to a extended web application without applying these modifications to all the extensions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Entries conflicts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Unfortunately, &lt;strong&gt;SharePoint doesn’t provide a solution for web.config conflict values&lt;/strong&gt; (when two applications added the same entry) so when deactivating one of the feature, entry is removed and the second application may not work correctly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Entries modifications through UI&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Last but not least,&lt;strong&gt; if you want to modify a value without executing any code, you will have to use a page that is able to manage all the entries&lt;/strong&gt;. You can find such a page here: &lt;a title="http://blog.thekid.me.uk/archive/2007/03/24/web-config-modification-manager-for-sharepoint.aspx" href="http://blog.thekid.me.uk/archive/2007/03/24/web-config-modification-manager-for-sharepoint.aspx"&gt;http://blog.thekid.me.uk/archive/2007/03/24/web-config-modification-manager-for-sharepoint.aspx&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hope this post will help!&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px;padding:0px 0px 0px 0px;"&gt;&lt;br /&gt;&lt;br /&gt;

&lt;/div&gt;&lt;img src="http://didierdanse.net/aggbug.aspx?PostID=259" width="1" height="1"&gt;</description><category domain="http://didierdanse.net/blogs/dev_en/archive/tags/SharePoint/default.aspx">SharePoint</category><category domain="http://didierdanse.net/blogs/dev_en/archive/tags/English/default.aspx">English</category><category domain="http://didierdanse.net/blogs/dev_en/archive/tags/Dev/default.aspx">Dev</category><category domain="http://didierdanse.net/blogs/dev_en/archive/tags/Debugging/default.aspx">Debugging</category></item><item><title>SharePoint: How to debug event handlers</title><link>http://didierdanse.net/blogs/dev_en/archive/2009/02/28/sharepoint-how-to-debug-event-handlers.aspx</link><pubDate>Sat, 28 Feb 2009 08:25:28 GMT</pubDate><guid isPermaLink="false">30b92a27-2adf-4ac9-9a55-506f6f2b3817:213</guid><dc:creator>Didier Danse</dc:creator><slash:comments>105</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://didierdanse.net/blogs/dev_en/rsscomments.aspx?PostID=213</wfw:commentRss><comments>http://didierdanse.net/blogs/dev_en/archive/2009/02/28/sharepoint-how-to-debug-event-handlers.aspx#comments</comments><description>&lt;p&gt;Every SharePoint developper is quickly in front of web parts development or workflows. Unfortunately, when things are wrong, only a few of them know how to debug, analyse and correct the code without problems. All developers had to do this and know that less it last, greater it is.&lt;/p&gt;  &lt;p&gt;So, here is a little how-to article about event handlers debugging.&lt;/p&gt;  &lt;p&gt;I will not write more about event handlers usage or deployment. If you want to have information about event handler, follow the link: &lt;a href="http://msdn.microsoft.com/en-us/library/ms442323.aspx" target="_blank"&gt;MSDN&lt;/a&gt;. The most important part for us is that event handlers are deployed to SharePoint bin folder or Global Assembly Cache (GAC). Furthermore, assemblies containing event handlers are loaded dynamically when needed.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Event handlers management tools&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Some management tools are available all across the Internet. Most part of them are free of charge. From my personal point of view, there is two ones which should be used : &lt;em&gt;SP RAD Studio&lt;/em&gt;, which will be available next month and &lt;em&gt;Event handler Explorer&lt;/em&gt;. You can do it from the following site: &lt;a title="Here" href="http://www.u2u.info/SharePoint/U2U%20Community%20Tools/EventHandlerExplorer.zip" target="_blank"&gt;Event Handler Explorer&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;Why should we use this kind of tool? The objective is to check that event handler is attached to document librairy or list we want.&lt;/p&gt;  &lt;p&gt;Event Handler Explorer is easy to use but here is a quick overview of the tool:&lt;/p&gt;  &lt;p&gt;When program is loaded, all controls are blank. You have to indicate what is the site collection url.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://didierdanse.net/blogs/dev_en/5_4C6645F3.png"&gt;&lt;img title="5" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="275" alt="5" src="http://didierdanse.net/blogs/dev_en/5_thumb_56BC8BB5.png" width="644" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;As soon as you did it, you can navigate through the complete site collection and select the list or the document library you want.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://didierdanse.net/blogs/dev_en/6_7601C339.png"&gt;&lt;img title="6" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="376" alt="6" src="http://didierdanse.net/blogs/dev_en/6_thumb_2006E2C4.png" width="644" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;After this, click on &lt;em&gt;Event Handlers&lt;/em&gt;. If there is some attached event handlers, they will be listed beside this node.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://didierdanse.net/blogs/dev_en/4_65445B4F.png"&gt;&lt;img title="4" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="205" alt="4" src="http://didierdanse.net/blogs/dev_en/4_thumb_5055698D.png" width="598" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;By selecting an event handler, you can get more information about it on the right panel.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://didierdanse.net/blogs/dev_en/3_4219814E.png"&gt;&lt;img title="3" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="327" alt="3" src="http://didierdanse.net/blogs/dev_en/3_thumb_03B3BD9B.png" width="421" border="0" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;It is also possible to attach or detach event handlers through this interface.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;SharePoint logs usage&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Errors that are not handled in an event handler is logged in the SharePoint file log. All the files (by defaut, there is one every 30 minutes) are located in the folder c:\Program Files\Common Files\Microsoft Shared\web server extensions\12\LOGS if you let default parameters during installation.&lt;/p&gt;  &lt;p&gt;Search in the files for the class name, &lt;em&gt;Company.SharePoint.EventHandlers.EventHandlerName&lt;/em&gt; for example so you will be able to see if there was an error or not. This kind of error will look like:&lt;/p&gt;  &lt;p&gt;&lt;em&gt;02/25/2009 21:14:39.61 w3wp.exe (0x0C04)&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 0x04DC Windows SharePoint Services&amp;#160;&amp;#160; General&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 8e0c&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Critical&amp;#160;&amp;#160; Event manager error: Could not load file or assembly &amp;#39;&lt;em&gt;Company.SharePoint.EventHandlers.EventHandlerName&lt;/em&gt; , Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5&amp;#39; or one of its dependencies. The system cannot find the file specified.&lt;/em&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/p&gt;  &lt;p&gt;If you are using Microsoft Office SharePoint Server 2007, you can directly write information in these logs. You have to add a reference to &lt;em&gt;Microsoft.Office.Server.dll&lt;/em&gt; DLL located in the &lt;em&gt;C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI\&lt;/em&gt; folder. Then, in your code, add the following instruction: &lt;em&gt;Microsoft.Office.Server.Diagnostics.PortalLog.LogString(“your text”);&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Visual Studio debugging&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Some processes are required to run SharePoint. One of them is used to manage and render web pages in the browser. In fact, this process is used by all ASP.NET applications and SharePoint is based on ASP.NET. So if we want to see what happens in our code, we have to attach the debugger to w3wp.exe process.To attach the debugger, go to Visual Studio and select &lt;em&gt;Attach to a process…&lt;/em&gt; in the &lt;em&gt;Debug&lt;/em&gt; menu.&lt;a href="http://didierdanse.net/blogs/dev_en/22_21289F58.png"&gt;&lt;img title="2" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="255" alt="2" src="http://didierdanse.net/blogs/dev_en/22_thumb_50E647D7.png" width="311" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Maybe you will find more than one w3wp process. If true, you can attach the debugger to all the instances of the process. &lt;/p&gt;  &lt;p&gt;Select all the w3wp instance by holding CTRL during selection. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://didierdanse.net/blogs/dev_en/12_478D1354.png"&gt;&lt;img title="1" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="454" alt="1" src="http://didierdanse.net/blogs/dev_en/12_thumb_35D29A2B.png" width="644" border="0" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;If you haven’t any w3wp process, go to your browser and open a SharePoint url so the w3wp will start to run. Then click on &lt;em&gt;Refresh&lt;/em&gt; button and select the newly process.&lt;/p&gt;  &lt;p&gt;Now you have your debugger attached to your event handler. You just have to add some breakpoints and run debugger step by step. There is a lot of features provided by Visual Studio, do not hesitate to use them (&lt;a title="http://msdn.microsoft.com/en-us/library/sc65sadd.aspx" href="http://msdn.microsoft.com/en-us/library/sc65sadd.aspx" target="_blank"&gt;Debugging in Visual Studio&lt;/a&gt;)! &lt;/p&gt;&lt;img src="http://didierdanse.net/aggbug.aspx?PostID=213" width="1" height="1"&gt;</description><category domain="http://didierdanse.net/blogs/dev_en/archive/tags/SharePoint/default.aspx">SharePoint</category><category domain="http://didierdanse.net/blogs/dev_en/archive/tags/English/default.aspx">English</category><category domain="http://didierdanse.net/blogs/dev_en/archive/tags/Dev/default.aspx">Dev</category><category domain="http://didierdanse.net/blogs/dev_en/archive/tags/Debugging/default.aspx">Debugging</category></item><item><title>SharePoint: How to set an URL column using code?</title><link>http://didierdanse.net/blogs/dev_en/archive/2009/01/11/sharepoint-how-to-set-an-url-column-using-code.aspx</link><pubDate>Sun, 11 Jan 2009 16:29:52 GMT</pubDate><guid isPermaLink="false">30b92a27-2adf-4ac9-9a55-506f6f2b3817:201</guid><dc:creator>Didier Danse</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://didierdanse.net/blogs/dev_en/rsscomments.aspx?PostID=201</wfw:commentRss><comments>http://didierdanse.net/blogs/dev_en/archive/2009/01/11/sharepoint-how-to-set-an-url-column-using-code.aspx#comments</comments><description>&lt;p&gt;It is not a trick but it can be useful for a lot of developpers. The opertaion is easy but way to assign the field can divert from what you are expecting.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;item[&lt;span class="str"&gt;&amp;quot;myfield&amp;quot;&lt;/span&gt;].Value = &lt;span class="str"&gt;&amp;quot;http://myserver.com, description string&amp;quot;&lt;/span&gt;;&lt;/pre&gt;&lt;img src="http://didierdanse.net/aggbug.aspx?PostID=201" width="1" height="1"&gt;</description><category domain="http://didierdanse.net/blogs/dev_en/archive/tags/SharePoint/default.aspx">SharePoint</category><category domain="http://didierdanse.net/blogs/dev_en/archive/tags/English/default.aspx">English</category><category domain="http://didierdanse.net/blogs/dev_en/archive/tags/Dev/default.aspx">Dev</category></item></channel></rss>