Tuesday, March 31, 2015

Powershell Move-Item does not create a new folder

While working on powershell I found out that while moving a folder from one location to another, powershell Move-Item command does not create top level folder if the destination folder does not contain any items already.

e.g. if folder A contains only one folder B which has a file MyFile.txt and we want to move folder B inside an empty folder C,

Get-ChildItem "C:\A" |% {Move-Item -Path $_.FullName -Destination "C:\C" -Force}

Above command does not create folder B at the destination location as expected, instead it only moves file the MyFile.txt directly under folder C. A workaround for this issue is just display full name of the folder using $_.FullName like explained below

Get-ChildItem "C:\A" |% {Write-Host $_.Name;Move-Item -Path $_.FullName -Destination "C:\C" -Force}

This command creates a folder B under folder C and moves file MyFile.txt under it.

Wednesday, March 25, 2015

Sharepoint REST API based data view webpart

This blog explains an efficient way to create a data view webpart using only REST based web service calls. It is quite useful for may of the complex view and query operations required on a coporate intranet site.

http://summit7systems.com/who-needs-a-data-view-web-part-sharepoint-rest-and-datatables-net/

Get data in a SharePoint list view in XML format

Here is a quick way to retrieve data displayed in a sharepoint list or document library view in XML format, use the list id, view id in following format

http://Server_Name/[sites/][Site_Name/]_vti_bin/owssvr.dll?XMLDATA=1&List={<List GUID>}&View={<View GUID>}&RowLimit=0&RootFolder=<URL Encoded Relative path of the folder>

The variables are
<Site URL>: normal URL of the web or subsite where your list or document library exists e.g. http://sharepoint/sites/hr

<List GUID>: GUID of the list e.g. 263FE49C-7FB3-4247-93CD-4AAB9770EF97
<View GUID>: GUID of the view in question 
<URL Encoded Relative path of the folder>: Relative of the folder inside list which you 
need to converted to XML e.g. %2fsites%2fHR%2fDocuments
Also refer to following post for more details about this command
https://msdn.microsoft.com/en-us/library/dd587743(v=office.11).aspx
If you need to export to excel, you can use 
http://Server_Name/[sites/][Site_Name/]_vti_bin/owssvr.dll?CS=109&Using=_layouts/query.iqy&List=GUID&View=GUID&CacheControl=1
as explained in above microsoft help. Also, I have found out that this URL format works as well
http://Server_Name/[sites/][Site_Name/]_vti_bin/owssvr.dll?CS=65001&Using=_layouts/query.iqy&List=%7B<List GUID>%7D&View=%7B<View GUID>%7D&RootFolder=<URL Encoded Relative path of the folder>&CacheControl=1

To generate outlook calender events file replace Using=_layouts/query.iqy with Using=event.ics as explained here


Tuesday, March 24, 2015

Submit HTML form using content editor webpart

This is a nice article about custom HTML forms in CWEP

http://sadomovalex.blogspot.co.uk/2011/01/submit-html-form-using-content-editor.html

Redirect to a custom page after submit button click on list view forms

Filter list view webpart using querystring parameters for date

Querystring paramters can be added to a XmlListViewWebpart and the data can be filtered based on them, however when using date parameters, the format of date in querystring is often confusing. The correct date format is yyyy-MM-dd. More details in the following two blogs

https://stackoverflow.com/questions/1655664/sharepoint-list-view-datetime-in-the-query-string/29235326#29235326

https://social.technet.microsoft.com/Forums/en-US/92271aa4-6582-4ea5-a10f-deaf02d2b62c/filtering-the-list-view-by-passing-date-parameters-using-sharepoint-desginer-2010?forum=sharepointcustomizationprevious


There is also a custom webpart available on codeproject which creates a custom menu button to export only filtered list view webpart data to excel

http://www.codeproject.com/Articles/400720/SharePoint-2010-Export-Selected-Items-to-Excel

SharePoint Nintex workflow to Move documents with version history

There was a great post at http://www.vadimtabakman.com/nintex-workflow-move-documents-and-preserve-version-history.aspx about creating a Nintex workflow to move a document to another document library with version history.

Also, to move manually, open both document libraries in windows explorer and the drag-drop the document in to destination library or cut-paste it.

Thursday, March 19, 2015

Lot of useful powershell utilities

This blog has a whole collection of useful utilities.. ..... saves lot of time..

http://blog.falchionconsulting.com/index.php/downloads/


Sharepoint 2007 to 2010 migration Issues

Powershell script to upgrade UI version and apply root web master page to all subsites

I have used this powershell script to upgrade UI version and apply the master page at root web of a site collection to all subsites

$siteUrl = "http://<Site URL>"

Start-SPAssignment -Global
$site = Get-SPSite "$siteUrl"
$topWeb = Get-SPWeb $site.Url
$topWeb.CustomMasterUrl = "/_catalogs/masterpage/My.master"
$topWeb.MasterUrl = "/_catalogs/masterpage/My.master"
$topWeb.Update()
$site | Get-SPWeb -limit all | ForEach-Object {$_.UIVersion = 4;$_.UIVersionConfigurationEnabled = 0;if (($_.WebTemplate -ne "SRCHCEN") -and ($_.WebTemplate -ne "SRCHCENTERLITE") -and ($_.WebTemplate -ne "SRCHCENTERFAST")) {$_.CustomMasterUrl = $topWeb.CustomMasterUrl;$_.AllProperties["__InheritsCustomMasterUrl"] = "True";$_.MasterUrl = $topWeb.MasterUrl;$_.AllProperties["__InheritsMasterUrl"] = "True";$_.AlternateCssUrl = $topWeb.AlternateCssUrl;$_.AllProperties["__InheritsAlternateCssUrl"] = "True";$_.Update();}}

Stop-SPAssignment -Global

Powershell script to copy master page to new site collection after upgrade

I have used this powershell script to  copy master page to new site collection after upgrade


$srcUrl = "http://<Source Site Url>"
$destUrl = "http://<Dest Site Url>"

$site = Get-SPSite $srcUrl
$topWeb = Get-SPWeb $site.Url

### Copy master page to the new site collection
$SourceWebURL = $destUrl
$SourceLibraryTitle = "Master Page Gallery" 
$DestinationLibraryTitle = $SourceLibraryTitle
$MasterPageTitle = "My.master"
$sWeb = Get-SPWeb $SourceWebURL
$sList = $sWeb.Lists | ? {$_.BaseType -eq "DocumentLibrary" -and $_.title -eq $SourceLibraryTitle}
$sItem = $sList.Items | ? {$_.Name -eq $MasterPageTitle}

$dList = $topWeb.Lists | ? {$_.BaseType -eq "DocumentLibrary" -and $_.title -eq $DestinationLibraryTitle}

if($sItem -eq $null)
{
write-host -ForegroundColor red "My.maser does not exist at web application root web"
}
else
{
$sBytes = $sItem.File.OpenBinary()
$dFile = $dList.RootFolder.Files.Add($sItem.Name, $sBytes, $true)

$AllFields = $sItem.Fields | ? {!($_.sealed)}

Write-Host -ForegroundColor green "Copying My master page to the new site collection"

foreach($Field in $AllFields)
{
    if($sItem.Properties[$Field.Title])
    {
        if(!($dFile.Properties[$Field.title]))
        {
            $dFile.AddProperty($Field.Title, $sItem.Properties[$Field.Title])
        }
        else
        {
            $dFile.Properties[$Field.Title] = $sItem.Properties[$Field.Title]
        }
    }
}
$dFile.Update()
if ($dFile.CheckOutType -ne "None")
    {
        $dFile.CheckIn("Automatically checked in by Powershell", "MajorCheckIn");
    }
    if ($dFile.Item.Versions[0].Level -ne "Published")
    {
        $dFile.Publish("Automatically published by Powershell");
    }
    if ($dFile.Item.ModerationInformation.Status -ne "Approved")
    {
        $dFile.Approve("Automatically approved by by Powershell");
    }
}


$sWeb.Dispose()
$topWeb.Dispose()

$site.Dispose()

Enable/Disable Developer Dashboard

Wednesday, March 18, 2015

Export sharepoint site but exclude its susites

I have found this blog has very useful information to export a site without including its subsites

http://sharepoint.stackexchange.com/questions/17671/export-spsite-but-exclude-subsites

Powershell update all navigation URL to be relative instead of absolete

I have used this powershell script to update all navigation items in a site collection to use only relative URLs instead of absolute ones.

function ProcessWeb($currentWeb)
   Write-Host -ForegroundColor Green "Processing web" $currentWeb.Url
   $currentWeb.AllowUnsafeUpdates = 1
   UpdateNavigation($currentWeb)
   $currentWeb.Update()
   $currentWeb.AllowUnsafeUpdates = 0
   foreach($sub in $currentWeb.Webs)
   {
         ProcessWeb($sub)
   }       
}

function UpdateNavigation($web)
{
   
    $topNavigationNodes = $web.Navigation.TopNavigationBar
    UpdateNavNodes($topNavigationNodes);
    $quickLaunchNodes = $web.Navigation.QuickLaunch
    UpdateNavNodes($quickLaunchNodes);
}

function UpdateNavNodes($navNodesCollection)
{
  if ($navNodesCollection -ne $null)
  {
    foreach($navNode in $navNodesCollection)
    {
        $navNode.Url = $navNode.Url.Replace('http://<My Root Site Url>','')
        $navNode.Update()
    }
  }
}

Write-Host -ForegroundColor red "STARTED"
ProcessWeb(Get-SPWeb -identity "http://<My Site Collection Url>")
Write-Host -ForegroundColor red "FINISHED"

Tuesday, March 17, 2015

spexception:81020014 Error while activating publishing feature at a site level after upgrading the site from SharePoint 2007 to SharePoint 2010

This issue is caused by Relationships list having wrong column name. The error log is

Watson bucket parameters: SharePoint Server 2010, ULSException14, 81eed5e0 "web content management", 0e001b67 "14.0.7015.0", 1f65804a "microsoft.sharepoint", 0e001be1 "14.0.7137.0", 543d891b "tue oct 14 21:35:39 2014", 00003bf7 "00003bf7", 00000027 "00000027", 33ecf53b "spexception:81020014", 38666937 "8fi7"

It can be solved easily by following steps as mentioned in the blog https://social.technet.microsoft.com/Forums/office/en-US/a30f0ffd-782f-4d4a-9c22-b92bac0fad4f/error-when-starting-a-sharepoint-2010-beta-2-publishing-site?forum=sharepointadminprevious

Basically

  1. Deactivate publishing infrastructure feature if it is already active 
  2. Delete the relationship list at site collection root web 
  3. Activate publishing infrastructure feature at site collection features 
  4. Activate publishing site feature at the site.

Secure micro services using jwt and ocelot

  Secure Microservices Using JWT With Ocelot in .NET Core (code-maze.com)