Tuesday, 4 December 2018

Encode - decode base64



https://scotch.io/tutorials/how-to-encode-and-decode-strings-with-base64-in-javascript

Thursday, 1 November 2018

Remove Duplicate Values in SharePoint List

<!--Copy all source code, paste it inside Content Editor /  Script Editor-->

<div><h1>Remove Duplicate Values</h1></div>
<div>Enter Your List Name : <input type='text' id='txtList' /></div>
<div>Enter Your Unique Column : <input type='text' id='txtUniColumn' /><input type='button' value='Remove Duplicate Value' onclick='getListItems()'/></div>

<div id='divDel'>Deleted Items
<div id='divDelItems'></div>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type='text/javascript'>

$(document).ready(function(){
debugger;
$('#divDelItems').html('');
$('#divDel').hide();
});

function RemoveDuplicateItems(items, propertyName) {
    var result = [];
     var ExistingItem = [];
    if (items.length > 0) {
        $.each(items, function (index, item) {
            if ($.inArray(item[propertyName], result ) == -1) {
                    if(!IsNullOrUndefined(item[propertyName])){
                             result.push(item[propertyName]);
                    }
            }
            else{
                   if(!IsNullOrUndefined(item[propertyName])){
                            ExistingItem.push(item['Id']+ ' : ' + item[$('#txtUniColumn').val()] );
                   }
           }
        });
    }
    return ExistingItem;
}



function getListItems() {
    $.ajax({
        url:  _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('"+$('#txtList').val()+"')/items?$select="+$('#txtUniColumn').val()+",Id&$top=5000&$orderby= Modified desc" ,
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function(data) {

            var items = data.d.results;
             items = RemoveDuplicateItems(items, $('#txtUniColumn').val());
             $('#divDel').show();
             if(items!=undefined && items.length>0){
             for(var i=0; i<items.length; i++){
                   deleteItems(items[i]);
            }}
        },
        error: function(data) {
            alert(data.responseText);
        }
    });
}
var count = 0;
function deleteItems(Id){
  $.ajax({ 
            url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('"+$('#txtList').val()+"')/items(" + Id.split(':')[0] + ")", 
            type: "POST", 
            contentType: "application/json;odata=verbose", 
            headers: { 
                "Accept": "application/json;odata=verbose", 
                "X-RequestDigest": $("#__REQUESTDIGEST").val(), 
                "IF-MATCH": "*", 
                "X-HTTP-Method": "DELETE", 
            }, 
            success: function(data) { 
                   var cnt = count++;
                  console.log(Id + ' Count - ' );
                  $('#divDelItems').append('<div>' + Id + ' Count - ' + cnt  + '</div>');
            }, 
            error: function(data) { 
                 
            } 
        });
}

</script>



Monday, 15 October 2018

Sharepoint WSP Solution BackUp and Deployment



//For WSP Backup
$farm = Get-SpFarm 
$file = $farm.Solutions.Item("WSP_Solution.wsp").SolutionFile 
$file.SaveAs("E:\FolderName\WSP_Solution.wsp")


//Before add WSP solution, Retract solution from central admin Farm solution and remove Solution from there.
Add-SPSolution "E:\FolderName\WSP_Solution.wsp"
Install-SPSolution –Identity WSP_Solution.wsp –WebApplication "Web App url" –GACDeployment

Sunday, 7 October 2018

Disable Future Dates of Calendar from SharePoint Default Forms

//Add this script inside forms or page's script editor

<script src="//code.jquery.com/jquery-3.2.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
var getSPDayDiff = function(date) {
return Math.round(Math.abs(( new Date(1601,0,1).getTime() - date.getTime())/( 24*60*60*1000 ) ) );
}
$(function () {
debugger;
var currentDate = new Date();
//currentDate.setMonth(currentDate.getMonth() + 1);
var minDay = getSPDayDiff(new Date());
var maxDay = getSPDayDiff(currentDate);

var datePicker=$("img[alt='Select a date from the calendar.']").parent();
var onclickStr=datePicker.attr("onclick");
//onclickStr=onclickStr.replace("minjday=109207", "minjday="+minDay);

        onclickStr=onclickStr.replace("minjday=109207", "minjday=109207");

onclickStr=onclickStr.replace("maxjday=2666269", "maxjday="+maxDay);
datePicker.attr("onclick",onclickStr);
});
</script>

Wednesday, 26 September 2018

Spfx Angular 2

https://www.fmtconsultants.com/sharepoint-framework-spfx-angular2/

https://www.barbarianmeetscoding.com/blog/2016/03/25/getting-started-with-angular-2-step-by-step-1-your-first-component/

https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/get-started/build-a-hello-world-web-part

rest Batch Operations

Thursday, 10 May 2018

Create Host Name Site Collection Using Powershell Script



[string] $ContentDB =  $(Read-Host -prompt "Content Database Name")
[string] $DatabaseServer =  $(Read-Host -prompt "Database Server Name")
[string] $WebApplication =  $(Read-Host -prompt "Web Application Name")
[string] $siteUrl = $(Read-Host -prompt "Site Url")
[string] $SiteName = $(Read-Host -prompt "Site Name")
[string] $SiteOwnerID = $(Read-Host -prompt "Site Owner ID")


New-SPContentDatabase $ContentDB -DatabaseServer $DatabaseServer -WebApplication $WebApplication
New-SPSite $siteUrl -HostHeaderWebApplication $WebApplication -Name $SiteName -OwnerAlias $SiteOwnerID -language 1033 -Template 'STS#0' -ContentDatabase $ContentDB

Wednesday, 9 May 2018

Deploy wsp 2010



//To Get Backup of wsp
$file - $farm.Solutions.Item("filename.wsp").SolutionFile
$file.SaveAs("D:\filename.wsp")



//To Add wsp sol on farm
Add-SPSolution -LiteralPath "D:\filename.wsp"


//to install wsp
Install-SPSolution -Identity filename.wsp -WebApplication "http://site:port/"

Time Conversion from UTC to IST


Put:
private static TimeZoneInfo INDIAN_ZONE = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
as a field.
Then, use:
DateTime indianTime =  TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, INDIAN_ZONE);
to get the time as needed.




public DataTable ChangeCreatedTime(ClientContext context, DataTable dt)
        {
            try
            {
                foreach (DataRow dr in dt.Rows)
                {
                    DateTime indianTime = TimeZoneInfo.ConvertTimeFromUtc(Convert.ToDateTime(dr["Created"].ToString()), INDIAN_ZONE);
                    dr["Created"] = indianTime.ToString();
                }
                dt.AcceptChanges();
            }
            catch (Exception ex)
            {
                WriteException(context, string.Empty, "Class File", "ChangeCreatedTime(ClientContext context, DataTable dt)", ex.Message);
            }
            return dt;
        }

Backup, Restore and Enable Dev Site Feature of Site Collection Using Powershell Script



Backup SIteCollection
 Backup-SPSite http://sitename.com/ -Path D:\backupfilename.bak –UseSqlSnapshot

Create New SiteCollection
Get-SPWebTemplate
$template = Get-SPWebTemplate "DEV#0"
New-SPSite -Url "http://domain:port/sites/sitename" -OwnerAlias "domain\username" -Template

Restore SiteCollection Backup
Restore-SPSite -Identity http://domain:port/sites/sitename  -Path "D:\backupfilename.bak" -Verbose -


Enable Developer Site Feature
Enable-SPFeature e374875e-06b6-11e0-b0fa-57f5dfd72085 -url http://domain:port/sites/sitename

Search & Restore Recycle Bin Item using Powershell

Step1. Run the below script to find out about the file in site collection recycle bin.

(Get-SPSite "http://SERVERNAME:PORT/").RecycleBin | ?{$_.Title -match "DeletedFile"}

If a matching file is found, Powershell will display information about the file. You will also be able to find who deleted it.


Step 2. Now take the ID of the item and restore back to the original location.

(Get-SPSite "http://SERVERNAME:PORT").RecycleBin.Restore("e7652991-b3b7-4df2-a3c8-39b76a8e98d3")

Dont forget to run PowerShell as administrator.

Wednesday, 28 March 2018

Using Rest Api get group members in Microsoft flow

http://www.sharepointpals.com/post/Step-by-Step-Procedure-to-Call-SharePoint-Office-365-REST-API-from-Microsoft-Flow