Making SharePoint Web Part using xml / xsl

    In this article, I’ll show you how to make SharePoint WebPart using notepad using only xml and xsl.

    We already wrote about the development of web parts, there it was also written why, in fact, they are needed: habrahabr.ru/blogs/sharepoint/57992

    In this article we will create a WebPart that will simply show some message. In itself, it is not informative and doubtful, as an example, but the task of showing the general mechanism is quite consistent.


    What do you need


    Not so much:
    1. Access to MS SharePoint services 3.0 and the ability to edit pages with web desks (for experiments)
    2. XML / text editor

    Why xml / xsl?


    The main advantage of this masochism is its easy installation.
    What you DO NOT NEED to do:
    You do not need to put the assembly anywhere.
    You do not need to register the assembly anywhere.
    You do not need to edit any configs.

    Installing such web-parts is easy using only the Web Interface SharePoint.

    How to do it


    The process will be described briefly and without unnecessary details.
    So let's get started.
    Creating a .webpart file

    Open your favorite XML editor (I use VS 2008) and create a “blank” for the web part:

     
      
       
       Cannot import this Web Part.
      

      
       
        Cannot import this Web Part.
        True
        
        Modeless
        True
        
        
        NotSet
        True
        
        -1
        
        0    
        TRUE
        NotSet
        True
        
        False
        
        
        
        Default
        
        
        
        Normal
        
        True
        86400
        True
        True
            
        False
        All
        True
        True

        HabraSample
        500px
        400px
        
       

      

     



    * This source code was highlighted with Source Code Highlighter.


    Actually, we are interested in the following properties:
    HabraSample
    500px
    400px


    * This source code was highlighted with Source Code Highlighter.


    The first is the name of the webpart. The second and third are understandable, and in the fourth we will write XSL.
    Let's write the simplest:

    xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ddwrt2="urn:frontpage:internal">
     

     
      Hello, Habr!
     



    * This source code was highlighted with Source Code Highlighter .

    Now add our XSL to webpart:

         
     

     
      Hello, Habr!
     

    ]]>


    * This source code was highlighted with Source Code Highlighter.

    All. We save our xml to a file with the extension .webpart (for example, Habr.webpart).
    You can completely download / view the code here:
    anychart.com/batsuev/habrahabr/sharepoint-1/habr.webpart

    Adding a webpart to a page

    Everything is very simple. Open the web part page, go to edit mode:


    click on Add web part, there we select Advanced Web Part gallery and options:


    In the Browse panel on the right, switch to import:


    Install the web-part and see:


    Next, just drag and drop drag & drop onto page.
    Whale:


    Afterword


    The biggest problem we encountered while writing such webparts: we did not find normal documentation for them.

    If I liked the article, I can write about:
    1. Where to put the web-part and how to register it so that it is accessible from all pages.
    2. Creating an installer for such WebParts (as we did here: www.anychart.com/products/sharepoint/demos/installation.php )
    3. Access to various data (for example, from the database, from the List, etc. .) using xml / xsl.

    Well, or something else related to this.

    Also popular now: