Tuesday 22 December 2015

Delete data from large lists using powershell

Delete data from large lists using powershell

cls
$web = Get-Spweb "http://........:/";
$list =  $web.Lists["NintexWorkflowHistory"]
$query = New-Object Microsoft.SharePoint.SPQuery;
$query.ViewAttributes = "Scope='Recursive'";
$query.RowLimit = 2000;
$query.Query = '<Where><Lt><FieldRef Name="ID"/><Value Type="Counter">1000000</Value></Lt></Where>';
Write-Host $list.Title
$itemCount = 0;
$listId = $list.ID;
[System.Text.StringBuilder]$batchXml = New-Object "System.Text.StringBuilder";
$batchXml.Append("<?xml version=`"1.0`" encoding=`"UTF-8`"?><Batch>");
$command = [System.String]::Format( "<Method><SetList>{0}</SetList><SetVar Name=`"ID`">{1}</SetVar><SetVar Name=`"Cmd`">Delete</SetVar></Method>", $listId, "{0}" );

do
{
    $listItems = $list.GetItems($query)
    $query.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
    foreach ($item in $listItems)
    {
Write-Host $item.ID
        if($item -ne $null){$batchXml.Append([System.String]::Format($command, $item.ID.ToString())) | Out-Null;$itemCount++;}
    }
}
while($query.ListItemCollectionPosition -ne $null)

$batchXml.Append("</Batch>");
$itemCount;

$web.ProcessBatchData($batchXml.ToString()) | Out-Null;
#$web.RecycleBin.DeleteAll()
$web.Dispose()

Friday 20 November 2015

Sharepoint 2013 visual studio workflow is not updated on subsequesnt deployments

tasklist /FI "IMAGENAME eq vssphost5.exe" 2>NUL | find /I /N "vssphost5.exe">NUL
if "%ERRORLEVEL%"=="0" taskkill /f /im vssphost5.exe
exit 0


http://stackoverflow.com/questions/19286924/sharepoint-2013-visual-studio-workflow-not-updating

Friday 16 October 2015

SharePoint 2010 error while submitting nintex forms

An SPRequest object was not disposed before the end of this thread.  To avoid wasting system resources, dispose of this object or its parent (such as an SPSite or SPWeb) as soon as you are done using it.  This object will now be disposed.  Allocation Id: {}  To determine where this object was allocated, set Microsoft.SharePoint.Administration.SPWebService.ContentService.CollectSPRequestAllocationCallStacks = true.

System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x80131904
 at Microsoft.SharePoint.Library.SPRequestInternalClass.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bPreserveItemUIVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish, String bstrFileName, ISP2DSafeArrayWriter pListDataValidationCallback, ISP2DSafeArrayWriter pRestrictInsertCallback, ISP2DSafeArrayWriter pUniqueFieldCallback)  
 at Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bPreserveItemUIVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish, String bstrFileName, ISP2DSafeArrayWriter pListDataValidationCallback, ISP2DSafeArrayWriter pRestrictInsertCallback, ISP2DSafeArrayWriter pUniqueFieldCallback)







Not allowing to edit list items wicth the above exception.

Fix: Removed indexed column in the list. started working.

Tuesday 1 September 2015

 ##SharePoint Copy Users between Site Colletions to same Groups

$SourceUrl = "http://";
$DestinationUrl = "http://";
 ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  #
 ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  #
cls
if ((Get-PSSnapin -Name Microsft.SharePoint.PowerShell -ErrorAction SilentlyContinue)) {
    Add-PSSnapin Microsoft.SharePoint.Powershell
    Write-Host "Loaded Powershell" -ForegroundColor gray
}

function CopyUsersBetweenSiteColetions( $SourceUrl, $DestinationUrl){
$SourceWeb = Get-SPWeb $SourceUrl -ErrorAction SilentlyContinue
    $DestWeb = Get-SPWeb $DestinationUrl -ErrorAction SilentlyContinue
    if (!$SourceWeb) {
        Write-Host "Not able to get site with url : $SourceUrl" -ForegroundColor Red
        return
    }
    if (!$DestWeb) {
        Write-Host "Not able to get site with url : $DestinationUrl" -ForegroundColor Red
        return
    }


    if ($DestWeb) {
    $DestWeb.AllowUnsafeUpdates = $true
        Write-Host " Getting site groups from the Site : " $SourceWeb.Title -ForegroundColor Yellow
        foreach($SourceGrp in $SourceWeb.SiteGroups) {
            $desGrp = $DestWeb.SiteGroups[$SourceGrp.Name]
                if ($desGrp) {
                    Write-Host "Comparing Group Members of the Group:- " $desGrp.Name -ForegroundColor Cyan
                    foreach($SourceMembr in $SourceGrp.Users) {
                        $DesMember = $DestWeb.EnsureUser($SourceMembr)
                            if ($DesMember) {
                           $exist = $desGrp.Users | Where{ $_.LoginName -eq $DesMember.LoginName  }

                            if(!$exist)
                            {
                             Write-Host " Adding User" $DesMember.LoginName "to the destination web" -ForegroundColor Gray
                                $desGrp.AddUser($DesMember)                          
                                }
                             
                            } else {
                                Write-Host $SourceMembr.Email " User Not existing in destination web" -ForegroundColor Yellow
                            }
                    }
                } else {
                    Write-Host "Group not exists in Destination site : " $SourceGrp.Name -ForegroundColor Gray
                }
        }
        $DestWeb.AllowUnsafeUpdates = $false
        $SourceWeb.Dispose()
        $DestWeb.Dispose()
        Write-Host "Opeartion complted." -ForegroundColor DarkYellow
    }
 }
 CopyUsersBetweenSiteColetions $SourceUrl $DestinationUrl

Tuesday 25 August 2015

SharePoint 2013 sort Left navigation using jquery

var $eleContainer = $("tr td:last-child.ms-tv-item").closest('div');
var $aryTblChl = $eleContainer.children('table');
$aryTblChl.sort(function (a, b) {
    a = $(a).find("tr td:last-child.ms-tv-item").text();
    b = $(b).find("tr td:last-child.ms-tv-item").text();
    return (a == b) ? 0 : ((a > b) ? 1 : -1);
}); $aryTblChl.detach().appendTo($eleContainer);

Friday 17 July 2015

Error 545 Error occurred in deployment step 'Recycle IIS Application Pool': The local SharePoint server is not available. Check that the server is running and connected to the SharePoint farm.

while deploying sharepoint solution to the sharepoint environment.


Add user to the sqlserver admins group.
Limit the No of characters entry in textarea control.


function LimitTextAreaContent() {
    $(".clstxtSummary").keydown(function (event) {
        if ($(this).val().trim().length > 500) {
            $(this).val($(this).val().trim().substring(0, 500));
        }
    });
    $(".clstxtJustification").keydown(function (event) {
        if ($(this).val().trim().length > 1000) {
            $(this).val($(this).val().trim().substring(0, 1000));
        }
    });
    $(".clstxtSummary").keyup(function (event) {
        if ($(this).val().trim().length > 500) {
            $(this).val($(this).val().trim().substring(0, 500));
        }
    });
    $(".clstxtJustification").keyup(function (event) {
        if ($(this).val().trim().length > 1000) {
            $(this).val($(this).val().trim().substring(0, 1000));
        }
    });
    $(".clstxtSummary").on('paste', function (event) {
        setTimeout(function () {
            var text = event.currentTarget.value;
            if (event.currentTarget.value.length > 500) {
                event.currentTarget.value = text.substring(0, 500);
            }
        }, 0);
    });
    $(".clstxtJustification").on('paste', function (event) {
        setTimeout(function () {
            var text = event.currentTarget.value;
            if (event.currentTarget.value.length > 1000) {
                event.currentTarget.value = text.substring(0, 1000);
            }
        }, 0);
    });
    (function ($) {
        $("textarea[id$='txtDelegateComments'], textarea[id$='txtComments'] , textarea[id$='txtResubComments'], textarea[id$='txtDCCComments'] ").bind("change keyup input", function () {
            if ($(this).val().trim().length > 250) {
                $(this).val($(this).val().trim().substring(0, 250));
            }
        });

    })(jQuery);
}

$(document).ready(function () {
    LimitTextAreaContent();
});
sharepoint logout of page after every 20 mins using script

var idle = 0;
$(document).ready(function () {
    //Call timeOutCheck every 10 minutes.
    var idleInterval = setInterval(timeOutCheck, 600000); // 10 minute

    //set idlaTimer to true on mouse click/keypress/keydown
    $(this).mousedown(function (e) {
        idle = 1;
    });
    $(this).keypress(function (e) {
        idle = 1;
    });          
    $(this).keydown(function (e) {
        idle = 1;
    });
});

function timeOutCheck() {

   
    if (idle == 0) { // 20 minutes
        window.location.assign(_spPageContextInfo.webAbsoluteUrl+"/_layouts/15/signout.aspx")
        //alert("time out");
    }
    else
    {
        //reset the timer
        idle = 0;
    }
}


Monday 6 July 2015

calculated column functions
http://blogs.technet.com/b/collaboration/archive/2008/03/28/functions-for-use-in-a-moss-2007-column-today-me-other.aspx

Wednesday 22 April 2015

Run Javascript from code behid  C# code
 ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('This Document already exists!');", true);