📜 ⬆️ ⬇️

We do SharePoint Web Part using xml / xsl

In this article I will explain how to make SharePoint WebPart using notepad using only xml and xsl.

About the development of web part-s has already been written earlier, it also wrote there, why, in fact, they are needed: habrahabr.ru/blogs/sharepoint/57992

In this article, we will create a WebPart that simply displays a message. By itself, it is not informative and questionable, as an example, but the task to show 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 experiences)
2. XML / text editor

Why xml / xsl?


The main advantage of this masochism is easy installation.
What NOT to do:
No need to put the assembly anywhere
No need to register an assembly anywhere
No need to edit any configs

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

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 (VS 2008) and create a “blank” for the web-part:
< webParts >
< webPart xmlns ="http://schemas.microsoft.com/WebPart/v3" >
< metaData >
< type name ="Microsoft.SharePoint.WebPartPages.DataFormWebPart, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
< importErrorMessage > Cannot import this Web Part. </ importErrorMessage >
</ metaData >
< data >
< properties >
< property name ="MissingAssembly" type ="string" > Cannot import this Web Part. </ property >
< property name ="FireInitialRow" type ="bool" > True </ property >
< property name ="TitleIconImageUrl" type ="string" />
< property name ="HelpMode" type ="helpmode" > Modeless </ property >
< property name ="CacheXslStorage" type ="bool" > True </ property >
< property name ="ViewContentTypeId" type ="string" />
< property name ="Description" type ="string" />
< property name ="DataSourcesString" type ="string" > NotSet </ property >
< property name ="AllowZoneChange" type ="bool" > True </ property >
< property name ="ParameterBindings" type ="string" null ="true" />
< property name ="PageSize" type ="int" > -1 </ property >
< property name ="TitleUrl" type ="string" />
< property name ="ViewFlag" type ="string" > 0 </ property >
< property name ="NoDefaultStyle" type ="string" > TRUE </ property >
< property name ="Direction" type ="direction" > NotSet </ property >
< property name ="UseSQLDataSourcePaging" type ="bool" > True </ property >
< property name ="ListName" type ="string" null ="true" />
< property name ="Hidden" type ="bool" > False </ property >
< property name ="DisplayName" type ="string" />
< property name ="SampleData" type ="string" null ="true" />
< property name ="HelpUrl" type ="string" />
< property name ="ChromeType" type ="chrometype" > Default </ property >
< property name ="CatalogIconImageUrl" type ="string" />
< property name ="DataFields" type ="string" />
< property name ="Default" type ="string" />
< property name ="ChromeState" type ="chromestate" > Normal </ property >
< property name ="DataSourceID" type ="string" />
< property name ="AllowClose" type ="bool" > True </ property >
< property name ="CacheXslTimeOut" type ="int" > 86400 </ property >
< property name ="AllowMinimize" type ="bool" > True </ property >
< property name ="AllowEdit" type ="bool" > True </ property >
< property name ="XslLink" type ="string" null ="true" />
< property name ="ShowWithSampleData" type ="bool" > False </ property >
< property name ="ExportMode" type ="exportmode" > All </ property >
< property name ="AllowHide" type ="bool" > True </ property >
< property name ="AllowConnect" type ="bool" > True </ property >

< property name ="Title" type ="string" > HabraSample </ property >
< property name ="Width" type ="string" > 500px </ property >
< property name ="Height" type ="string" > 400px </ property >
< property name ="Xsl" type ="string" ></ property >
</ properties >
</ data >
</ webPart >
</ webParts >


* This source code was highlighted with Source Code Highlighter .


Actually, we are interested in the following properties:
< property name ="Title" type ="string" > HabraSample </ property >
< property name ="Width" type ="string" > 500px </ property >
< property name ="Height" type ="string" > 400px </ property >
< property name ="Xsl" type ="string" ></ property >


* This source code was highlighted with Source Code Highlighter .


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

xsl:stylesheet version ="1.0" xmlns:xsl ="http://www.w3.org/1999/XSL/Transform" xmlns:ddwrt2 ="urn:frontpage:internal" >
< xsl:output method ="html" version ="1.0" encoding ="UTF-8" indent ="yes" />

< xsl:template match ="/" xmlns:ddwrt ="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" >
Hello, Habr!
</ xsl:template >
</ xsl:stylesheet >


* This source code was highlighted with Source Code Highlighter .

Now add our XSL to the webpart:
< property name ="Xsl" type ="string" >
<! [CDATA[ < xsl:stylesheet version ="1.0" xmlns:xsl ="http://www.w3.org/1999/XSL/Transform" xmlns:ddwrt2 ="urn:frontpage:internal" >
< xsl:output method ="html" version ="1.0" encoding ="UTF-8" indent ="yes" />

< xsl:template match ="/" xmlns:ddwrt ="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" >
Hello, Habr!
</ xsl:template >
</ xsl:stylesheet > ]] ></ property >


* This source code was highlighted with Source Code Highlighter .

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

Adding webpart to the page

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


We press on the Add web part, there we select the Advanced Web Part gallery and options:


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


Upload the web-part and see:


Then simply drag and drop on the page.
Walla:


Afterword


The biggest problem we encountered when writing such webpart is: 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 similar WebParts (as we did here: www.anychart.com/products/sharepoint/demos/installation.php )
3. Access to various data (for example, from a database, from a List, etc.) using xml / xsl

Well, or something else about something related to this.

Source: https://habr.com/ru/post/58134/


All Articles