Tag Archives: wss3

Alternative Way to Output Data in XML format from a SharePoint List Using /_vti_bin/owssvr.dll

In my previous post I explained how to create a DFWP in order to display contents of a SharePoint list in XML structured output. There is a faster way: /_vti_bin/owssvr.dll!

All you need is:

  1. The URL of your server, e.g.: http://yoursharepointserver.com
  2. The List GUID, e.g. 1CABA434-E7A6-443D-90DA-B3E7DEED245F
  3. and create a custum list view (if you need one, otherwise just use the default view: “All Items”)

Lets put it together now: server + /_vti_bin/owssvr.dll + cmd + list + view + output

In my case it looks like that:
http://mysharepointserver.com/_vti_bin/owssvr.dll?Cmd=Display&List={1CABA434-E7A6-443D-90DA-B3E7DEED245F}&View={87486B2B-71D9-4B78-956E-B05B52EB60C0}&XMLDATA=TRUE

If you are dislpaying the default “All Items” View, you can dismiss the View parameter:
http://mysharepointserver.com/_vti_bin/owssvr.dll?Cmd=Display&List={1CABA434-E7A6-443D-90DA-B3E7DEED245F}&XMLDATA=TRUE

How to Create a Custom XML Output using SharePoint Services 3.0

There are just few simple steps:

  1. Create a List
  2. Open SharePoint Designer 2007 and open a blank .aspx page.
  3. Delete all the code generated in .aspx page
  4. In the Task pane open the Data Source Library and click Show Data
  5. Select the Title field and than click Insert Selected Fields as … Multiple Item View
  6. In Change Layout select Plain List of Titles.
  7. Add XML declaration: <?xml version=”1.0″ encoding=”utf-8″ ?>
  8. Remove all HTML tags
  9. After <WebPartPages:DataFormWebPart runat=”server” add additional property SuppressWebPartChrome=”True” wich will prevent the chrome being displayed. In short: now <table> tags around the web part.
  10. Go to the <xsl:template section and replace the <p> tags with: <xsl:text disable-output-escaping=”yes”>&lt;Root&gt;</xsl:text> … – this will be the first node of the XML file. You will also need to end this tag.
  11. do the same for all other child nodes you want to display.

List in SharePoint:

XML Output:

The blank.aspx code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?xml version="1.0" encoding="utf-8" ?>
<%@ Page language="C#" inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register tagprefix="WebPartPages" namespace="Microsoft.SharePoint.WebPartPages" assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register tagprefix="SharePoint" namespace="Microsoft.SharePoint.WebControls" assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<WebPartPages:DataFormWebPart runat="server" SuppressWebPartChrome="True" IsIncluded="True" FrameType="None" NoDefaultStyle="TRUE" ViewFlag="0" Title="ListToBeXML" ListName="{98BDF941-3262-4E4E-8BC7-28D15E66393D}" Default="FALSE" DisplayName="ListToBeXML" __markuptype="vsattributemarkup" __WebPartId="{78236CF0-21FA-4FF6-AF4A-9DC1B935B435}" id="g_78236cf0_21fa_4ff6_af4a_9dc1b935b435" __AllowXSLTEditing="true" WebPart="true" Height="" Width="">
    <DataSources>
        <SharePoint:SPDataSource runat="server" DataSourceMode="List" UseInternalName="true" selectcommand="&lt;View&gt;&lt;/View&gt;" id="ListToBeXML1"><SelectParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{98BDF941-3262-4E4E-8BC7-28D15E66393D}"/></SelectParameters><DeleteParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{98BDF941-3262-4E4E-8BC7-28D15E66393D}"/></DeleteParameters><UpdateParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{98BDF941-3262-4E4E-8BC7-28D15E66393D}"/></UpdateParameters><InsertParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{98BDF941-3262-4E4E-8BC7-28D15E66393D}"/></InsertParameters></SharePoint:SPDataSource>
    </DataSources>
    <ParameterBindings>
    <ParameterBinding Name="ListID" Location="None" DefaultValue="{98BDF941-3262-4E4E-8BC7-28D15E66393D}"/>
    <ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>
    <ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>
    <ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>
</ParameterBindings>
    <datafields>@Title,Title;@Book,Book;@Writer,Writer;@Year,Year;@ID,ID;@ContentType,Content Type;@Modified,Modified;@Created,Created;@Author,Created By;@Editor,Modified By;@_UIVersionString,Version;@Attachments,Attachments;@File_x0020_Type,File Type;@FileLeafRef,Name (for use in forms);@FileDirRef,Path;@FSObjType,Item Type;@_HasCopyDestinations,Has Copy Destinations;@_CopySource,Copy Source;@ContentTypeId,Content Type ID;@_ModerationStatus,Approval Status;@_UIVersion,UI Version;@Created_x0020_Date,Created;@FileRef,URL Path;</datafields>
    <XSL>
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
    <xsl:output method="html" indent="no"/>
    <xsl:decimal-format NaN=""/>
    <xsl:param name="dvt_apos">'</xsl:param>
    <xsl:variable name="dvt_1_automode">0</xsl:variable>
    <xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls">
        <xsl:call-template name="dvt_1"/>
    </xsl:template>
   
    <xsl:template name="dvt_1">
        <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row" />
        <xsl:text disable-output-escaping="yes">&lt;Root&gt;</xsl:text>
        <xsl:call-template name="dvt_1.body">
            <xsl:with-param name="Rows" select="$Rows" />
        </xsl:call-template>
        <xsl:text disable-output-escaping="yes">&lt;/Root&gt;</xsl:text>
    </xsl:template>
   
    <xsl:template name="dvt_1.body">
        <xsl:param name="Rows" />
        <xsl:for-each select="$Rows">
            <xsl:call-template name="dvt_1.rowview" />
        </xsl:for-each>
    </xsl:template>
   
    <xsl:template name="dvt_1.rowview">
        <xsl:text disable-output-escaping="yes">&lt;item id=&quot;</xsl:text><xsl:value-of select="@ID" /><xsl:text disable-output-escaping="yes">&quot;&gt;</xsl:text>
            <xsl:text disable-output-escaping="yes">&lt;book&gt;</xsl:text><xsl:value-of select="@Book" /><xsl:text disable-output-escaping="yes">&lt;/book&gt;</xsl:text>
            <xsl:text disable-output-escaping="yes">&lt;writer&gt;</xsl:text><xsl:value-of select="@Writer" /><xsl:text disable-output-escaping="yes">&lt;/writer&gt;</xsl:text>
        <xsl:text disable-output-escaping="yes">&lt;/item&gt;</xsl:text>
    </xsl:template>
   
</xsl:stylesheet>   </XSL>
</WebPartPages:DataFormWebPart>

If you want to have more universal WebPart so you cold reuse it when saving the site as template you just have to find and replace 2 things:

  1. Find the guid (in my case: {98BDF941-3262-4E4E-8BC7-28D15E66393D}) and replace all it with name of your list (in my case ListToBeXML)
    Task 1: {98BDF941-3262-4E4E-8BC7-28D15E66393D} -> ListToBeXML
  2. Find ListID and replaceall it with ListName
    Task 2: ListID -> ListName

By searching and replacing we will get:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?xml version="1.0" encoding="utf-8" ?>
<%@ Page language="C#" inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register tagprefix="WebPartPages" namespace="Microsoft.SharePoint.WebPartPages" assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register tagprefix="SharePoint" namespace="Microsoft.SharePoint.WebControls" assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<WebPartPages:DataFormWebPart runat="server" SuppressWebPartChrome="True" IsIncluded="True" FrameType="None" NoDefaultStyle="TRUE" ViewFlag="0" Title="ListToBeXML" ListName="ListToBeXML" Default="FALSE" DisplayName="ListToBeXML" __markuptype="vsattributemarkup" __WebPartId="{78236CF0-21FA-4FF6-AF4A-9DC1B935B435}" id="g_78236cf0_21fa_4ff6_af4a_9dc1b935b435" __AllowXSLTEditing="true" WebPart="true" Height="" Width="">
    <DataSources>
        <SharePoint:SPDataSource runat="server" DataSourceMode="List" UseInternalName="true" selectcommand="&lt;View&gt;&lt;/View&gt;" id="ListToBeXML1"><SelectParameters><WebPartPages:DataFormParameter Name="ListName" ParameterKey="ListName" PropertyName="ParameterValues" DefaultValue="ListToBeXML"/></SelectParameters><DeleteParameters><WebPartPages:DataFormParameter Name="ListName" ParameterKey="ListName" PropertyName="ParameterValues" DefaultValue="ListToBeXML"/></DeleteParameters><UpdateParameters><WebPartPages:DataFormParameter Name="ListName" ParameterKey="ListName" PropertyName="ParameterValues" DefaultValue="ListToBeXML"/></UpdateParameters><InsertParameters><WebPartPages:DataFormParameter Name="ListName" ParameterKey="ListName" PropertyName="ParameterValues" DefaultValue="ListToBeXML"/></InsertParameters></SharePoint:SPDataSource>
    </DataSources>
    <ParameterBindings>
    <ParameterBinding Name="ListName" Location="None" DefaultValue="ListToBeXML"/>
    <ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>
    <ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>
    <ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>
</ParameterBindings>
    <datafields>@Title,Title;@Book,Book;@Writer,Writer;@Year,Year;@ID,ID;@ContentType,Content Type;@Modified,Modified;@Created,Created;@Author,Created By;@Editor,Modified By;@_UIVersionString,Version;@Attachments,Attachments;@File_x0020_Type,File Type;@FileLeafRef,Name (for use in forms);@FileDirRef,Path;@FSObjType,Item Type;@_HasCopyDestinations,Has Copy Destinations;@_CopySource,Copy Source;@ContentTypeId,Content Type ID;@_ModerationStatus,Approval Status;@_UIVersion,UI Version;@Created_x0020_Date,Created;@FileRef,URL Path;</datafields>
    <XSL>
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
    <xsl:output method="html" indent="no"/>
    <xsl:decimal-format NaN=""/>
    <xsl:param name="dvt_apos">'</xsl:param>
    <xsl:variable name="dvt_1_automode">0</xsl:variable>
    <xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls">
        <xsl:call-template name="dvt_1"/>
    </xsl:template>
   
    <xsl:template name="dvt_1">
        <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row" />
        <xsl:text disable-output-escaping="yes">&lt;Root&gt;</xsl:text>
        <xsl:call-template name="dvt_1.body">
            <xsl:with-param name="Rows" select="$Rows" />
        </xsl:call-template>
        <xsl:text disable-output-escaping="yes">&lt;/Root&gt;</xsl:text>
    </xsl:template>
   
    <xsl:template name="dvt_1.body">
        <xsl:param name="Rows" />
        <xsl:for-each select="$Rows">
            <xsl:call-template name="dvt_1.rowview" />
        </xsl:for-each>
    </xsl:template>
   
    <xsl:template name="dvt_1.rowview">
        <xsl:text disable-output-escaping="yes">&lt;item id=&quot;</xsl:text><xsl:value-of select="@ID" /><xsl:text disable-output-escaping="yes">&quot;&gt;</xsl:text>
            <xsl:text disable-output-escaping="yes">&lt;book&gt;</xsl:text><xsl:value-of select="@Book" /><xsl:text disable-output-escaping="yes">&lt;/book&gt;</xsl:text>
            <xsl:text disable-output-escaping="yes">&lt;writer&gt;</xsl:text><xsl:value-of select="@Writer" /><xsl:text disable-output-escaping="yes">&lt;/writer&gt;</xsl:text>
        <xsl:text disable-output-escaping="yes">&lt;/item&gt;</xsl:text>
    </xsl:template>
   
</xsl:stylesheet>   </XSL>
</WebPartPages:DataFormWebPart>

So here is the actual result of our WebPart

1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0" encoding="utf-8" ?>
<Root>
    <item id="1">
        <book>Some book</book>
        <writer>John Doe</writer>
    </item>
    <item id="2">
        <book>Another book</book>
        <writer>Jane Doe</writer>
    </item>
</Root>

How to Create a Host Header Site Collection in WSS3 and SharePoint Foundation 2010

For WSS3 and MOSS you will have to open the CMD and use “stsadm” function. Here is the syntax:

1
stsadm -o createsite -url http://yourdomain.com -owneremail user@yourdomain.com -hostheaderwebapplicationurl htt://yourwebapplication.com

You can also give a check at the Microsoft Technet reference: http://technet.microsoft.com/en-us/library/cc262594%28office.12%29.aspx

In SharePoint Foundation 2010 you will have to use PowerShell which comes with Windows Server 2008.

First run:

1
Add-PSSnapin "Microsoft.SharePoint.PowerShell"

Now lets add a new site collection with host header (be sure to configure the command accodring to your server settings – link):

1
New-SPSite http://www.newdomain.com -OwnerAlias SERVER2008\Administrator -HostHeaderWebApplication http://server2008

Sooner or later you will also like to know which Site Collections there are in you Web Application (link). You can either look for it in Central Administration but you can also run a command in PowerShell:

1
Get-SPWebApplication http://server2008 | Get-SPSiteAdministration -Limit ALL | Select URL

Finaly, you do not want to use your Site Collection any more. Lets delete it (link):

1
RemoveSPSite -Identity "http://www.deletethis.com" -GradualDelete

‘Stsadm’ is not Recognized as an Internal or External Command, Operable Program or Batch File.

Add stsadm.exe to default system paths: make your system able to execute stsadm no matter what folder you are in.

Go to Control panel > System > Advanced system setings

Under “System Variables” click Path (You will need to scroll down a bit – see the image attached). Click edit. At the end of the line add:

;C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\BIN

I was at my friend Jose Antonio Morales the other day. He had the same problem. Usualy he was solving this problem by just copying the stsadm.exe file to c:\ and than run all commands from there. But the problem with this approach is that the stsadm.exe in c:\ does not get updated, so he could not use the stsamd -o rename function.