Top Menu

Monday, December 3, 2012

Backup and Restore SharePoint Site

Site Collection Backup and Restore

Backup: 
stsadm -o backup -url http://site1.com/sitecoll1 -filename c:\backup\backup1.dat
Restore: 
stsadm -o restore -url http://site2.com/sitecoll1 -filename c:\backup\backup1.dat -overwrite


Export and import a subsite, list, or library

Export:
stsadm -o export –url http://site1.com/sites/portal/Shared%20documents –filename c:\backup\lib.bak -quiet -overwrite 
Import:
stsadm -o import –url http://site2.com/sites/portal/Shared%20documents –filename c:\backup\lib.bak -quiet


Wednesday, September 19, 2012

JQuery: Batch update the list items via Lists.asmx

Quick JQuery script to batch update the list items via Lists.asmx.

I have two lists Projects(Title, ProjectStatus) and Teams(Title, Project, ProjectStatus). Team.Project is a lookup column from Projects.Title and I want to update Teams.ProjectStatus when Projects.ProjectStatus is updated in the Projects list via EditForm.aspx. Now we can link two columns from projects list into the Teams list but can not connect them together in the Teams list, so following script was a great help. It batch updates the Teams.ProjectStatus once Project.ProjectStatus is updated.

Thanks to the this post I found 100% functionality ready to go.


<script type="text/javascript" src="/Scripts/jquery-1.8.1.min.js"></script>

<script type="text/javascript">

var strProject = "";
var strProjectStatus = "";

function PreSaveItem()
{
 strProject = document.getElementById('ctl00_m_g_f2d95e24_befb_49d2_b15f_823d71c9c758_ctl00_ctl04_ctl00_ctl00_ctl00_ctl04_ctl00_ctl00_TextField').value;
 strProjectStatus = document.getElementById('ctl00_m_g_f2d95e24_befb_49d2_b15f_823d71c9c758_ctl00_ctl04_ctl01_ctl00_ctl00_ctl04_ctl00_DropDownChoice').value;
 
 GetProjectID();
  
 return true;
}

function GetProjectID(){

var soapEnv = "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
<soap:Body> \
    <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
        <listName>Teams</listName> \
        <query><Query><Where><Eq><FieldRef Name='Project'/><Value Type='Text'>"+ strProject +"</Value> </Eq></Where></Query></query> \
        <viewFields> \
            <ViewFields> \
                <FieldRef Name='ID' /> \
                <FieldRef Name='Title' /> \
            </ViewFields> \
        </viewFields> \
        <rowLimit>99999</rowLimit> \
        <queryOptions xmlns:SOAPSDK9='http://schemas.microsoft.com/sharepoint/soap/' ><QueryOptions/> \
        </queryOptions> \
    </GetListItems> \
</soap:Body> \
</soap:Envelope>";

jQuery.ajax({
url: "/itsglobal/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: ResultMethod,
contentType: "text/xml; charset=\"utf-8\""
});

}

function ResultMethod(xData, status) 
{

    if (status=="success")
    {
        var oldbatch = "";
        $(xData.responseXML).find("z\\:row").each(function() 
        {
            oldbatch = AddTobatch(oldbatch, $(this).attr("ows_ID"));
        });
        
        UpdateTeamItem(oldbatch);
    }

}

function AddTobatch(oldbatch, itemId)
{

//Specify the batch query
var _batch = "<Method ID='1' Cmd='Update'><Field Name='ID'>" + itemId +"</Field><Field Name='ProjectStatus'>"+ strProjectStatus +"</Field></Method>";
oldbatch = oldbatch + _batch;

return oldbatch;
}

function UpdateTeamItem(batch) 
{
var soapEnv = "<?xml version=\'1.0\' encoding=\'utf-8\'?> \
<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/\'> \
<soap:Body> \
<UpdateListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
<listName>Teams</listName> \
<updates> \
<Batch OnError='Continue'>" + batch + "</Batch> \
</updates> \
</UpdateListItems> \
</soap:Body> \
</soap:Envelope>";

$.ajax({
url: "/itsglobal/_vti_bin/lists.asmx",
beforeSend: function(xhr) { xhr.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
},
type: "POST",
dataType: "xml",
data: soapEnv,
complete: updateResult,
contentType: "text/xml; charset=\"utf-8\""

});
}

function updateResult(xData, status) {
if (status != 'success' )
    alert("Update Project Status in Teams library failed");
}


</script>

JQuery: Read list Item via Lists.asmx

Following JQuery script is to get list items using Lists.asmx web service in MOSS 2007:
<script type="text/javascript" src="/Scripts/jquery-1.8.1.min.js"></script>
<script type="text/javascript">

//This function will call when OK button will be pressed on a List's default form (e.g. EditItem.aspx).

function PreSaveItem()
{
 var project = "Project A";
 
 GetProjectID(project);
 
 return true;
}

function GetProjectID(project){

var soapEnv = "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
<soap:Body> \
    <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
        <listName>Teams</listName> \
        <query><Query><Where><Eq><FieldRef Name='Project'/><Value Type='Text'>"+ project +"</Value> </Eq></Where></Query></query> \
        <viewFields> \
            <ViewFields> \
                <FieldRef Name='ID' /> \
                <FieldRef Name='Title' /> \
            </ViewFields> \
        </viewFields> \
        <rowLimit>99999</rowLimit> \
        <queryOptions xmlns:SOAPSDK9='http://schemas.microsoft.com/sharepoint/soap/' ><QueryOptions/> \
        </queryOptions> \
    </GetListItems> \
</soap:Body> \
</soap:Envelope>";

jQuery.ajax({
url: "/itsglobal/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: ResultMethod,
contentType: "text/xml; charset=\"utf-8\""
});

}

function ResultMethod(xData, status) 
{

    if (status=="success")
    {
        alert(status);
        $(xData.responseXML).find("z\\:row").each(function() 
        {
            alert($(this).attr("ows_ID"));
        });
    }

}

</script>
I have copied this script from the internet and have tweaked it a bit to work with JQuery 1.8 version.

Tuesday, August 28, 2012

SharePoint 2007 - Save RSS Feed into List using JQuery

The idea is to fetch the RSS feed from multiple sources and then save into the SharePoint 2007 List so that we can perform search, archive the RSS news, display data nicely in Data View etc etc.



The following JQuery script will fetch the RSS feed from multiple sources and then save the data into the SharePoint 2007 list via lists.asmx:
<script src="/Scripts/jquery-1.8.0.min.js" type="text/javascript"></script>


<script type="text/javascript">
  
    function LoadFeed() 
    {
        var varFeedURL = new Array();
            varFeedURL[0] = "http://feeds.bbci.co.uk/news/business/rss.xml";
            varFeedURL[1] = "http://www.ft.com/rss/home/uk";
            varFeedURL[2] = "http://www.ft.com/rss/home/us";

            for (i = 0; i < varFeedURL.length; i++)
            {

                $.get(varFeedURL[i], function(data) {
                    var $xml = $(data);
                    $xml.find("item").each(function() {
                        var $this = $(this),
                            item = {
                                title: $this.find("title").text(),
                                link: $this.find("link").text(),
                                description: $this.find("description").text(),
                                pubDate: $this.find("pubDate").text()
                        }
                        
                        
                        //Show only Today's Items
                        var a = new Date(item.pubDate);
                        var b = new Date(); //Today's Date
                        
                        var msDateA = Date.UTC(a.getFullYear(), a.getMonth()+1, a.getDate());
                           var msDateB = Date.UTC(b.getFullYear(), b.getMonth()+1, b.getDate());
                                                   
                        if (parseFloat(msDateA) == parseFloat(msDateB))
                        {
                        
                            var content = document.getElementById('content');
                            content.appendChild(document.createTextNode(item.title)); 
                            content.appendChild(document.createElement('br'));
                            content.appendChild(document.createTextNode(item.description));
                            content.appendChild(document.createElement('br'));
                            content.appendChild(document.createTextNode(item.link));
                            content.appendChild(document.createElement('br'));
                            content.appendChild(document.createElement('hr'));
                            
                            CreateNewItem(item.title, item.description, item.link);
                        }
                        
                    });
                });
            }
        alert('Done');
    }        
        
        
        function CreateNewItem(varTitle, varDescription, varLink) 
        {
                    var batch =
                        "<Batch OnError=\"Continue\"> \
                            <Method ID=\"1\" Cmd=\"New\"> \
                                <Field Name=\"Title\">" + varTitle + "</Field> \
                                <Field Name=\"Description\">" + varDescription + "</Field> \
                                <Field Name=\"Link\">" + varLink + "</Field> \
                            </Method> \
                        </Batch>";
                
                    var soapEnv =
                        "<?xml version=\"1.0\" encoding=\"utf-8\"?> \
                        <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/\"> \
                          <soap:Body> \
                            <UpdateListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\"> \
                              <listName>RSSData</listName> \
                              <updates> \
                                " + batch + "</updates> \
                            </UpdateListItems> \
                          </soap:Body> \
                        </soap:Envelope>";
                
                    $.ajax({
                        url: "http://portalstg.amr.kworld.kpmg.com/_vti_bin/lists.asmx",
                        beforeSend: function(xhr) {
                            xhr.setRequestHeader("SOAPAction",
                            "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
                        },
                        type: "POST",
                        dataType: "xml",
                        data: soapEnv,
                        complete: processResult,
                        contentType: "text/xml; charset=utf-8"
                    });
                }
                
                function processResult(xData, status) {
                    //alert(status);
                }
        
  
    </script>

<input id="btnGo" onclick="LoadFeed()" type="button" value="Get RSS Data" />


Ref: http://weblogs.asp.net/jan/archive/2009/04/10/creating-list-items-with-jquery-and-the-sharepoint-web-services.aspx


Thursday, August 9, 2012

SharePoint 2013 - Facebook style Discussion with Like Button

This post has also been published at NothingButSharePoint.

The famous Facebook Like is one of the features that everybody want these days so that they can like/unlike everything they can read and see over the internet. I was exploring SharePoint 2013 Technical Preview's new features and how to use them in real world scenarios when I came across the amazing new Discussion Board list and its configuration settings so that users can like/unlike a discussion, comment and a reply. 

First I am going to show the new features (displayed in the image below) and then I will show you how to configure the like/unlike button (in the video below). 

New Discussion Board list has following cool features:
  1. Display Picture - Now users can see the person who has started the discussion and who is replying. 
  2. Rich text - Users can reply with rich text to highlight the important parts of the conversation in their comments. 
  3. Reply to Reply - Users can now reply to an existing reply just like the discussion topic. 
  4. Multimedia Reply - Users can attach picture, video or a simple link with in their reply to provide a reference etc. 
  5. Like a reply - Users can rate a post by liking it.
  6. Best Reply - A reply can be marked as Best reply in order to avoid other users to dig for an answer in the thread.
Following video shows how to configure the Discussion Board list for Facebook style Like Button on posts:


Tuesday, July 17, 2012

SharePoint 2013 is here

Yup...SharePoint 2013 Technical Preview has launched today. Woohoo.

Here is the documentation for SharePoint developers:
http://msdn.microsoft.com/en-us/library/jj162979(office.15).aspx



SharePoint 2010 - Join Two Lists (Child Parent Relation)

This article has also been published at NothingButSharePoint.

Description: This tutorial explains how to join two lists based on child parent relation without writing any code.

This post explains how to implement the child parent relationship between two lists/tables. Two lists will have one common field ID from Category list. Category.ID will act as primary key in Category list and will be used in Products list as a foreign key to match the items. Below diagram illustrate the relationship that has been implemented in the video.
Child Parent Relation



This technique can also be used in SharePoint 2007 via SharePoint Designer 2007 as explained in one of my previous posts. However the Data Source and Data View web part's menu options are little different.

Official SharePoint Documentation

I have recently contributed to the official SharePoint documentation for developement. Check it out here: https://docs.microsoft.com/en-us...