in

didierdanse.net

Site personnel de Didier Danse
Didier Danse's Personnal Website
Microsoft Most Valuable Professional SharePoint

didierdanse.net - Development News

  • Print as PDF option with Office 2010

    Because Microsoft released a Print as PDF addin for Office 2007, a lot of people have the same reaction: go to the Internet and search for Print as PDF addin for Office 2010 but they don’t find any download.

    With Office 2010, we should call this feature Save as PDF. Let’s have a look to the save as file type options:

    image

    You will find PDF (*.pdf) option. That’s all…

  • Enter the real interoperability ECM World with Content Management Interoperability Services (CMIS)

    How many times did you hear “This product is better for this part and this product is better for all the rest”? I am pretty sure that you are not able to answer this exactly. Most of you will say “a lot of time”. Every time there is this question, we heard “We will integrate both solutions”. But what does “integrate” mean? Most part of time, the answer is “develop custom features that will meet the other solution web services specifications”. It works… until any change!

    More ways two solutions can communicate more issues you will face out. Because of this, ECM leaders (Microsoft, IBM, EMC, Alfresco, OpenText, SAP and Oracle) worked on interoperability specifications for a lot of months (about two years!) and proposed a standard way to implement communication points in the major ECM solutions. This standard is called Content Management Interoperability Services (CMIS). CMIS will reduce difficulties about interoperability in a heterogeneous environment.

    This specification has been proposed to Oasis consortium. After public vote, CMIS specifications have been approved.

    Read the complete announcement from Oasis : http://www.oasis-open.org/news/oasis-news-2010-05-04.php

    Normally, CMIS Connector will be available in the beginning of July through the SharePoint Administrator Toolkit. We hope that all vendors will implement and deploy CMIS soon.

  • Software Development Kits and Training Kits available for developers

    A few days ago, someone ask me where he was able to find some information about SharePoint and Office development. Here are some interesting links:

    SharePoint 2010: http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=f0c9daf3-4c54-45ed-9bde-7b4d83a8f26f

    SQL Server 208 R2: http://www.microsoft.com/downloads/details.aspx?familyid=FFFAAD6A-0153-4D41-B289-A3ED1D637C0D&displaylang=en

    Office 2010: http://www.microsoft.com/downloads/details.aspx?FamilyID=b90fadab-f4f9-4452-aa61-ed7bd5d8111e&displaylang=en

    Identity: http://www.microsoft.com/downloads/details.aspx?familyid=C3E315FA-94E2-4028-99CB-904369F177C0&displaylang=en

    There are others SDK and Training Kits that are available. Do not hesitate to do have a deeper look to.

  • Windows Server 2008 Server doesn’t detect any wireless, what can I do?

    You installed your wireless network adapter and you feel happy until you see that Windows Server 2008 (R2) is not able to find any network. Does your adapter is not compatible with Windows Server 2008? Maybe… But before buying another one, be sure that Windows Server has the Windows LAN Service feature is active.

    Go to the server Configuration tasks. Click on Add features.

    Untitled 2

    Check Wireless LAN Service

    Untitled 1

    and enjoy!

    Thanks a lot to Marc Donnay for the tip!

  • SharePoint 2010 Certifications

    New SharePoint certifications are (nearly) here. By reading the content of these certifications, it seems that they are a little bit difficult compared to previous SharePoint certifications.

    You will find more information by following the links:

    Exam 70-667: TS: Microsoft SharePoint 2010, Configuring http://www.microsoft.com/learning/en/us/exam.aspx?ID=70-667&locale=en-us

    Exam 70-668: PRO: Microsoft SharePoint 2010, Administrator http://www.microsoft.com/learning/en/us/exam.aspx?ID=70-668&locale=en-us

    Exam 70-573: TS: Microsoft SharePoint 2010, Application Development http://www.microsoft.com/learning/en/us/exam.aspx?ID=70-573&locale=en-us

    Exam 70-576: PRO: Designing and Developing Microsoft SharePoint 2010 Applications http://www.microsoft.com/learning/en/us/exam.aspx?ID=70-576&locale=en-us

  • How to show Developer tab in Office 2010

    Because there is some changes in Office 2010 about the way to display the developer tab in Microsoft Office 2010, here is a quick update about how to do this with Office 2010.

    The following screenshots come from Microsoft Word.

    • Go to File tab;

    image

    • In the Customize Ribbon zone, check Developer menu item.

    image

    • Go back to your application. The developer tab is there.

    image

  • SharePoint 2010: All about Document Set

    There is a lot of situations that requires the use of multiple files. These files are grouped and has to be considered as an unique item.

    With SharePoint 2007, the only way to group documents together were to use folders. Now we have a way to manage, edit and shared metadata between each element of a group of files directly in the user interface without any custom development. This feature is named Document Set.

    Document set is new in SharePoint 2010 and is really an interesting concept that we were waiting for a long time. So let have a global overview of this new content type available as a site collection feature.

    Quick overview

    When adding a new document set, this screen pops up:

    image

    After saving the new document set, it is available as an item in a SharePoint document library.

    image

    Document set is displayed as a web page with some metadata about the document set and a list with contained documents.

    image

    As you may know, ribbon is new in SharePoint 2010 and is available on each page. When a document set is loaded, the following ribbon items are available. We will discuss each of these features in the next paragraphs.

    image image 

    Versioning 

    There is the possibility to create version of a document set and also versions for the documents in the document set. So you can create a lot of documents versions before creating a document set version.

    Document versioning is performed as usual. According to your settings, new version is created when uploading the document or modify it. Version history is similar to the feature that was available in SharePoint 2007.

    image

    Because Document Set is a content type, we can use versioning and so on. Document set version is a snapshot of related documents with the latest versions captured when clicking on Capture Version in the ribbon.

    image 

    Because minor versions can be considered as draft, we can check which documents versions should be used:

    • Latest major versions only;
    • Latest major or minor versions.

    We also have the possibility to add a comment to the document set version.

    image

    Document set version history will display versions of the document set itself but also the captured versions of the documents in the document set.

    image

    Metadatas

    Metadatas can be shared (applied) across the different documents in the document set. So you just have to add the metas to the document set and every document in the document set will use the same metadatas.

    It is a very simple feature but it is really something that was missing before. Now you can perform more efficient searches as every file has the metadata on it.

    Workflows

    Version capture and content changes can happened on document sets. These events can be used to run workflows. Really useful for global approve on a set of documents.

    image

    Because documents contained in the document set are group of unique documents, workflow can be attached to each document as we did with SharePoint 2007.

    image

    By using both workflow levels, we can run a lot of scenarios. Approval can be applied to individual documents and to a set of documents.

    Permissions

    Permissions set at document level are, by default, inherited from the document set itself.

     image

    You can configure permissions on each individual document within the document set. Sometimes it is necessary to grant access to a document to a particular user but not all the other documents. That’s the same way to manage permissions within a document library.

    Because there is a lot of other possibilities, we will just tell that every feature available at document level is available for document set level. Just remember that document set is considered as an item.

    Download

    Unfortunately, there is no way to download all the files in the document set.

    Document Set Welcome page

    Document set have welcome page that can be customized. As you can see on the following screen, there is the possibility to add some web part on the welcome page of a document set.

    It can really be useful for displaying information about the document set itself as the document set is can be considered as an single item or a set of different files that are related each other.

    image 

    How to set up document set?

    Document set is a content type. Content type will be available as soon as Document Sets feature will be activated. You need to have permissions at site collection level before activating this feature.

    To enable this content type, go through the following screens:

    • Click on Site Settings

    image

    • Go to Site collection features

    image

    • Activate the Document Sets feature

    image

    The new content type is now available but need to be activated at document library level.

    • Click on Library Settings for the library that will contains Document Sets

    image

    • You have to go to the advanced settings page…

    image

    • … and then check the allow management of content types box.

    image

    • On the Settings page, click on Add a new content type

    image

    • Now, Document Set is available in your document library

    image

    Have a great day!

  • Microsoft License Advisor

    Do you need to have information about Microsoft licensing? There is a website that is available from Microsoft. You can configure products and calculate costs.

    image

    http://www.microsoft.com/licensing/mla/default.aspx

    According to first tests, it should be interesting that the tool select automatically requirements. Merging information on product description with information in the tool will permit to have a global overview of cost.

  • SharePoint 2010 Foundation Language Packs available

    To download it, follow the link: http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=646e311a-aaf3-4d30-b03c-2f3c70d19a22

    Installation is really easy. The only point that can cause some trouble is the correct language pack download. Most of SharePoint administrators have already download English Language pack instead of expected file. Indexes in Google or Bing contains information in different languages. This content is related to the same url. But depending on your regional settings, page will certainly be displayed in English. That’s why a query using French terms will bring us to a English Language Pack download page and we install English Language Pack on a SharePoint in English. So be sure to select the correct language as shown on the following screenshot:

    image 

    Note that most usual Language Packs use between 110 and 170MB. Here is a sample with French L.P. (We can show that filename that is send by download server is not really explicit):

    image

    After this, you know what to do… next, next et next :-)

    image image image 

    image image

    As indicated, be sure to run the configuration wizard as soon as you have the possibility!

    After this, go to the site settings of a SharePoint site. You’ll see a Language settings.

    image

    By clicking on the link, you will have the possibility to select available languages for your site:

    image

    Users will be able to select the display language they prefer…

    image

    Everything that is "out-of-the-box" is translated (menus, ribbon, …)

    image 

    There is a lot of other features about multilinguism. I will certainly publish some other posts about it in the next few weeks.

  • SharePoint: How to modify passphrase?

    When installing SharePoint, you have to define a passphrase which is used for service accounts and other stuff. As usual in a test envrionment, you lost the passphrase and you need to change it.Once again, Powershell is the solution.

    First thing, we have to see which CmdLet is available to perform passphrase operations…

    PS C:\Users\Administrator> get-command *passp* 
    
    CommandType     Name                            Definition 
    -----------     ----                            ---------- 
    Cmdlet          Set-SPPassPhrase                Set-SPPassPhrase -PassPhrase... 

    There is only one. Passphrase need to be a secure string so we have to convert our passphrase to a secure string.

    PS C:\Users\Administrator>  $passphrase = ConvertTo-SecureString -asPlainText -Force 
    
    cmdlet ConvertTo-SecureString at command pipeline position 1 
    Supply values for the following parameters: 
    String: P2ssw0rd 

    We can use the secured version of the passphrase in the set method to change the stored passphrase:

    PS C:\Users\Administrator> Set-SPPassPhrase -PassPhrase $passphrase -Confirm 
    
    cmdlet Set-SPPassPhrase at command pipeline position 1 
    Supply values for the following parameters: 
    ConfirmPassPhrase: ******** 
    
    Confirm 
    Are you sure you want to perform this action? 
    Performing operation "Set-SPPassPhrase" on Target "SPPassPhrase". 
    Yes Yes  Angel Yes to All  No No  [L] No to All  Sleep Suspend  [?] Help 
    (default is "Y"):y 

    Easy to do, isn’t it?

  • SharePoint Quotas Overview

    SharePoint comes with an interesting feature: Site quotas. It is quite easy to implement it but there is still a lot of questions about this. SharePoint quotas are used the same way with SharePoint 2007 and SharePoint 2010.

    First of all, a short definition of quota term: Quota is a restriction of quantity. In the case of SharePoint, quantity is data volume.

    Quota scope

    Quota can be used at site collection (SPSite) level only. There is no way to use it with site (SPWeb) or list. It is quite important to know this limitation as logical architecture will be impacted by quota needs.

    Quota template

    Quota template is a set of three properties:

    • Template Name;
    • Limit site storage;
    • Warning email level

    These properties are configurable through the interface.

    image

    You can configure quota templates through the user interface in the central administration. Because of this, you need farm administrator permission.

    image

    Full Quota template user interface:

    image 

    Applying / removing quota to / from a site collection

    In the Central Administration, you can apply quota to a site collection.

    image

    You can also use the object model (SPSite.Quota) or Powershell to perform this operation.

    Storage Space Allocation page

    As a site collection administrator, you can have a overview of the space used by documents in the site collection. Just go to the site collection settings and click on Storage space allocation. This link will show the following page: /_layouts/storman.aspx">http://<site_url>/_layouts/storman.aspx

    image

    If the link is not available, it is pretty sure that quotas are not active on your site collection. You can try to navigate directly to the page but you will see a error message instead :-) This message is

    The storage space allocation page cannot be used for sites that do not have a storage quota defined.

    image

    So, have a quick overview of these simple but useful reports. You will have the choice between several display modes. First one is “Document libraries” as it is the most space consumer.

    image

    But you also have to possibility to list files instead of libraries…

    image

    Unfortunately, we cannot have access to more than 100 items using the interface. The only way to do this is to create a custom page.

    Hope it helps! Have a good day

  • Announcing DotNetHub !

    I’ve been working with some friends on a project for a while now, and it is finally time to talk about it more publicly as it is eventually coming to life : DotNetHub !

    DotNetHub is a new community about the Microsoft .Net Platform as well as the Agile Methodologies.

    DotNetHub will be a bit particular for 2 reasons:

    • First, it will be dedicated mainly to french-speaking people, mostly living in Belgium, Luxembourg, France & Switzerland (but, if you are elsewhere, don’t hesitate to contribute !). Why only french-speaking people ? Simply because there are already tons of english-speaking communities, all very good, but my friends and I felt that there was a void to be filled, especially here in Belgium (French people have DotNetGuru & Tech Head Brothers !).
    • Secondly, as mentioned, we will not only focus on technological aspects but also on the methodological ones, something that we find missing in other communities, but that is nonetheless as important. Bringing those two aspects together in the events & conferences we are going to organize will be a big challenge, but it’s worth it !

    We’re hoping to have many people joining us in order to create a very dynamic community. We are also actively looking for sponsors … so if you’re interested, please contact us.

    I’m already very happy to announce that our first event will take place on the 20th of January with Jonathan “Peli” de Halleux from Microsoft Research, who will talk about “Stubs, Moles & Pex“. Go register on the website, the number of places is limited !

    If you have any questions, suggestions, comments, … please visit us ! :-)

    Update : A more detailed presentation in french by Pierre-Emmanuel can be found here.

    (originally posted by Steve Degosserie on his blog: http://blog.yoot.be/index.php/2009/12/14/announcing-dotnethub/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+Yoot+%28Yoot%29)

  • SharePoint: How to limit available site templates for site creation

    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.

    The easiest way to do this is to click on Page Layouts and Site Templates on the Site Settings page. This link points at //_Layouts/AreaTemplateSettings.aspx">//_Layouts/AreaTemplateSettings.aspx">http://<yoursharepointurl>/<sitename>/_Layouts/AreaTemplateSettings.aspx 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.

    On this page, you will be able able to select site templates from available site templates list: 

    From a developer or an administrator perspective, there is also the possibility to use some code to manage available site templates.

    Here is a example of this code:

    public void SetAvailableTemplates(List<string> templateNames)
    {
         SetAvailableTemplates(templateNames, 0);
    }
    
    public void SetAvailableTemplates(List<string> templateNames, uint lcid)
    {
        using (SPSite site = new SPSite("http://<yoursharepointurl>/<sitename>"))
        {
            using (SPWeb web = site.OpenWeb())
            {
                if (lcid == 0) lcid = web.Language;
                Collection<SPWebTemplate> availablesTemplates = new Collection<SPWebTemplate>;
                foreach (SPWebTemplate template in site.GetWebTemplates(lcid))
                    if (templateNames.Keys.Contains(template.Name))
                        availablesTemplates.Add(template);
            
                if (availablesTemplates.Count > 0)
                {
                   // Code is different if site is a publishing site or not as some properties and methods are not exposed directly
                    if (PublishingWeb.IsPublishingWeb(web))
                    {
                        PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
                        if (lcid == 0) publishingWeb.SetAvailableCrossLanguageWebTemplates(availablesTemplates, false);
                        else publishingWeb.SetAvailableWebTemplates(availablesTemplates, lcid, false);
                    }
                    else
                    {
                        if (lcid == 0) web.SetAvailableCrossLanguageWebTemplates(availablesTemplates);
                        else web.SetAvailableWebTemplates(availablesTemplates, lcid);
                        web.AllProperties["__InheritWebTemplates"] = false.ToString();
                        web.Update();
                    }
                }
            }
        }
    }

    Now you can package this as a STSADM extension, a feature or anything else that can be imagined to manipulate your SharePoint.



  • SharePoint: Farm, web application, sites collection, sites and subsites, how to know what to use?

    Because of the scalability of SharePoint, each one who has to organize a SharePoint infrastructure is quickly set against an important question: What to use and at what time? There isn’t only one answer to this. Each element that composes an complete Infrastrcutre has typical properties and objectives. So we have to use the best container according to objectives and content.

    There is some kind of containers. The most important are:

    • 1a) SharePoint Farm (SPFarm from a SharePoint point of view)
    • 1b) Shared Services Provider
    • 2) Web Application (SPWebApplication)
    • 3) Sites Collection (SPSite)
    • 4) Sites (SPWeb)
    • 4) Sub sites (SPWeb)

    Mainly the first four elements (in blue) are used for technical reasons while the two other ones are used to structure sites and data from a logical point of view.

    So have a quick look through elements that are used in a SharePoint infrastructure. For more details, please use the best tool in the developers’ world: Internet.

    1.A) SharePoint Farm

    A SharePoint farm is a group of front-end servers, applicative servers (Shared Services), indexing servers and database servers. A SharePoint farm can be deployed to a particular location according to objectives (Internet access, geographical localization, …).

    image

    1.B) Shared Services Provider

    SharePoint Services Provider (SSP) is the composition of some farm-level services. These services are shared between all web applications and thus also between sites collections.

    These services are responsible of:

    • User Profile (profile properties, synch parameters)
    • Search (scopes, properties mappings, content sources, …)
    • Excel Services
    • Business Data Catalog

    image

    It is possible to use more than one SSP but it is highly recommended not to use more than useful. Using a lot of SSP can result to a complex SharePoint administration.

    2) Web Application

    There is nothing new for ITs or developers that already worked with sites or applications powered by ASP.NET, PHP or all server-side technologies. A web application characteristics are:

    • A site in IIS
    • A particular url
    • A authentication method associated with this web application

    image

    We can notice that a web application uses its own database in a SharePoint context (to be more precise, it is the case for new application. There is the possibility to create Web Applications extensions. These extensions can use different parameters that the main web application. We will use this when we want to share data between web applications and use different authentication modes for example).

    Furthermore, SharePoint is an ASP.NET application so it uses Web.config files. We will be able to add differents entries according to the objectives of the web application. We will remove some features if the web application is used by partners for example.

    Finally, a web application is always associated with a SSP.

    3) Sites Collection

    A sites collection is a virtual container (there is no physical file as it is the case for previously described elements) and sites collection structure is stored in a configuration database.

    Form an IT point of view, sites collection has some advantages. The main advantages are:

    • Content quota templates
    • Ease of maintenance (backup / restore is performed by site collection by default)

    image

    From a content manager point of view, we will notice that an administrator is defined each site collection. This administrator can manage:

    • Second level Recycle bin
    • Customized search
    • Users of the site collection

    Lastly, site collections is used to bring customized elements together and shared them with a audience that will access data across this sites collection (per example a department):

    • Master Pages
    • Images
    • Sites and lists Templates
    • Web parts

    There is always a root site in a site collection.

    image

    4) Sites and subsites

    In the beginning of this post, we told a lot of time of IT guys, a little bit about developers but I didn’t told about about end users even though they are the driving force of SharePoint content.

    At this level, everything is related to content management. According to the users permissions, they can:

    • Create sites
    • Create lists
    • Attach workflow to lists
    • Grant permissions
    • Restore deleted content
    • A lot of others operations!

    At this level, there is only one important thing to manage and organize data: company best practices and rules. It doesn’t matter where data are logically based, it will be physically stored in the same database. However, data should be spread all around sites and sub-sites. Do not hesitate to use important feature as permissions inheritance. It will help to organize data efficiently.

    image

    It is possible to add some code or reporting tools but the most important thing is the end-user and power-user training.

     

    Here is a SharePoint structure example:

    • Farm
      • Web Application 1
        • Sites collection A (with top-level site)
          • Site A.1
            • Site A.1.1
            • Site A.1.2
          • Site A.2
        • Sites collection B (with top-level site)
          • Site B.1
            • Site B.1.1
              • Site B.1.1.1
          • Site B.2
      • Web Application 2
        • Sites collection C (with top-level site)
          • […]
        • Sites collection D (with top-level site)
          • […]

     

    There is a lot things to write about this topic. I hope that you will have an understandable overview of SharePoint infrastructure and also the reasons of getting information from Internet or specialist.



  • SharePoint: How to use SPWebConfigModification class

    SharePoint provides a API that allows developers to modify web.config on all web front-end servers at the same time. This is really a nice concept as soon as it is used the correct way. All web.config modifications should (I could stay must) be performed through the API. Any direct change to web.config files can result in changes lost as this API will override entries in the config file.

    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, this API is poorly documented. 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.

    SPWebConfigModification usual members

    First of all, a web config modification is described with a name, an owner name, an xpath value to define location of the change and a value.

    So if you want to add 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 <action param1=’value1’ param2=’value2’ param3=’value3’ /> and you know that only param3 should be changed, you have to define Name parameter to action [@param1=’value1’] [@param2=’value2’]. 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: 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.

    Owner property is also really useful. We will use it to know which entries we have to delete when deactivating the feature.

    Feature sample

    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.

    Feature.xml

    <?xml version="1.0" encoding="utf-8"?>
    <Feature  Id="1625EAF0-F3EB-4c4a-AB8A-36FDBD878AE8"
              Title="Company_FeatureName"
              Description="Used to add some entries in the web.config"
              Version="12.0.0.0"
              Hidden="FALSE"
              Scope="WebApplication"
              DefaultResourceFile="core"
              ReceiverAssembly="Company.FeatureName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0a1bc23456d78ef9"
              ReceiverClass="Company.FeatureName.WebConfigModificatorFeatureReceiver"
              xmlns="http://schemas.microsoft.com/sharepoint/">
      <ElementManifests />
    </Feature>

    Feature receiver

        class WebConfigModificatorFeatureReceiver : SPFeatureReceiver
        {
            private const string SPWebConfigModificationOwner = "OwnerName";
    
            public override void FeatureActivated(SPFeatureReceiverProperties properties)
            {
                string name, xpath, value;
    
                SPWebApplication webApp = (SPWebApplication)properties.Feature.Parent;
    
                #region ..: appSettings :..
                name = "add[@key='TrustedGroup']";
                xpath = "configuration/appSettings";
                value = "<add key='TrustedGroup' value='Trusted' />";
                ModifyWebConfig(webApp, name, xpath, value, SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode);
    
                name = "add[@key='KeyName']";
                xpath = "configuration/appSettings";
                value = "<add key='KeyName' value='Value' />";
                ModifyWebConfig(webApp, name, xpath, value, SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode);
                #endregion
     
                try
                {
                    webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
                }
                catch (Exception ex)
                {
                    RemoveAllModifications(properties);
                    throw ex;
                }
            }
    
            public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
            {
                RemoveAllModifications(properties);
    
                try
                {
                    SPWebApplication webApp = (SPWebApplication)properties.Feature.Parent;
                    webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.EventLog eventLog = new System.Diagnostics.EventLog();
                    eventLog.Source = SPWebConfigModificationOwner;
                    eventLog.WriteEntry(ex.Message);
                    throw ex;
                }
            }
    
            private void RemoveAllModifications(SPFeatureReceiverProperties properties)
            { 
                SPWebApplication webApp = (SPWebApplication)properties.Feature.Parent;
    
                List<SPWebConfigModification> modificationsToRemove = new List<SPWebConfigModification>();
    
                foreach (SPWebConfigModification modification in webApp.WebConfigModifications)
                    if (modification.Owner == SPWebConfigModificationOwner)
                        modificationsToRemove.Add(modification);
    
                foreach (SPWebConfigModification modification in modificationsToRemove)
                    webApp.WebConfigModifications.Remove(modification);
    
                webApp.Update();
            }
    
            private void ModifyWebConfig(SPWebApplication webApp, String nameModif, String pathModif, String valueModif, SPWebConfigModification.SPWebConfigModificationType typeModif)
            {
                SPWebConfigModification modification = new SPWebConfigModification(nameModif, pathModif);
                modification.Value = valueModif;
                modification.Sequence = 0;
                modification.Type = typeModif;
                modification.Owner = SPWebConfigModificationOwner;
    
                try
                {
                    webApp.WebConfigModifications.Add(modification);
                    webApp.Update();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.EventLog eventLog = new System.Diagnostics.EventLog();
                    eventLog.Source = SPWebConfigModificationOwner;
                    eventLog.WriteEntry(ex.Message);
    
                    throw ex;
                }
            }
    
            public override void FeatureInstalled(SPFeatureReceiverProperties properties) { }
    
            public override void FeatureUninstalling(SPFeatureReceiverProperties properties) { }
        }

    Catching exception during ApplyWebConfigModifications

    If you run two ApplyWebConfigModifications simultaneously, an exception will be thrown during the second operation and modifications are not sent (I know, I said  simultaneously, I should say if you execute a ApplyWeConfigModifications before the end of another ApplyWebConfigModifications). 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.

    Scope of modifications

    What about the scope? Web config modifications can be applied by web application. 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.

    Entries conflicts

    Unfortunately, SharePoint doesn’t provide a solution for web.config conflict values (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.

    Entries modifications through UI

    Last but not least, 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. You can find such a page here: http://blog.thekid.me.uk/archive/2007/03/24/web-config-modification-manager-for-sharepoint.aspx

    Hope this post will help!



More Posts Next page »
L'auteur du site ne peut être tenu responsable des dommages que les informations fournies pourraient entraîner. Tout est cependant mis en oeuvre pour éviter tout désagrément.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems