Category Archives: SharePoint 2010 - Page 2

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

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

Unable to open Flash or HTML page in SharePoint Foundation 2010

Yesterday I succesfully set up my first SharePoint Foundation 2010 in Windows Server 2008. Everything went very smoth.

When I tried to play flash movie inside .aspx file i didn’t work. When I tried to open the flash file link directly it was starting to download the swf instead of playing it. I also tried with .html – it was also forcing the download.

I googled a bit and than stumbled upon http://paritala-sasi.blogspot.com/2009/12/opening-html-files-in-sharepoint-2010.html blog.

You need to do following steps:

  1. Open Central Administration
  2. Go to Manage web applications
  3. Select the Web application you want to configure
  4. In the ribbon click on the General Settings button
  5. Under Browser File Handling select Permissive (the explanation there should clarify what is going on)