Saturday 28 October 2017

Restore Deleted SiteCollection PowerShell

PowerShell Script to Restore Deleted SiteCollection from a Webapplication 



Get the Specific Webapplication ID  and use GetDeltedSites() method to to find out ID your deleted sitecollection and use Restore-SPDeletedSite command let to restore the sitecollection


cls


Add-PSSnapin "Microsoft.SharePoint.PowerShell"

$WebApplication = Get-SPWebApplication -Identity http://spdev2016:2626/

$restore = $WebApplication.GetDeletedSites()


Restore-SPDeletedSite  -Identity 1b0af67e-2f0d-413c-b8b7-9dec119dbc8c -WebApplication 7f1ac80d-d8fb-4a0a-9715-3865a4d139c5 -Confirm:$false 

Thursday 5 October 2017

Remove Mantainance Mode of SharePoint Site

PowerShell Script to remove Maintenance of a site


cls

asnp "*sh*"

$Admin = new-object Microsoft.SharePoint.Administration.SPSiteAdministration('http://siteurl/’)

$Admin.ClearMaintenanceMode() 

Wednesday 30 August 2017

SharePoint FrameWork Development EnvironmentSetup Set by Step

Follow the below steps to your SharePoint Framework Dev setup

1. Install Node.js first (node.js)

https://nodejs.org/en/ 

Open Powershell command window  check for installation and its version status of Node.js

npm -v









2. Install visual studio code

https://code.visualstudio.com/download 


3. Open Powershell command window and then install yeoman and gulp with below command

 npm install -g yo gulp















4. npm install @microsoft/generator-sharepoint -g







































yoman is going to install all project scafoldings(creating project structure solution will be generated

gulp trust-dev-cert to install 

gulp serve 

Monday 13 March 2017

CSOM TermStore GetTerms

CSOM Get Groups in TermStore/CSOM Get Termsets in TermStore/ CSOM Get Terms in TermSets
















OutPut :






















using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Taxonomy;

namespace TermstoreCSOM
{
    class Program
    {
        static void Main(string[] args)
        {
            ClientContext ctx = new ClientContext("http://SPDev2013:3636/");
            ctx.Credentials = new System.Net.NetworkCredential("username", "pwd","domain");

            //Get the Taxanomy Session

            TaxonomySession tx = TaxonomySession.GetTaxonomySession(ctx);
            ctx.Load(tx, t => t.TermStores);
            ctx.ExecuteQuery();
           
            //Get the defualt TermStore from Taxonamy Session

            var ts = tx.TermStores[0];
            ctx.Load(ts);
            ctx.ExecuteQuery();
            Console.ForegroundColor = ConsoleColor.White;
           
            //Print the TermStore Name

            Console.WriteLine(ts.Name);

           //Get the Groups inside the Termstore

            TermGroupCollection groups = ts.Groups;
            ctx.Load(groups);
            ctx.ExecuteQuery();
            foreach( TermGroup group in groups)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
               
                //Print Each Group inside the TermStore

                Console.WriteLine("TermGroup is :" +group.Name);
               
                //Ge the Termsets inside the Each Group

                TermSetCollection termsetcollections = group.TermSets;
                ctx.Load(termsetcollections);
                ctx.ExecuteQuery();

                foreach (TermSet t in termsetcollections)
                {
                    Console.ForegroundColor = ConsoleColor.Green;

                    //Print Each Termset

                    Console.WriteLine("TermsetName is :" + t.Name);
                    ctx.Load(t);
                    ctx.Load(t.GetAllTerms());
                    ctx.ExecuteQuery();
                   
                    //Get All the Terms inside the TermSet

                    TermCollection terms = t.GetAllTerms();
                    ctx.Load(terms);
                    ctx.ExecuteQuery();
                    foreach (Term term in terms)
                    {
                       
                      Console.ForegroundColor = ConsoleColor.DarkCyan;
                          
                        //Print Each Term inside TermSet
                         
                        Console.WriteLine("Terms is :" + term.Name);

                    }

                }

            }
            Console.ReadKey();

           

        }
    }
}


Saturday 4 March 2017

Rest API SharePoint 2013

Basic ODATA Queries on SharePoint 2013 List


OutPut :





    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js" type="text/javascript"></script>
    <script src="/_layouts/15/sp.runtime.js" type="text/javascript"></script>
    <script src="/_layouts/15/sp.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function(){
            jQuery("#webtitleid").click(GetWebTitle);
            jQuery("#CurrentUser").click(GetCurrentUser);
            jQuery("#createList").click(CreateList);
            jQuery("#listitems").click(GetListItems);
            jQuery("#addlistitem").click(AddListItem);
      
        });

        function AddListItem() {

            var call = jQuery.ajax({
                url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/getByTitle('Products')/Items",
                type: "POST",
                datatype: "json",
                headers:
                    {
                        Accept: "application/json;odata=verbose",
                        "Content-Type": "application/json;odata=verbose",
                        "X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
                    },
                data:
                    JSON.stringify({
                        "__metadata": { type: "SP.Data.ProductsListItem" },                  
                         Title: "ItemAddedthroughMyRest"
                    })

            });
            call.done(function (data, textstatus, jqXHR) {
                var msg = jQuery("#additem");
                msg.text("ListItem Added Successfully");
            });

            call.fail(function (data, textstatus, jqXHR) {
                alert('failed to Add ListItem');

            });
        }

        function GetListItems()
        {
            var call = jQuery.ajax({
                url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/getByTitle('Products')/Items?$select=Title",
                type: "GET",
                datatype: "json",
                headers:
                    {
                        Accept: "application/json;odata=verbose"

                    }
            });
            call.done(function (data, textstatus, jqXHR) {
                var msg = jQuery("#litems");

                jQuery.each(data.d.results, function (index, value) {
                    msg.append("<li>" +value.Title +"</li>");
                });
            });

            call.fail(function (data, textstatus, jqXHR) {
                alert("failed to get list items");
            });
        }
        function CreateList()
        {
            var call = jQuery.ajax({
                url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists",
                type: "POST",
                datatype: "json",
                headers:
                    {
                        Accept: "application/json;odata=verbose",
                        "Content-Type": "application/json;odata=verbose",
                        "X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
                    },
                data:
                    JSON.stringify({
                            "__metadata": { type: "SP.List" },
                            BaseTemplate: SP.ListTemplateType.genericList,
                             Title: "MyRestAPICustomList"
                                 })

            });
            call.done(function (data, textstatus, jqXHR) {
                var msg = jQuery("#list");
                msg.text("List Created Successfully");
            });

            call.fail(function (data, textstatus, jqXHR) {
                alert('failed to Create List');

            });
        }

        function GetWebTitle()
        {
            var call = jQuery.ajax({
                url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/",
                type: "GET",
                datatype:"json",
                headers:
                {
                    Accept: "application/json;odata=verbose"
                }
            });

            call.done(function (data, textstatus, jqXHR) {
                var msg = jQuery("#webtitle");
                  msg.text("Web Title is :").append(data.d.Title);
            });
            call.fail(function (data, textstatus, jqXHR) {
                alert('failed to get the result');
            });

        }
            function GetCurrentUser()
        {
            var call = jQuery.ajax({
                url:_spPageContextInfo.webAbsoluteUrl + "/_api/Web/?$select=CurrentUser&$expand=CurrentUser",
                type:"GET",
                datatype: "json",
                headers:
                {
                    Accept : "application/json;odata=verbose"

                }
            });
            call.done(function (data, textstatus, jqXHR) {
                var msg = jQuery("#User");
                     msg.text("User Title is :").append(data.d.CurrentUser.Title);

            });
            call.fail(function (data, textstatus, jqXHR) {
                alert('failed to get the result');

            });

        }
    </script>

    <div>
        <p id="webtitle"></p>
        <p id="User"> </p>
        <p id="list"> </p>
        <ul id="litems"></ul>
        <p id="additem"></p>
        <input id="webtitleid" type="button" value="GetWebTitle" />
        <input id="CurrentUser" type="button" value="GEtCurrentUser" style="margin: 10px;" />
        <input id="createList" type="button" value="CreateList" style="margin: 10px;" />
        <input id="listitems" type="button" value="GetProductsListItems" style="margin: 10px;" />
        <input id="addlistitem" type="button" value="AddProductsListitem" style="margin: 10px;" />

        <br />

    </div>