Wednesday, 12 February 2014

Display/Get Data from SharePoint list using REST with JQuery (Ajax)

<html>
<head>

</head>

<body>
<script type="text/javascript">
    var json;
    var currentSiteUrl = $().SPServices.SPGetCurrentSite();
    var QuestionSet = new Array();
    var responseListName = "Quiz Responses";
    var accountName = $().SPServices.SPGetCurrentUser({
        async: true,
        fieldName: "Name",
        debug: true
    });

var questionUrl = currentSiteUrl + "/_vti_bin/listdata.svc/QuizQuestions?$filter=Active eq true&$orderby=DisplayOrder";
        $.ajax({
            url: questionUrl,
            type: 'GET',
            dataType: 'JSON',
            sortable: true,
            rownumbers: true,
            async: false,
            success: function (jsonData) {
                json = jsonData;
            },
            error: function () {
              alert("Error CallQuestion");
            }
    CallAnswer();
        });

function CallAnswer() {
        $(document).ready(function () {
            $("div#question").html("<span style='padding-top: 2px;'>" + json.d.Question + "</span></br><div style='border-bottom: solid #ddd 1px;padding-bottom:5px;'>");
            if (json.d.Answer1 != null) {
                $("div#answer").append("<span><input type='radio'  name='optionGroup' value='" + json.d.Answer1 + "' class='optionAnswer'>" + json.d.Answer1 + "</input></span></br>")
            }
            if (json.d.Answer2 != null) {
                $("div#answer").append("<span><input type='radio'  name='optionGroup' value='" + json.d.Answer2 + "' class='optionAnswer'>" + json.d.Answer2 + "</input></span></br>")
            }
            if (json.d.Answer3 != null) {
                $("div#answer").append("<span><input type='radio'  name='optionGroup' value='" + json.d.Answer3 + "' class='optionAnswer'>" + json.d.Answer3 + "</input></span></br>")
            }
            if (json.d.Answer4 != null) {
                $("div#answer").append("<span><input type='radio'  name='optionGroup' value='" + json.d.Answer4 + "' class='optionAnswer'>" + json.d.Answer4 + "</input></span></br>")
            }
            if (json.d.Answer5 != null) {
                $("div#answer").append("<span><input type='radio'  name='optionGroup' value='" + json.d.Answer5 + "' class='optionAnswer'>" + json.d.Answer5 + "</input></span></br>")
            }
            if (json.d.Answer6 != null) {
                $("div#answer").append("<span><input type='radio'  name='optionGroup' value='" + json.d.Answer6 + "' class='optionAnswer'>" + json.d.Answer6 + "</input></span></br>")
            }
        });
    }
</script>
<div>
    <div id="question">
    </div>
    <div id="answer">
    </div>
    <div id="comment">
    </div>
    <div id="anotherComment">
    </div>
    <div>
        <input type="button" name="btnSubmit" value="" id="btnSubmit" />&nbsp;
        <input type="button" name="btNext" id="btnNext" value="" />
    </div>
</div>
</body>
</html>

Table bind with DataTable using JQuery (JQuery.dataTables.css and JQuery.dataTables.js)

<html>
<head>
</head>
<body>
  <table id="example">
    <thead>
      <tr><th>Sites</th></tr>
    </thead>
    <tbody>
      <tr><td>SitePoint</td></tr>
      <tr><td>Learnable</td></tr>
      <tr><td>Flippa</td></tr>
    </tbody>
  </table>
  <script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script>
  <script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
  <script>
  $(function(){
    $("#example").dataTable();
  })
  </script>
</body>
</html>

Wednesday, 15 January 2014

Word wrapping SharePoint 2010 list column headers using CSS


 Add  a Content Editor Web Part (CEWP)

    1.Go to your list. Select Site Actions < Edit Page
    2.Click “Add a web part”
    3.Select Content editor webpart and click add new content.
    4.select html--< Edit Html source and add following css:

<style type="text/css"<
.ms-vh, .ms-vh2-nograd, .ms-vh2, .ms-vb
{
white-space: normal;
text-align:center;
vertical-align:text-bottom;
}
</style<

Tuesday, 14 January 2014

Dynamic Add Image inside Radio Buttons Using JQuery

<!DOCTYPE html<
<html<
<head<
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"<
</script<
<script<
$(document).ready(function(){


$("#button").click(function(){
var curAns="Radio 1";
var curVal=$('.optionAnswer:checked').val();

if(curAns == curVal)
{
$('.optionAnswer:checked').parent().append('<img width=25 height=25 src="" alt="correct"/<');
}
else
{
$('.optionAnswer:checked').parent().append('<img width=25 height=25 src="" alt="worng"/<');
$('.optionAnswer').each(function(index){
if($(this).val()== curAns)
$(this).parent().append('<img width=25 height=25 src="" alt="correct"/<');
});

}
});
});
</script<
</head<
<body<
  <div id="optionAns")<
   <span< <input type="radio" name="optionGroup" value="Radio 1" class="optionAnswer"<Radio 1</input<</span<</br<
   <span< <input type="radio" name="optionGroup" value="Radio 2" class="optionAnswer"<Radio 2</input<</span<</br<
   <span< <input type="radio" name="optionGroup" value="Radio 3" class="optionAnswer"<Radio 3</input<</span<</br<
</div<
<input type="button" id="button" name="button" value="submit" /<
 
</body<

</html<

Thursday, 9 January 2014

Get current user name detail in sharepoint 2010 with spservices

Field Name Field Internal Name WSS MOSS
Account Name
Name Title
Work e-mail EMail
About me Notes
Picture Picture
Department Department
Job Title JobTitle
SIP Address SipAddress
First name FirstName  
Last Name LastName  
Work phone WorkPhone  
Office Office  
User name UserName  
Web site WebSite  
Responsibilities SPResponsibility  

Wednesday, 1 January 2014

Below list shows ListTemplateId for all SharePoint list and libraries.

ListTemplateId
Description
100
Generic list
101
Document library
102
Survey
103
Links List
104
Announcement list
105
Contact List
106
Event List
107
Task List
108
Discussion Board
109
Picture Library
110
Data Source
111
Site Template Gallery
112
User Information List
113
Web Part Gallery
114
List Template Gallery
115
Xml Form Library
116
Master page Gallery
117
No-Code Workflows
118
Custom Workflow Process
119
Wiki Page Library
120
Custom Grid for list
130
Data Connection Library
140
Workflow History
150
Gantt Tasks list
200
Meeting Series list
201
Meeting Agenda list
202
Meeting Attendees list
204
Meeting Decisions list
207
Meeting Objectives list
210
Meeting text box
211
Meeting Things To Bring list
212
Meeting Workspace Pages list
300
Portal Sites list
301
Blog Posts list
302
Blog Comments list
303
Blog Categories list
1100
Issue tracking
1200
Administrator tasks list
2002
Personal document library
2003
Private document library

Thursday, 19 December 2013

Backup and Restore SharePoint 2010 Site Collection with PowerShell 

A PowerShell command prompt will appear and you need to format the following to fit the backup for your site.

Backup-SPSite -Identity SiteCollectionURLHere -Path BackupFilePathHere [-Force] [-NoSiteLock] [-UseSqlSnapshot] [-Verbose]
  • Force – Include this if you want to override a backup with the same name
  • NoSiteLock – Will prevent the site from going to Read Only mode while the backup is being taken.  A small warning, if someone changes content on the site while the backup is being created and according to Microsoft “might lead to possible data corruption”
  • UseSQLSnapshot – A database snapshot will be taken before the backup begins and the backup will be done off the snapshot. The advantage is that changes can be made to the site while the backup process is running without fear of corruption.  The snapshot will be deleted automatically when the backup is completed.  You don’t need to specify the -NoSiteLock parameter when using this method
For Example:
Backup-SPSite -Identity http://servername/sites/BISite -Path D:\SharePointBackups\BISite\07-13-2011.bak

Restore-SPSite -Identity SiteCollectionURLHere -Path BackupFilePathHere [-DatabaseServer DatabaseServerNameHere] [-DatabaseName ContentDatabaseNameHere] [-HostHeader HostHeaderHere] [-Force] [-GradualDelete] [-Verbose]

  • DatabaseServer – Specify the server for the content database
  • DatabaseName – Specify the name of the content database
  • HostHeader – URL of the Web application that will hold the host-named site collection
  • Force – Overwrite the site collection if it exists
  • GradualDelete – Recommended for site collections over 1 Gig in size, existing data is marked as deleted and gradually removed over time by a job rather than all at once to reduce the performance hit of deleting large amounts of data