Search This Blog

Tuesday, February 24, 2015

get current logged user name & its ID in sharepoint 2010 using jquery

$().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(curUserId);



var context = null;  
var web = null;  
var currentUser = null;  
function getWebUserData() {
    context = new SP.ClientContext.get_current();
    web = context.get_web();
    currentUser = web.get_currentUser();
    currentUser.retrieve();
    context.load(web);
    context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));
}

function onSuccessMethod(sender, args) {
    var userObject = web.get_currentUser();
    alert('User name:' + userObject.get_title() + '\n Login Name:' + userObject.get_loginName());
}
function onFailureMethod(sender, args) {
    alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}

SharePoint jQuery Cascading Dropdown utility (working on webparts and pages)

   

Monday, August 18, 2014

Bulk Deletion of Items from sharepoint list programmatically

static StringBuilder BuildBatchDeleteCommand(SPList spList) { StringBuilder sbDelete = new StringBuilder(); sbDelete.Append(""); string command = "" + spList.ID + "{0}Delete"; foreach (SPListItem item in spList.Items) { sbDelete.Append(string.Format(command, item.ID.ToString())); } sbDelete.Append(""); return sbDelete; } static void DeleteItems() { using (SPSite oSite = new SPSite("http://yh1002545lt")) { using (SPWeb oWeb = oSite.OpenWeb()) { SPListItemCollection spTktList = oWeb.Lists.TryGetList("ThreshHold").Items; SPListItem item = null; try { StringBuilder sb= BuildBatchDeleteCommand(oWeb.Lists.TryGetList("ThreshHold")); oWeb.ProcessBatchData(sb.ToString()); } catch (Exception ex) { } } } }

Wednesday, July 9, 2014

Powershell scripts to delete sharepoint List Items

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) { Add-PSSnapin "Microsoft.SharePoint.PowerShell" } # "Enter the site URL instead http://serverurl" $SITEURL = "http://arwqa.grouphc.net/" $site = new-object Microsoft.SharePoint.SPSite ( $SITEURL ) $web = $site.OpenWeb() "Web is : " + $web.Title # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWAdjInvoice"]; $query=new-object Microsoft.SharePoint.SPQuery $query.ViewAttributes = "Scope='Recursive'" $items=$oList.GetItems($query) "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); } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWAdjProductCode"]; "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); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWCreditDebitOrder"]; "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); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWDisputeInvoice"]; "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); } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWDrafts"]; "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); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWErrorReason"]; "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); } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWInvoiceNewCustomer"]; "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); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWInvoiceNewCustomerProductCode"]; "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); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWJDEFailureTickets"]; "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); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWK2Rules"]; "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); } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWNote"]; "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); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWReasonCode"]; "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); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWRecordCorrections"]; "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); } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWReinvoiceProductCode"]; "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); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWReinvoiceSameCustomer"]; "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); } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWSalesinformation"]; "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); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWStatusCode"]; "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); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) } # Enter name of the List below insted of LIST NAME $oList = $web.Lists["ARWTicketHistory"]; "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); } #DEleting folders $query = New-Object Microsoft.SharePoint.SPQuery $camlQuery = 'Folder' $query.Query = $camlQuery $items = $oList.GetItems($query) Write-Host("DELETED FILE: " + $count) for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--) { $items.Delete($intIndex); Write-Host("DELETED Folder: " + $intIndex) }

Powershell script to delete Sharepoint List Items with Folder

[System.reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

$site = Get-SPSite "http://arwqa.grouphc.net/"
$web = $site.rootweb
$list = $web.Lists["ARWTicket"]
$caml=""
#optional filter
#<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">Form</Value></Eq></Where>"

$query=new-object Microsoft.SharePoint.SPQuery
$query.ViewAttributes = "Scope='Recursive'"
$query.Query=$caml

$items=$list.GetItems($query)
Write-Host $items.Count


$count = $items.Count - 1
foreach ($item in $list.Items)
  {
 
    write-host "`rProcessing ID: $($item.ID) ($i of $batchSize)" -nonewline
   
   

        $listItem =$items.GetItemById($item.ID) #1187

        try
           {
                $IsRecord = [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::IsRecord($listItem)
                if ($IsRecord -eq $true)
                {
               
                [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::UndeclareItemAsRecord($listItem)
                    Write-Host "Success:Undeclared $($listItem.Title)"
                }
            }
        Catch [system.exception]
          {
                 Write-Host "Error:Item $($listItem.Title)"
          }
                 $listItem.Delete();

   
  }


#$items | % { $list.GetItemById($_.Id).Delete() }

#DEleting folders      
       
 $query =  New-Object Microsoft.SharePoint.SPQuery
$camlQuery = '<Where><Eq><FieldRef Name="ContentType" /><Value Type="Text">Folder</Value></Eq></Where>'
$query.Query = $camlQuery
$items = $list.GetItems($query)


 Write-Host("DELETED FILE: " + $count)

for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--)
{
   $items.Delete($intIndex);
    Write-Host("DELETED FILE: " + $intIndex)
 
}



$web.Dispose()
$site.Dispose()

Sharepoint Long Running Process

  using (SPLongOperation longOperation = new SPLongOperation(this.Page))
                {
                    longOperation.LeadingHTML = Constants.MSG_LONG_OPERATION;
                    longOperation.TrailingHTML = "";
                    longOperation.Begin();
                    LH.ARW.Repository.DataModel.Ticket ticketValues = new LH.ARW.Repository.DataModel.Ticket();
                    BulkUpdates(ticketValues);
                    longOperation.EndScript("window.frameElement.commitPopup();");    
                }

Tuesday, July 30, 2013

Finding substrings after speical char in sqlserver

SELECT isnull((SELECT TOP 1 1

FROM SYNPROD.GETEMPINFORMATION
WHERE
(
LTRIM(RTRIM(SUBSTRING(GRADE, 0, CHARINDEX('-',GRADE,0))))NOT  IN ('b1' ,'b2','b3')

AND GRADE NOT  IN ('e2','e3','e0','e4','e1')
)
and userid=@USERID ) ,0
) [eligile]