Sunday, February 22, 2015

Updating the SharePoint Online site logo with power shell code

In order to update the site logo for a Office 365 SharePoint site below code snippet can be used. I had used a SharePoint office 365 developer site to change the site logo.

$credential=Get-Credential
$username=$credential.UserName
$password=$credential.GetNetworkCredential().Password
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$url = "https://spk0365.sharepoint.com/sites/PradeepLearning"

 ### References # Specify the path where the dll's are located.
 Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
 Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

 $clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url)
 $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
 $clientContext.Credentials = $credentials
 #Get the SharePoint Web
 $web=$clientContext.Web;
 $web.SiteLogoUrl="https://spk0365.sharepoint.com/sites/PradeepLearning/SiteAssets/team-india-630-new-odi-kit.jpg";
 $web.Update();
 $clientContext.Load($web);
 $clientContext.ExecuteQuery();

Wednesday, February 4, 2015

Power Shell for SharePoint Office 365

For SharePoint 2013 on premises we had around 700+ command lets but SharePoint 2013 Online has a limited command-lets of 30 because of this limitation we are going to use power shell with Client side object model.Below are prerequisites for running a power shell script.

1. You need to have Power shell ISE
2. You need to have assemblies and these can be downloaded here

Power Shell scripts for retrieving all the lists present in the site and exporting it to CSV File

#Enter the credentials in dialog box
$credential = Get-Credential
$username=$credential.UserName
$password=$credential.GetNetworkCredential().Password
$securePassword=ConvertTo-SecureString $password -AsPlainText -Force

##URL for site
$url="https://spk0365.sharepoint.com/sites/PradeepLearning"

#Add dll
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

## Function to retrieve lists in the site
function GetAllLists()
{
$clientContext=New-Object Microsoft.SharePoint.Client.ClientContext($url)
$credentials=New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username,$securePassword)
$clientContext.Credentials=$credentials
$web=$clientContext.Web;
$listColl=$web.Lists;
$clientContext.Load($listColl);

#Execute query will execute the query with server and will load site's lists properties in ClientContext
$clientContext.ExecuteQuery();
foreach($list in $listColl)
{
Write-Host "List Name: " $list.Title " ID: " $list.Id

#Writing the Lists properties to CSV
$web.Lists | select Title,ID | Export-CSV c:\Lists.csv
}
}

#Calling the function
GetAllLists

Monday, February 2, 2015

XSLT in SharePoint

XSLT stands for Extensible style sheet transformations. It is basically used to convert XML document into HTML output file. It can be used to present xml data in many different ways.
In SharePoint it is used as part of
  • XML Viewer Web Part
  • XSLT list view web part
  • Content query web part XSLT
  • Search results can be formatted using XSLT
These topic covers example of XML viewer web part in SharePoint 2013 Online. We will be using two files, one is xml file which contains xml data and other is xslt file which basically reads each node and transforms the data to html page. I had taken xml file from this link.
SharePoint Out of the box has list view webpart so we will be using this webpart and it bascially asks for two sources xml and xslt files. I had prepared xslt using the xml file and below is the code snippet for xslt. Once these files are configured properly we should be able to see the XMlL viewer webpart.