Category Archives: wss3

Get SharePoint list items and export them to XML using PowerShell

Last time I was explaining how to get sharepoint 2010 list items using powershell script. Now, lets make a step forward and export those items into an XML file:

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
cls
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell;
}

$outputXmlFilePath="C:\Exports\yourfile.xml";
$webURL = "http://sharepointsite";
$listName = "listUwant2export";

$spWeb = Get-SPWeb $webURL;
$spList = $spWeb.Lists[$listName];
$spItems = $spList.GetItems();

[System.Xml.XmlTextWriter]$xml = New-Object 'System.Xml.XmlTextWriter' $outputXmlFilePath, ([Text.Encoding]::UTF8);
$xml.Formatting = "indented";
$xml.Indentation = 4;

$xml.WriteStartDocument();
$xml.WriteStartElement('root');

$spItems | ForEach-Object {

$xml.WriteStartElement('item');

$xml.WriteAttributeString("ID",$_['ID']);
$xml.WriteAttributeString("Title",$_['Title']);

$xml.WriteEndElement();
Write-Host $_['Title'];
}

$xml.WriteEndElement();

$xml.Flush();
$xml.Close();
$spWeb.Dispose();

The result will be an XML output with values as attributes.

Get items from SharePoint List using PowerShell script

For long time I wanted to dive a bit deeper into PowerShell. Hopefully I will be able to post few of the sharepoint powershell tricks here.
First one is about getting list items from a sharepoint list:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
cls
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
    Add-PSSnapin Microsoft.SharePoint.PowerShell;
}

$sourceWebURL = "http://sharepointsite"
$sourceListName = "mylist"

$spSourceWeb = Get-SPWeb $sourceWebURL
$spSourceList = $spSourceWeb.Lists[$sourceListName]
#$spSourceItems = $spSourceList.GetItems()
#$spSourceItems = $spSourceList.GetItemById("1")
$spSourceItems = $spSourceList.Items | where {$_['ID'] -eq 1}

$spSourceItems | ForEach-Object {
    Write-Host $_['ID']
    Write-Host $_['Title']
}

You can either get all the items with GetItems() method currently commented out or you can filter items by some parameters. Filter applied in the script above is also equal to the GetItemById(“1″) method.

Making a POST in Objective-C (Xcode) to SharePoint Webservice requiring Windows NTLM Authenticaton for iPhone or Ipad

Xcode logoIn my previous posts I was talking about how to use SOAP to SharePoint Webservices using different programing languages (PHP, Android – Java). I found it very convenient to be able to publish also a sample how to do the same in Xcode (Objective-C).

I also had to browse the web quite a bit. Finilly I stumbeled upon article from Ravi Dixit about the tipical webservice changing celsius to fahrenheit. Becase I was missing some steps in the code Erhan Demirci steped in. Because I also needed to authenticate this article came handy. I connected the dots, changed the SOAP request and displayed the responce in the screen (also in the log).

When creating new project in Xcode just choose View-based Application, name it “SoapSharePoint” and copy-paste the code below.

The SoapSharePointController.h code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#import <UIKit/UIKit.h>

@interface SoapSharePointViewController : UIViewController <NSXMLParserDelegate> {

    IBOutlet UILabel *output;
    NSMutableData *webData;
    NSXMLParser *xmlParser;
    NSString *finaldata;
    NSString *convertToStringData;
    NSMutableString *nodeContent;

}
@property (nonatomic,retain) UILabel *output;
-(IBAction)invokeService;

@end

And the SoapSharePointController.m file:

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#import "SoapSharePointViewController.h"

@implementation SoapSharePointViewController
@synthesize output;

-(IBAction)invokeService
{
   
        nodeContent = [[NSMutableString alloc]init];

        NSString *soapFormat = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                                "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
                                "<soap:Body>\n"
                                "<GetListCollection xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\" />\n"
                                "</soap:Body>\n"
                                "</soap:Envelope>\n"];

       
       
        NSLog(@"The request format is %@",soapFormat);
       
        NSURL *locationOfWebService = [NSURL URLWithString:@"http://localhost/_vti_bin/lists.asmx"];
       
        NSLog(@"web url = %@",locationOfWebService);
       
        NSMutableURLRequest *theRequest = [[NSMutableURLRequest alloc]initWithURL:locationOfWebService];
       
        NSString *msgLength = [NSString stringWithFormat:@"%d",[soapFormat length]];
       
       
        [theRequest addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
        [theRequest addValue:@"http://schemas.microsoft.com/sharepoint/soap/GetListCollection" forHTTPHeaderField:@"SOAPAction"];
        [theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
        [theRequest setHTTPMethod:@"POST"];
        //the below encoding is used to send data over the net
        [theRequest setHTTPBody:[soapFormat dataUsingEncoding:NSUTF8StringEncoding]];
       
       
        NSURLConnection *connect = [[NSURLConnection alloc]initWithRequest:theRequest delegate:self];
       
        if (connect) {
            webData = [[NSMutableData alloc]init];
        }
        else {
            NSLog(@"No Connection established");
        }
   
}


//NSURLConnection delegate method

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    [webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    NSLog(@"ERROR with theConenction");
    [connection release];
    [webData release];
}

-(BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
    return YES;
}

-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
    NSURLCredential *credential = [NSURLCredential credentialWithUser:@"username" password:@"password" persistence:NSURLCredentialPersistenceForSession];
    [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
}


-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSLog(@"DONE. Received Bytes: %d", [webData length]);
    NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
    NSLog(@"%@",theXML);
   
    convertToStringData = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding];
   
    output.numberOfLines = 0;
    output.text = convertToStringData;
    [output sizeToFit];
   
    [connection release];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)viewDidUnload {
    [super viewDidUnload];
}


- (void)dealloc {
    [output release];
    [convertToStringData release];
    [super dealloc];
}

@end

Also don’t forget to create a label and a button in the XIB (nib) file. Connect the the File’s Owner in outlets output to label and in the received action invokeService to button.

Or you can simply download it.

Manipulating SharePoint list items with PHP

For long time I’ve been playing around in my head with the idea to be able to connect to SharePoint Web Services with some third-party tools. Finaly I googled a bit and found quite few articles about it. I liked the most the one from http://davidsit.wordpress.com.

I am also attaching the the code for php version 5.3 with built in SOAP support. The only thing I added are the HTML tags and UTF-8 charset in order to display slovenian characters properly.

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
51
52
53
<?php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Manipulating SharePoint list items with PHP</title>
</head>
<?php
//Authentication details
$authParams = array('login' => 'yourUsername', 'password' => 'yourPassword');

/* A string that contains either the display name or the GUID for the list.
 * It is recommended that you use the GUID, which must be surrounded by curly
 * braces ({}).
 */

$listName = "TempList";
$rowLimit = '150';

/* Local path to the Lists.asmx WSDL file (localhost). You must first download
 * it manually from your SharePoint site (which should be available at
 * yoursharepointsite.com/subsite/_vti_bin/Lists.asmx?WSDL)
 */

$wsdl = "http://localhost/_vti_bin/Lists.asmx?WSDL";

//Creating the SOAP client and initializing the GetListItems method parameters
$soapClient = new SoapClient($wsdl, $authParams);
$params = array('listName' => $listName, 'rowLimit' => $rowLimit);

//Calling the GetListItems Web Service
$rawXMLresponse = null;
try{
    $rawXMLresponse = $soapClient->GetListItems($params)->GetListItemsResult->any;
}
catch(SoapFault $fault){
    echo 'Fault code: '.$fault->faultcode;
    echo 'Fault string: '.$fault->faultstring;
}
echo '<pre>' . $rawXMLresponse . '</pre>';

//Loading the XML result into parsable DOM elements
$dom = new DOMDocument();
$dom->loadXML($rawXMLresponse);
$results = $dom->getElementsByTagNameNS("#RowsetSchema", "*");

//Fetching the elements values. Specify more attributes as necessary
foreach($results as $result){
    echo $result->getAttribute("ows_LinkTitle")."<br/>";
}
unset($soapClient);
?>
<body>
</body>
</html>

In the article from David Dudok de Wit you will also find a solution for older PHP versions. You just have to include nusoap.php library

Security Trimmed Controls in SharePoint

Suppose you want to display certain WebPart (or the entire page) to limited audience. You can do this using Security Trimmed Controls. It looks like:

1
2
3
<Sharepoint:SPSecurityTrimmedControl runat=”server” Permissions=”DeleteListItems”>
Only users with DeleteListItems permissions will be able to see this content.
</SharePoint:SPSecurityTrimmedControl>

All you have to do is wrap your control with this security control and set the correct permissions in the Permissions attribute. The Permissions attribute, when used in Visual Studio or Designer, will have intellisense and will be filled with the following properties obtained from http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.spbasepermissions.aspx. Whatever permissions you specify will be required by the user in order to view the control(s) inside of the SPSecurityTrimmedControl:

Member name Description
EmptyMask Has no permissions on the Web site. Not available through the user interface.
ViewListItems View items in lists, documents in document libraries, and view Web discussion comments.
AddListItems Add items to lists, add documents to document libraries, and add Web discussion comments.
EditListItems Edit items in lists, edit documents in document libraries, edit Web discussion comments in documents, and customize Web Part Pages in document libraries.
DeleteListItems Delete items from a list, documents from a document library, and Web discussion comments in documents.
ApproveItems Approve a minor version of a list item or document.
OpenItems View the source of documents with server-side file handlers.
ViewVersions View past versions of a list item or document.
DeleteVersions Delete past versions of a list item or document.
CancelCheckout Discard or check in a document which is checked out to another user.
ManagePersonalViews Create, change, and delete personal views of lists.
ManageLists Create and delete lists, add or remove columns in a list, and add or remove public views of a list.
ViewFormPages View forms, views, and application pages, and enumerate lists.
Open Allow users to open a Web site, list, or folder to access items inside that container.
ViewPages View pages in a Web site.
AddAndCustomizePages Add, change, or delete HTML pages or Web Part Pages, and edit the Web site using a SharePoint Foundation–compatible editor.
ApplyThemeAndBorder Apply a theme or borders to the entire Web site.
ApplyStyleSheets Apply a style sheet (.css file) to the Web site.
ViewUsageData View reports on Web site usage.
CreateSSCSite Create a Web site using Self-Service Site Creation.
ManageSubwebs Create subsites such as team sites, Meeting Workspace sites, and Document Workspace sites.
CreateGroups Create a group of users that can be used anywhere within the site collection.
ManagePermissions Create and change permission levels on the Web site and assign permissions to users and groups.
BrowseDirectories Enumerate files and folders in a Web site using Microsoft Office SharePoint Designer 2007 and WebDAV interfaces.
BrowseUserInfo View information about users of the Web site.
AddDelPrivateWebParts Add or remove personal Web Parts on a Web Part Page.
UpdatePersonalWebParts Update Web Parts to display personalized information.
ManageWeb Grant the ability to perform all administration tasks for the Web site as well as manage content. Activate, deactivate, or edit properties of Web site scoped Features through the object model or through the user interface (UI). When granted on the root Web site of a site collection, activate, deactivate, or edit properties of site collection scoped Features through the object model. To browse to the Site Collection Features page and activate or deactivate site collection scoped Features through the UI, you must be a site collection administrator.
UseClientIntegration Use features that launch client applications; otherwise, users must work on documents locally and upload changes. 
UseRemoteAPIs Use SOAP, WebDAV, or Microsoft Office SharePoint Designer 2007 interfaces to access the Web site.
ManageAlerts Manage alerts for all users of the Web site.
CreateAlerts Create e-mail alerts.
EditMyUserInfo Allows a user to change his or her user information, such as adding a picture.
EnumeratePermissions Enumerate permissions on the Web site, list, folder, document, or list item.
FullMask Has all permissions on the Web site. Not available through the user interface.

XSLT display random row in SharePoint

Today I was updating a web site for a customer. They needed new web part in SharePoint do display random content. As i eventually figured out this was quite easy to do:

<xsl:variable name=”highlight” select=”ddwrt:Random(1,count($Rows))” />
<xsl:for-each select=”$Rows[position()=$highlight]”>

(I googled the code in: http://blog.allyis.com/blog/bid/29519/Randomly-Displayed-Content-in-SharePoint)

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>

Read List Items using Sharepoint Web Services and jQuery

These days you can find the samples of this code almost in every corner of the WWW. Here is my contribution. I am also adding new JavaScript function called asmx(). What is does? It gets the URL of the current Site Collection, so you don’t have to write it every time you move your code to different site or server. Just be sure it is in the root folder of your Site Collection or modify the code accordingly.

First do not forget to include the jQuery library!

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
var listName = "myList";

$(document).ready(function() {
    var soapEnv =
        "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
            <soapenv:Body> \
                 <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                    <listName>"
+listName+"</listName> \
                    <viewFields> \
                        <ViewFields> \
                           <FieldRef Name='Title' /> \
                       </ViewFields> \
                    </viewFields> \
                </GetListItems> \
            </soapenv:Body> \
        </soapenv:Envelope>"
;
   
    $.ajax({
        url: asmx(),
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        complete: processResult,
        contentType: "text/xml; charset=\"utf-8\""
    });
});

function asmx() {

    var url = window.location.href;
    var urlin = url.substring(7);
    var urlsplit = urlin.split("/");
    var dolzina = urlsplit.length - 1;
    var naslov = new Array();
    for(i = 0; i < dolzina; i++){
        var naslov = naslov + urlsplit[i] + "/";
    }
    var asmx =  "http://" + naslov + "_vti_bin/lists.asmx";
    return asmx;

}

function processResult(xData, status) {
    $(xData.responseXML).find("z\\:row").each(function() {
        var liHtml = "<li>" + $(this).attr("ows_Title") + " - " + $(this).attr("ows_Total") + "</li>";
        $("#data").append(liHtml);
    });
}

Also create some HTML markup where to insert the results:

1
<ul id="data"></ul>

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