Thursday, July 2, 2015

How to Use JSLink with List View Web Part in SharePoint 2013

What is JsLink in SharePoint 2013:
JSLink is a new method of combining JavaScript, CSS and HTML elements together to customize the look and feel of SharePoint Fields, List Items, List views, List forms and web parts.
 
How to use JSLink in SharePoint 2013?
Here is the SharePoint 2013-jslink example. Lets customize the look and feel of static "% Complete" to bar chart with the help of JSLink. At high-level, here are the steps:
  1. Create a JavaScript override file
  2. Upload the JavaScript file to the "Master Page Gallery >> Display Templates", Set the content type and properties of the file.
  3. Set the JS Link property of the List view web part to point to the JavaScript file we've uploaded.

Step 1: Create your custom JS file to render SharePoint list field
As the first step, We'll have to create a new js file which customizes the rendering of our field. Here is what I've created "TaskListDT.js".
(function () {
var overrideCtx = {};
overrideCtx.Templates = {};
overrideCtx.Templates.Fields = {
'PercentComplete': { 'View': renderPercentComplete }
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();

function renderPercentComplete(ctx) {
 
    var fieldVal = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];
    var percentComplete = fieldVal.toString().replace(" ", "");
 
    var html = '';
    html += "<div style='width:100%;height:20px;border:1px solid #AEAEAE;position:relative;'>";
    html += "<div style='background-color:#0072C6;height:100%;width:" + percentComplete + ";'></div>";
    html += "<p style='width:100%;text-align:center;position:absolute;top:0px;left:0px;margin:0px;'>";
    html += percentComplete;
    html += "</p>";
    html += "</div>";
 
    return html;
}

Step 2: Upload the JS file to Display Templates Folder
Navigate to Site Settings >> Click on "Master pages" link. >> Navigate to "Display Templates" folder >> Upload your custom JS file. (It could be uploaded to anywhere in the site!)

While uploading, Make sure you set the properties of the JS file. Set the content type as "JavaScript Display Template" and supply other required parameter values as in the below screen.sharepoint 2013 how to use jslink

Step 3: Set JS Link property of List View Web part in SharePoint 2013
The next step is to specify the location of your JavaScript file in the List view web part property. Be sure you follow the "~sitecollection/Your-JS-File-complete-Path" format! (Can also use: ~site, ~layouts, ~siteLayouts, ~siteCollectionLayouts tokens)
jslink list view sharepoint 2013

Here is the Typical "% Complete" column from SharePoint 2013 task list:
sharepoint 2013 jslink property
and Here is our output - Bar charts for "% Complete" column.
sharepoint 2013 list view webpart jslink
In earlier versions of SharePoint (SharePoint 2007, SharePoint 2010), we used to customize XSL for such requirements. Here is one among them: Building Bar chart to Display Progress in Task List

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Monday, June 15, 2015

Move SharePoint Web Application's IIS Physical Path to a New Location

Requirement: Move SharePoint web application's IIS physical location from system drive (c:\) to application drive (d:\) due to new server support policies!

Solution:
SharePoint web applications, by default placed under: "C:\inetpub\wwwroot\wss\VirtualDirectories" when we create them. There is no UI/direct way to change the physical location of SharePoint IIS web sites later. However, these three steps can be utilized to move SharePoint web application's IIS physical directory to a new location:
  1. Copy all contents from the current virtual directory to new directory
  2. Change IIS website's physical path
  3. Update SharePoint web application to point to the new directory path.
Lets automate these manual steps with PowerShell.

PowerShell Script to Move IIS Web Site to New Physical Location:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Import IIS Module
Import-Module WebAdministration

#Variables
$WebAppURL="http://intranet.crescent.com/"
$NewPath="D:\IIS\VirtualDirectories\Intranet.Crescent.com"     
$IISSiteName = "Crescent Intranet" 
 
#Get Web Applications' IIS Settings
$WebApp = Get-SPWebApplication $WebAppURL
$IISSettings = $WebApp.IisSettings[[Microsoft.SharePoint.Administration.SPUrlZone]::Default]
$OldPath = $IISSettings.Path

#Check if destination folder exists already. If not, create the folder
if (!(Test-Path -path $NewPath))        
{            
    $DestFolder = New-Item $NewPath -type directory          
}

#***** Step 1 - Copy Current Virutal Directory to new location **** #
Copy-Item -Path $OldPath\* -Destination $NewPath -Force -Recurse 

#***** Step 2 - Change IIS Web Site's Physical path ******
Set-ItemProperty "IIS:\Sites\$($IISSiteName)" -name PhysicalPath -value $NewPath

#***** Step 3 - Update SharePoint Web Application ******
#Change the Web App path
$IISSettings.Path = $NewPath
#Update Web Application
$WebApp.Update()
Please note, You'll have to repeat steps 1 and 2 in all SharePoint web front end servers.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Monday, June 1, 2015

Restrict Office Web Apps Edit License within a AD Group

Requirement: SharePoint 2013 Office Web Apps "Edit in Browser" feature needs to be limited to users who has Microsoft Office Volume license.

Solution: License Enforcement in Office Web Apps 2013
The overall idea for the solution is: Create a new security group in AD, Add users to it - who are allowed to use edit option in Office web Apps. From SharePoint, Enable user licensing and map this AD group with the "Office Web Apps Edit" license.

Step 1: Create a AD Security Group
Login to your domain controller, Create new security group to hold users who are allowed to use Edit feature in office Web Apps. Add members to it. Here is mine: OWA Editors!
office web apps edit in browser

Step 2: Configure OWA and SharePoint to Enforce Licensing:
Login to your Office Web Apps Server, Create a new Office Web Apps Farm with "EditingEnabled" Switch.
New-OfficeWebAppsFarm -InternalUrl "http://was.crescent.com" -ExternalUrl "https://was.crescent.com" -CertificateName "Crescent Hosting Certificate" -AllowHTTP -SSLOffLoaded -EditingEnabled

For Existing OWA Farms, Set Editing Enabled Switch:
Set-OfficeWebAppsFarm -EditingEnabled

From SharePoint Server, Enable User licensing Enforcement and Add new Mapping: 
Check whether the licensing enforcement is enabled with the cmdlet: Get-SPUserLicensing , If its false, Enable it with:
Enable-SPUserLicensing
Once its enabled, verify the licenses created:
Get-SPUserLicense
This should return user licenses:Enterprise, Standard, Project, OfficeWebAppsEdit, etc.
 office web apps edit license

Now, you can map the AD security group with the Office Web Apps Edit license:
$LicenseMapping = New-SPUserLicenseMapping -SecurityGroup "OWA Editors" –License OfficeWebAppsEdit
$LicenseMapping | Add-SPUserLicenseMapping

Result: 
Users who are member of the AD group "OWA Editors" will get "Edit" options from Office Web Apps. Rest gets only "View" option.

Office Web Apps with View Option:
 office web apps 2013 edit in browser

Office Web Apps with Editing Option enabled:
sharepoint 2013 office web apps edit in browser
Important: Adding users to AD Security group will not take effect immediately!
This is by design! When you add/remove users to the dedicated AD group, it doesn't take effect immediately, because SharePoint does this sync in every 10 hours! To overcome, you can change these time intervals as in : SharePoint - Active Directory Security Group Membership Sync Problem and Solution
Same approach applies when you want to restrict users from using SharePoint 2013 Enterprise license!


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Sunday, May 24, 2015

How to Uninstall SharePoint 2013 - Complete Steps

Its a pretty common question and we stuck here often: How to Uninstall SharePoint 2013 completely from the server? Remove Server option From Central Administration >> Servers in Farm page? NO!! You can't uninstall SharePoint 2013 with this option. Remove server option must be used only when a particular server is no longer available and you want to remove it from your SharePoint farm.

Follow these steps to uninstall SharePoint 2013.
  • Go to Control Panel (Shortcut: Appwiz.cpl ), Pick Microsoft SharePoint Foundation 2013 (or Server!) and click on "Change" button.uninstall sharepoint server 2013
  •  In the Change your installation of Microsoft SharePoint Server 2013 page, Choose Remove, and then click Continue.how to uninstall sharepoint 2013
  • A confirmation message appears. Click Yes to remove SharePoint 2013.
     uninstall sharepoint 2013 server
  • A warning message appears. Click OK to continue.
     uninstall sharepoint 2013 manually
  • Watch the uninstall progress..
    how uninstall sharepoint 2013
  • Wait for the "Successfully uninstalled" message.
But wait! When you uninstall SharePoint 2013 with above steps, most of the files and folders are deleted. However, There are objects that needs our manual intervention.

Clear IIS Sites and Virtual Folders. Remove physical files 
We got to manually delete web applications created in IIS and their virtual folders from the file system.

Delete Search Index Files:
In search index servers, remove the search index manually. To get search index files location, Run these PowerShell cmdlets:
$SearchInstance = Get-SPEnterpriseSearchServiceInstance
$SearchInstance.Components

Delete IIS Log Files:

Delete 14/15 Hive customizations:
 
Delete the SharePoint Databases from Database Server:
Uninstalling SharePoint 2013 dismounts SharePoint databases from its web applications. But it doesn't remove any physical file stored in the database server. So, remove them all!

Technet reference on Uninstall SharePoint 2013: https://technet.microsoft.com/en-us/library/cc262874.aspx

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Saturday, May 9, 2015

Check In All Documents in a SharePoint Library using PowerShell

Requirement: Check-in All files which are checked out in a SharePoint document library.

How to Check In all checked out documents in SharePoint 2013:
SharePoint 2013 makes it simpler by providing context sensitive ribbon buttons to check in multiple files in bulk. Simply select all files which are checked-out and click on "Check In" button from the ribbon.
check in multiple documents in SharePoint 2013
But this method doesn't work when you have any required field with no default value assigned!

Check In All Documents in a SharePoint Library using PowerShell
When you do Multiple file upload (bulk upload or through explorer view) and your required column doesn't has any default value in it, then your files will be checked-out automatically. The "Check In" button won't work when you miss-out any required fields in the library.
You must fill out all required properties before checking in this document.

So, our solution is: PowerShell.

PowerShell script to check in all documents in the library:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables for Site URL and Library Name
$WebURL="http://sharepoint.crescent.com/sites/sales"
$LibraryName="Proposal Documents"

#Get Site and Library
$Web = Get-SPWeb $WebURL
$DocLib = $Web.Lists.TryGetList($LibraryName)

#Get all Checked out files
$CheckedOutFiles = $DocLib.Items | Where-Object { $_.File.CheckOutStatus -ne "None"} 

#Check in All Checked out Files in the library
ForEach($item in $CheckedOutFiles)
    { 
        #If you want to update fields
        #$item["Field"] = "value"
        #$item.SystemUpdate()

        #check in file programmatically     
        #$item.TakeoverCheckout() 
        $DocLib.GetItemById($item.Id).file.CheckIn("Checked in by Admin") 
        write-host "File:'$($item.Name)' has been checked in!"         
    }

Its possible to check-in file without supplying required field values through PowerShell!

If you want to do this for all libraries in your entire SharePoint web application, use: Find All Checked Out Files and Check-In them Back


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


You might also like:

Related Posts Plugin for WordPress, Blogger...