Delete SharePoint list items based on particular view using PowerShell

Delete SharePoint list items based on particular view using PowerShell
In this article you can able to see how to delete  SharePoint list items based on the particular view and also having another condition how have to delete items on every Monday, we created a couple of views what type of data have to delete based on item created date.
One view is used to delete SharePoint list items every day and another delete only on Monday.

Note:  by default list item limit is 30 items, we have to modify the view based on the requirement I change to 5000 so every day it will delete only 5000 items to delete.

add-pssnapin microsoft.sharepoint.powershell
$web = get-spweb -identity "http://dotnetsharepoint.com/sites/sharepoint/deleteitems"
$MainList = $web.lists["DeleteListItems"];
$today = (get-date).DayOfWeek
if($today -eq "Monday")
{
$view = $MainList.Views["DeleteMondaylistitems"];
}   
else
{
$view = $MainList.Views["DeleteEverydaylistitems"];
}
$items = $MainList.GetItems($view)
$totalcount = $items.Count
$j = 0;
for($i = $totalcount -1; $i -ge 0; $i--)
{
$deleteitem = $items[$i]
write-host $deleteitem.ID
$deleteitem.Delete()
}

How to add blank value to choice field in SharePoint

As per my requirement I want to show blank value in choice field, but SharePoint won’t take space as a valid option. So we can use ASCII code.
Method1: We can use Unicode character that does not print nothing. I tried with U+205F & it’s working as expected. To use this character please check the below steps.
1.    Navigate to Start -> run -> charmap
  

It will open Character Map Window.
Choose Font: Calibri, Drag down the cursor & select black check the code finally click copy the code

Paste the code in choice field and save.

Now check blank field. 

It’s working as expected.
Method 2: Use ASCII code 0129. It is empty character that SharePoint will accept as a valid option. It will appears empty on dropdown list. Hold down the ALT key and type the number 0129

Flow app in SharePoint Office 365

Flow:    

We can create automated workflows between your favorite apps and services to get notifications, synchronize files, collect data, and more. See how it works. Introducing multiple environments — distinct spaces to store and manage your organization's flows.
Navigate to Office 365.
Office 365 new app Flow -> Click on Flow App                                                                     
                                                                
 Here we can create Flow in two ways

Create from blank

  We can choose our own template to create  flow.


Crete from template
   We can choose from existing template to create flow

Now we are going to create flow using Create from blank -> Click on create from blank


 Search for triggers and select, here we are selecting "Blogger when Post is created".


Add  Blog Id & Post Status
Here I selected my blog & Post status is All. It will get data from under all section in blog.
-> Click on New Step






-> Click Add an Action



       Search for triggers and select, here we are selecting "SharePoint Create item"
Enter SharePoint Site url & select list where you want to store blog                   details                                                                                                                                                         

Select the title on Dynamic Content -> Click on Create flow      
                                                                                                                              
Now Flow created successfully.



Now create a article in Blog & Publish. Finally check the SharePoint list what we selected in flow, Item was created successfully.         

Hope it's help.

Cannot connect to the server at this time. Changes to your data cannot be saved



  I Export to Excel SharePoint custom list, when I am trying to open that excel sheet it’s showing the below error.


Error:


Resolution:

I added the SharePoint site URL in Compatibility view.

Navigate to IE settings -> click on compatibility view settings.

 


Add SharePoint site url and close the settings.


Now refresh the page and check. Hope it will help.

SharePoint Online Real Time Training Contact: JLAKSHMITULASI@GMAIL.COM

Get Random values from SharePoint list using PowerShell

In this article we are going to learn how to Get Random SharePoint items using PowerShell.
PowerShell is a Powerful scripting language, we can do our work/tasks easily, having so many built-in commands are available in PowerShell. In that we are using Get-Random command to get the random SharePoint list items.




add-pssnapin microsoft.sharepoint.powershell
$web = get-spweb -identity "http://dotnetsharepoint.com /sites/sharepoint/getrandom "
$Employeelist = $web.lists["Employee"];
$listitemsTotal = $Employeelist.Items.Count
$getvalues = $Employeelist.Items
if($listitemsTotal -gt 0)
{
$Random=Get-Random -Count $listitemsTotal -InputObject(1..$listitemsTotal)
}
for($j=0;$j -lt $listitemsTotal;$j++){
$RandomVal=$Random[$j]
$EmpNameName=$getvalues[$RandomVal]["EmployeeId"];
Write-host $RandomVal
write-host $EmpNameName

}

Hide “Edit Links” in quick launch SharePoint 2013

Here you can see how to hide “Edit links” in quick launch left navigation in SharePoint 2013.
This option is useful to drag and drop links in the quick launch, but how ever having access to create a new item they can able to see this option and can also modify these options , we are hiding the Edit Links to restrict all the users, using the CSS  as shown below.
Add the Content Editor or Script Editor in the home page or in any page that you want to hide the “Edit Links”

<style>
.ms-displayInlineBlock
{
display: none;
}
</style>


Move site collection from one content database to another content database

In this article we can able to see how to move site collection from one content database to another content database using PowerShell.
 Using Move-SPSite , this is used to move a site collection from one content database to another content database.
We have to execute the below command.

 Move-SPSite -Identity "http://dotnetsgharepoint.com/sites/movesitecollection"-DestinationDatabase "WSS_AnotherDBName"
-Identity is used to identify the site collection

Once Move-SPSite command executed, have to restart the IIS, run the iisreset command on all the servers in the farm to reflect changes in the IIS.

Create SharePoint sub site using Rest API

In this article you are able to see how to create sub site using Rest API.
We created a custom page and designed UI as per the below, Add this code in the script editor web part.
Create SharePoint Sub site using Client object model

<html>
<head>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js"></script>
<script type="text/javascript">
$(document).ready(function () {
               bindButtonClick(); 
 });
 function bindButtonClick() {  
            alert('startbtnclick');
            $("#register").on("click", function() {  
                var name = $("#txtSiteTitle").val();  
                var id = $("#txtSiteDescription").val();  
                var URL = $("#txtSiteURL").val();
                if (name == '' || id == '' || URL == '') {  
                    alert("Please fill all fields...!!!!!!");  
                } else {  
                    createSite();  
                }  
            });  
        } 
function createSite()
{
      var siteTitle = $("#txtSiteTitle").val();  
            var siteDesc = $("#txtSiteDescription").val();  
            var siteUrl =  $("#txtSiteURL").val();
  $.ajax({
   url: "https://dotnetsharepoint.com/Test/_api/web/webinfos/add",
   type: "POST",
   headers: {
    "accept": "application/json;odata=verbose",
    "content-type": "application/json;odata=verbose",
    "X-RequestDigest": $("#__REQUESTDIGEST").val()
   },
   data: JSON.stringify({
    'parameters': {
     '__metadata': {
      'type': 'SP.WebInfoCreationInformation'
     },
     'Url': siteUrl ,
     'Title': siteTitle ,
     'Description': siteDesc ,
     'Language': 1033,
     'WebTemplate': 'sts',
     'UseUniquePermissions': false
    }
   })           
  });
 }
</script>


</head>

<body>  
    <div class="container">  
        <div class="main">  
            <form class="form" method="post" action="#">  
                <h2>Create Client sub Site</h2>
                 <label>Client Site Name :</label> <input type="text" name="dname" id="txtSiteTitle"> 
                 <label>Client Site Description:</label> <input type="text" name="demail" id="txtSiteDescription"> 
                 <label>Client Site URL: </label> <input type="text" name="durl" id="txtSiteURL">
                 <input type="button" name="register" id="register" value="Submit"> </form>  
       </div>  
</body>
  
</html>




Create SharePoint Sub site using Client object model

In this article we can able to see how to create a sub site in SharePoint using Client object model.
Create a custom page and add the below code in the Script Editor Web part.


<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.12.3.js"></script>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js"></script>
 <script src="../_layouts/15/sp.runtime.js" type="text/javascript"> </script>
 <script type="text/javascript"> 
        $(function() { 
            bindButtonClick(); 
        }); 
        function bindButtonClick() { 
           $("#register").on("click", function() { 
                var name = $("#txtSiteTitle").val(); 
                var id = $("#txtSiteDescription").val(); 
                var URL = $("#txtSiteURL").val();
                if (name == '' || id == '' || URL == '') { 
                    alert("Please fill all fields...!!!!!!"); 
                } else { 
                    createSite(); 
                } 
            }); 
        } 

        function createSite() { 

            var siteTitle = $("#txtSiteTitle").val(); 
            var siteDesc = $("#txtSiteDescription").val(); 
            var siteUrl =  $("#txtSiteURL").val(); 
            var clientContext = new SP.ClientContext('https://rptj.sharepoint.com/Test/'); 
            var collWeb = clientContext.get_web().get_webs(); 
            var webCreationInfo = new SP.WebCreationInformation(); 
            webCreationInfo.set_title(siteTitle); 
            webCreationInfo.set_description(siteDesc); 
            webCreationInfo.set_language(1033); 
            webCreationInfo.set_url(siteUrl); 
           webCreationInfo.set_useSamePermissionsAsParentSite(true); 
            webCreationInfo.set_webTemplate('STS#0'); 
            var oNewWebsite = collWeb.add(webCreationInfo); 
            clientContext.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed)); 
        } 
        function onQuerySucceeded() { 
            alert('Site successfully Created!'); 
        } 
       function onQueryFailed(sender, args) { 
            alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); 
        } 
    </script> 
</head>



<body> 

    <div class="container"> 
        <div class="main"> 
            <form class="form" method="post" action="#"> 
                <h2>Create Client sub Site</h2> 
               <label>Client Site Name :</label> <input type="text" name="dname" id="txtSiteTitle">
                 <label>Client SIte Description:</label> <input type="text" name="demail" id="txtSiteDescription">
                 <label>Client SIte URL:</label> <input type="text" name="durl" id="txtSiteURL">
                 <input type="button" name="register" id="register" value="Submit"> </form> 
       </div> 
</body>
  </html>




Filtering & Sorting using SharePoint online List with Angular JS & Rest API

In this article we can learn how to do Filtering & Sorting in SharePoint List with Angular JS & Rest API
In a page added the script editor and place the below code.

<style>
        th {
            background-color: blue;
            color: white;
        }
    </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('InfoList')/items?$select=Title,Employee,Company",
            headers: { "Accept": "application/json;odata=verbose" }
        }).success(function (data, status, headers, config) {
            $scope.customers = data.d.results;
$scope.mySortFunction = function(customer) {//Sorting Iteam
                                    if(isNaN(customer[$scope.sortExpression]))
                                                return customer[$scope.sortExpression];
                                    return parseInt(customer[$scope.sortExpression]);
                        }
        }).error(function (data, status, headers, config) {

        });

    });

    </script>

    <h1> Filtering and sorting in SharePoint List using AngularJS-REST-API !!</h1>
    <br /><br />
    <div ng-app="SharePointAngApp" class="row">
        <div ng-controller="spCustomerController" class="span10">
            <div>
                Sort by:
                <select ng-model="sortExpression">
                    <option value="Title">Title</option>
                    <option value="Employee">Employee</option>
                    <option value="Company">Company</option>
                </select>
            </div>

            <br />
            Search By Any:
            <input type="text" ng-model="search.$" />
            <br />
            <br />
            <table class="table table-condensed table-hover">
                <tr>
                    <th>Title</th>
                    <th>Employee</th>
                    <th>Company</th>

                </tr>
                <tr ng-repeat="customer in customers  | orderBy:mySortFunction | filter:search">
                    <td>{{customer.Title}}</td>
                    <td>{{customer.Employee}}</td>
                    <td>{{customer.Company}}</td>
                </tr>
            </table>
        </div>
    </div>