Skip to main content

Posts

Get SharePoint List Item Version History

Here is a powershell script you can use to get csv output of version history from SharePoint 2010 list. The output includes changes to individual item fields as viewable from item version history. $web  = Get-SPWeb http://pravahaminfo.com/web  $list = $web.Lists["Document Library"] # Name of the List?library $csvFile = "C:\ListItemVersionHistory.csv" # Save folder Location function GetFieldValue([Microsoft.SharePoint.SPField]$field, [Microsoft.SharePoint.SPListItemVersion]$currentVersion)  {      if(($field.Type -eq "User") -and ($currentVersion[$field.Title] -ne $null))      {          $newUser = [Microsoft.SharePoint.SPFieldUser]$field;          $fieldStr = $newUser.GetFieldValueAsText($currentVersion[$field.Title])          $fieldStr = "$($field.Title): $fieldStr"      }      elseif(($field.Type -eq "...

Copy List Item to other list in SharePoint using Powershell

#  In the below code, there are five custom variables ## $srcListSiteUrl : Site url where the source list is present ## $SourceListName : Name of the source list ## $dstListSiteUrl : Site url where the destination list is present (In the above code both lists are in the same site) ## $DestinationListName : Name of the destination list ## $keyColumnInternalName : Column name with which we have to check whether to insert or update. ## Note, in the above example $keyColumnInternalName value is ‘Title’. It is Text type. So, the CAML query variable $camlQuery is constructed in that way. ## If you have different data type column which you want to use as a reference column, you have to change the variable accordingly as the column type. ### Remove-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue     try     {     $srcListSiteUrl = "http://contoso...

Delete a List Item from a SiteCollection in SharePoint using Powershell

$site = Get-SPSite "http://contoso:1212/mysites/" $web = $site.rootweb $list = $web.Lists["Market"] $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 $items | % { $list.GetItemById($_.Id).Delete() } $web.Dispose() $site.Dispose()

Import List Items in SharePoint using Powershell

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue  $csvVariable= Import-CSV -path "http://sp2010.contoso.com/finance/" # Destination site collection $WebURL = "http://sp2010.contoso.com/sites/Utility/"  # Destination list name $listName = "Inventory"  #Get the SPWeb object and save it to a variable $web = Get-SPWeb -identity $WebURL  #Get the SPList object to retrieve the list $list = $web.Lists[$listName]  #Get all items in this list and save them to a variable  $items = $list.items        #loop through csv file foreach($row in $csvVariable) {     $updated = 0     #loop through SharePoint list     foreach($item in $items)     {         if($item["ID #"] -eq $row."ID #")              {                  $updated++          ...

Export List Items in SharePoint using Powershell

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue     #Get the target site collection  $web = Get-SPWeb -identity "http://sp2010.contoso.com/finance/"    #Get the Target List  $list = $web.Lists["Purchase"]     #Array to Hold Result - PSObjects  $ListItemCollection = @()      #Get All List items where Products is Stationary  $list.Items |  Where-Object { $_["Products"] -eq "Stationary"} | foreach {   $ExportItem = New-Object PSObject    $ExportItem | Add-Member -MemberType NoteProperty -name "Products" -value $_["Products"]   $ExportItem | Add-Member -MemberType NoteProperty -Name "Quantity" -value $_["Quantity"]   $ExportItem | Add-Member -MemberType NoteProperty -name "Vendor" -value $_["Vendor"]   $ExportItem | Add-Member -MemberType NoteProperty -name "ID #" -value $_["ID"]  $ExportI...

Photo Zoom option script

// Magnific Popup v0.9.9 by Dmitry Semenov // http://bit.ly/magnific-popup#build=inline+image+ajax+iframe+gallery+retina+imagezoom+fastclick (function(a){var b="Close",c="BeforeClose",d="AfterClose",e="BeforeAppend",f="MarkupParse",g="Open",h="Change",i="mfp",j="."+i,k="mfp-ready",l="mfp-removing",m="mfp-prevent-close",n,o=function(){},p=!!window.jQuery,q,r=a(window),s,t,u,v,w,x=function(a,b){n.ev.on(i+a+j,b)},y=function(b,c,d,e){var f=document.createElement("div");return f.className="mfp-"+b,d&&(f.innerHTML=d),e?c&&c.appendChild(f):(f=a(f),c&&f.appendTo(c)),f},z=function(b,c){n.ev.triggerHandler(i+b,c),n.st.callbacks&&(b=b.charAt(0).toLowerCase()+b.slice(1),n.st.callbacks[b]&&n.st.callbacks[b].apply(n,a.isArray(c)?c:[c]))},A=function(b){if(b!==w||!n.currTemplate.closeBtn)n.currTemplate.closeBtn=a(n.st.close...

ShowHidePagecontrol based on user permissions in SharePoint using javascript

$(document).ready(function (){         getCurrentUserRole();  });  function getCurrentUserRole() {     var userPerm;     $().SPServices({         operation: "GetRolesAndPermissionsForCurrentUser",         async: false,         completefunc: function (xData, Status) {             //if( Status == "success") {             userPerm = $(xData.responseXML).SPFilterNode("Permissions").attr("Value");             //alert(userPerm);                         var nonAdminP = (33554432 & userPerm) == 33554432;         ...

Upload only PDF and XSL files for SharePoint Lists

function OkAttach() {     a: ;     var g = FileuploadString + String(FileUploadIndex), b = GetAttachElement(g), f = TrimWhiteSpaces(b.value);     if (!Boolean(f)) {         alert(Strings.STS.L_FileNameRequired_TXT);         b.focus()     }      else if(CustomizedCheck(b.value)==false) {            if(_spPageContextInfo.serverRequestPath.indexOf("Listname1") > -1)            {             alert("Invalid File Type. (Only PDF/PPTX files are allowed.)");            }            else if(_spPageContextInfo.serverRequestPath.indexOf("ListName2") > -1)        ...

Getting SharePoint List attachments in the SPGrid or Asp grid

In ascx or aspx file add the below code : <script type="text/javascript">        var listName = "List Name";        function deleteListItem(ID) {         var siteUrl = 'Site URL';         this.itemId = ID;         var clientContext = new SP.ClientContext(siteUrl);         var oList = clientContext.get_web().get_lists().getByTitle('List Name);         this.oListItem = oList.getItemById(itemId);         oListItem.deleteObject();         clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));     }     function onQuerySucceeded(data) {         al...