Showing posts with label sharePoint 2010. Show all posts
Showing posts with label sharePoint 2010. Show all posts

Sunday, 1 March 2015

SharePoint Angular Js :- Get items from SharePoint List using Angular js Example

1.Create a Custom List Name as "Emp" and Create a below Column Name


2.Create one Content Editor WebPart and  paste the below code

<script type="text/javascript">
function altRows(id){
if(document.getElementsByTagName){  

var table = document.getElementById(id);  
var rows = table.getElementsByTagName("tr"); 
 
for(i = 0; i < rows.length; i++){          
if(i % 2 == 0){
rows[i].className = "evenrowcolor";
}else{
rows[i].className = "oddrowcolor";
}      
}
}
}
window.onload=function(){
altRows('alternatecolor');
}
</script>

<style type="text/css">
table.altrowstable {
font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 1px;
border-color: #a9c6c9;
border-collapse: collapse;
}
table.altrowstable th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #a9c6c9;
}
table.altrowstable td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #a9c6c9;
}
.oddrowcolor{
background-color:#d4e3e5;
}
.evenrowcolor{
background-color:#c3dde0;
}
</style>  
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>   
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>   
   
<script>   
       
   
    var myAngApp = angular.module('SharePointAngApp', []);   
    myAngApp.controller('spCustomerController', function ($scope, $http) {   
        $http({   
            method: 'GET',   
            url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Emp')/items?$select=FirstName,LastName,Location",   
            headers: { "Accept": "application/json;odata=verbose" }   
        }).success(function (data, status, headers, config) {   
            $scope.customers = data.d.results;   
        }).error(function (data, status, headers, config) {   
          
        });   
    });   
       
   
</script>   

<h1>SharePoint with Angular js Example </h1>   
   
<div ng-app="SharePointAngApp" class="row">   
    <div ng-controller="spCustomerController" class="span10">   
       
         <table class="altrowstable" id="alternatecolor">
            <tr>   
                <th>FirstName</th>   
                <th>LastName</th>   
                <th>Location</th>   
                  
           </tr>   
            <tr ng-repeat="customer in customers">   
               <td>{{customer.FirstName}}</td>   
                <td>{{customer.LastName}}</td>   
               <td>{{customer.Location}}</td>   
               </tr>   
        </table>   
    </div>   
</div>  

output:-
          
          

           





Continue Reading...

SharePoint Knockout js :- Get items from SharePoint List using Knockout js

1.Create a Custom List Name as "Emp" and Create a below Column Name


2.Create one Content Editor WebPart and  paste the below code

<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>   
<script src="https://SiteCollectionUrl/sites/DevSite/Style%20Library/knockout-3.3.0.js"></script>   
<script src="https://SiteCollectionUrl/sites/DevSite/Style%20Library/ko.sp-1.0.min.js"></script>   

<script type="text/javascript"> 
function altRows(id){
if(document.getElementsByTagName){  

var table = document.getElementById(id);  
var rows = table.getElementsByTagName("tr"); 
 
for(i = 0; i < rows.length; i++){          
if(i % 2 == 0){
rows[i].className = "evenrowcolor";
}else{
rows[i].className = "oddrowcolor";
}      
}
}
}
window.onload=function(){
altRows('alternatecolor');
}
</script>

<style type="text/css">
table.altrowstable {
font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 1px;
border-color: #a9c6c9;
border-collapse: collapse;
}
table.altrowstable th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #a9c6c9;
}
table.altrowstable td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #a9c6c9;
}
.oddrowcolor{
background-color:#d4e3e5;
}
.evenrowcolor{
background-color:#c3dde0;
}
</style>  

<script>   
   
    ExecuteOrDelayUntilScriptLoaded(MainFunction, "sp.js");   
    var completeEmployeeList = null;   
   
     
    function EmployeeList(title, firstname, lastname, location) {   
        var self = this;   
        self.Title = title;   
        self.FirstName = firstname;   
        self.LastName = lastname; 
        self.Location = location;   
    }   
       
    
    function EmployeeListViewModel() {   
        var self = this;   
       
        self.Employees = ko.observableArray([]);   
        self.AddEmployees = function (title, firstname, lastname, location) {   
            self.Employees.push(new EmployeeList(title, firstname, lastname, location));   
        }   
    }   
   
    function MainFunction() {   
        completeEmployeeList = new EmployeeListViewModel();             
        retrieveListItems();               
        ko.applyBindings(completeEmployeeList);   
    }   
   
    function retrieveListItems() {   
        var clientContext = new SP.ClientContext.get_current();   
        var oList = clientContext.get_web().get_lists().getByTitle('Emp');   
        var camlQuery = new SP.CamlQuery();   
        camlQuery.set_viewXml("<View><RowLimit>10</RowLimit></View>");   
        this.collListItem = oList.getItems(camlQuery);   
        clientContext.load(collListItem);   
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));   
    }   
   
    function onQuerySucceeded(sender, args) {   
        var listItemInfo = '';   
        var listItemEnumerator = collListItem.getEnumerator();   
        while (listItemEnumerator.moveNext()) {   
            var currentItem = listItemEnumerator.get_current();   
            completeEmployeeList.AddEmployees(currentItem.get_item("Title"), currentItem.get_item("FirstName"), currentItem.get_item("LastName"), currentItem.get_item("Location"));   
        }   
    }   
   
    function onQueryFailed(sender, args) {   
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());   
    }   
</script>   
   

<div id="divEmployeeList">   
   
    <h2>SharePoint with Knockout js Example</h2>   
    <br />   
   
  <table class="altrowstable" id="alternatecolor">
        <thead>   
            <tr>   
                <th>Title</th>   
                <th>FirstName</th>    
                <th>LastName</th>    
                <th>Location</th>   
            </tr>   
        </thead>   
        
        <tbody data-bind="foreach: Employees">   
            <tr>   
                <td data-bind="text: Title"></td>   
                <td data-bind="text: FirstName"></td> 
                <td data-bind="text: LastName"></td>    
                <td data-bind="text: Location"></td>   
            </tr>   
        </tbody>   
    </table>   

</div>  

output:- 
    



Continue Reading...

Monday, 2 February 2015

Get current logged user details in SharePoint using spservices

 1.Create one Content Editor WebPart and  paste the below code

<script type="text/javascript" src="https://Site Collection Url/sites/TestSite/Style Library/Samples/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="https://Site Collection Url/sites/TestSite/Style Library/Samples/jquery.SPServices-2014.02.min.js"></script>

<script type="text/javascript">

$(document).ready(function() { 

 GetLoggeduserInfo();
   
});

function GetLoggeduserInfo()
{

$().SPServices({
    operation: "GetUserInfo",
    async: false,
    userLoginName: $().SPServices.SPGetCurrentUser(),
    completefunc: function (xData, Status) {
        $(xData.responseXML).find("User").each(function() {
            curUserId = $(this).attr("ID");
            curUserName = $(this).attr("Name");
            curFullUserName = $(this).attr("ID")+";#"+$(this).attr("Name");
            alert(curFullUserName);
        });
    }
});
}

</script>
Continue Reading...

Wednesday, 30 July 2014

Programmatically Delete all Item in SharePoint List using c#

       
        public static void DeleteAllItems(string list)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (SPSite spSite = new SPSite(SPContext.Current.Site.ID))
                {
                    using (SPWeb spWeb = spSite.OpenWeb())
                    {
                        spWeb.AllowUnsafeUpdates = true;
                        StringBuilder deletebuilder = BatchCommand(spWeb.Lists[list]);
                        spSite.RootWeb.ProcessBatchData(deletebuilder.ToString());
                        spWeb.AllowUnsafeUpdates = false;
                    }
                }
            });

        }
        private static StringBuilder BatchCommand(SPList spList)
        {
            StringBuilder deletebuilder = new StringBuilder();
            deletebuilder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");
            string command = "<Method><SetList Scope=\"Request\">" + spList.ID +
                "</SetList><SetVar Name=\"ID\">{0}</SetVar><SetVar Name=\"Cmd\">Delete</SetVar></Method>";

            foreach (SPListItem item in spList.Items)
            {
                deletebuilder.Append(string.Format(command, item.ID.ToString()));
            }
            deletebuilder.Append("</Batch>");
            return deletebuilder;
        }
   DeleteAllItems("Employee");
Continue Reading...

Wednesday, 4 December 2013

Delete all SharePoint List Item using Powershell in SharePoint

Sytax:-

$SITEURL = "http://serverurl"

$site = new-object Microsoft.SharePoint.SPSite ( $SITEURL )
$web = $site.OpenWeb()
"Web is : " + $web.Title

$oList = $web.Lists["LIST NAME"];

"List is :" + $oList.Title + " with item count " + $oList.ItemCount

$collListItems = $oList.Items;
$count = $collListItems.Count - 1

for($intIndex = $count; $intIndex -gt -1; $intIndex--)
{
        "Deleting record: " + $intIndex
        $collListItems.Delete($intIndex);
}

Continue Reading...

Tuesday, 3 December 2013

join two sharepoint list using c#


1.Create a custom list name as "List1" with below column

2.Create a custom list name as "List2" with below column

3.paste the below code inside the webpart

public void GetEmployee()
        {
            SPWeb objweb = SPContext.Current.Web;
            SPList olist1 = objweb.Lists["list1"];
            SPListItemCollection collListItems = olist1.Items;
            SPQuery oQuery1 = new SPQuery();
            DataTable table1 = collListItems.GetDataTable();
            SPList olist2 = objweb.Lists["list2"];
            SPListItemCollection collListItems2 = olist2.Items;
            DataTable table2 = collListItems2.GetDataTable();
            DataTable dt = new DataTable();
            dt.Columns.Add("Name", typeof(string));
            dt.Columns.Add("Age", typeof(string));
            dt.Columns.Add("Salary", typeof(string));
            dt.Columns.Add("Sex", typeof(string));
            dt.Columns.Add("Address", typeof(string));
            var Vout = from tbl1 in table1.AsEnumerable()
                       join tbl2 in table2.AsEnumerable() on tbl1["Name"] equals tbl2["Name"]
                       select new
                       {
                           Sex = tbl2["Sex"],
                           Address = tbl2["Address"],
                           Name = tbl1["Name"],
                           Age = tbl1["Age"],
                           Salary = tbl1["Salary"]
                       };
            foreach (var item in Vout)
            {
                DataRow dr = dt.NewRow();
                dr["Name"] = item.Name;
                dr["Age"] = item.Age;
                dr["Salary"] = item.Salary;
                dr["Sex"] = item.Sex;
                dr["Address"] = item.Address;
                dt.Rows.Add(dr);
            }
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
4.output



Continue Reading...

Timer Job Example in SharePoint 2013


1.open visual studio 2012
2.Add SharePoint2013-Empty Project named it "TimerJobExample"
3.Enter your site collection and choose Deploy as a Farm solution
4.Add class file in your solution named it "Employee"
5.paste the below code inside the Employee class

 public class Employee : SPJobDefinition
    {
        public Employee()
            : base()
        {
            Title = "Sithik Job";

        }

        public const string JobName = "Sithik Job";
        public Employee(SPWebApplication webApp) :
            base(JobName, webApp, null, SPJobLockType.Job) { }
        public override void Execute(Guid targetInstanceId)
        {
            AddNewItem();

        }
  public void AddNewItem()
        {
            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList listEmpInsert = web.Lists["Employee"];
                        web.AllowUnsafeUpdates = true;
                        SPListItem EmpInsert = listEmpInsert.Items.Add();
                        EmpInsert["EmpName"] = "Mohamed";
                        EmpInsert["Age"] = "28";
                        EmpInsert["Address"] = "Chennnai";
                        EmpInsert.Update();
                        web.AllowUnsafeUpdates = false;
                    }
                }
            });
        }  

    }
6.Go to Features right click add one new features and rename it "Employee"
7.Right click the Employee Features  add one "Event receiver" paste the below code inside the receiver

 private void DeleteJob(Microsoft.SharePoint.Administration.SPJobDefinitionCollection jobs)
        {
            foreach (SPJobDefinition job in jobs)
            {
                if (job.Name.Equals(TimerJobExample.Employee.JobName,
                StringComparison.OrdinalIgnoreCase))
                {
                    job.Delete();
                }
            }
        }

   public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
            DeleteJob(webApp.JobDefinitions);


            TimerJobExample.Employee simpleJob = new TimerJobExample.Employee(webApp);

            SPMinuteSchedule schedule = new SPMinuteSchedule();
            schedule.BeginSecond = 0;
            schedule.EndSecond = 59;
            schedule.Interval = 1;

            simpleJob.Schedule = schedule;
            simpleJob.Update();
        }

      public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
            DeleteJob(webApp.JobDefinitions);
        }

8.click the "Employee Features" Change the scope to "WebApplication"
9.click the "properties windows" "Always Force to Install" to "True"
10.Deploy the project
11.Go "central administration" click "Monitoring"
12.under "Timer Jobs" click "Review Job definitions"
13.you will see your Timer job named "Sithik Job"



Continue Reading...

Followers

Follow The Author