Thursday, 15 May 2014


<xsl:value-of select="ddwrt:FormatDateTime(string(ddwrt:Today()),1033,'dd')"/>

Displaying today’s date using XSL and SharePoint
 < xsl:value-of select="ddwrt:Today()">

FormatDate(string szDate, long lcid, long formatFlag) 
FormatDate(@Today, 1033, @No)

1  : 5/9/2007
3  : Wednesday, May 09, 2007
4  : 9:06 AM
5  : 5/9/2007 9:06 AM
7  : Wednesday, May 09, 2007 9:06 AM
12: 9:06:12 AM
13: 5/9/2007 9:06:12 AM
15: Wednesday, May 09, 2007 9:06:12 AM

 < xsl:value-of select="ddwrt:FormatDateTime(string(ddwrt:Today()), 1033,'yyyyMMdd')" > < /xsl:value-of > 

XsltListViewWebPart Date Format using DDWRT
 <xsl:value-of select="ddwrt:FormatDateTime(string(@Modified), 3081, ‘dd-MMM-yyyy’)" />

SPLocale.LCID property & Regional settings (SharePoint Server 2010)
 Australia: 3081
 Persian: 1065

Branding CSS and Javascript tricks

How To: Hide Left Side Navigation on Home Page
<style type="text/css">
 body #s4-leftpanel {display: none;
.s4-ca {margin-left: 0px;

How To: Hide Recently Modified
<style type="text/css">
 .s4-recentchanges {display:none;}

How To: Change the “No Items” message in a discussion web part with jQuery
<script type="text/javascript">
 $("td .ms-vb:contains('There are no items to show in')").text('There are no active discussions');

How To: Hiding “Add new item” and “There are no items to show…” in SharePoint

How To: How To Remove Extra Space Around the Web Part In SharePoint 2013
<style type="text/css">
 .ms-webpartPage-root {border-spacing: 0px !important;}
 .ms-webpartzone-cell {margin: 0px !important;}

How To: Hide a web part with zero rows
function HideWebPartWithZeroRows()
  var a = document.getElementsByTagName("TABLE")
  for (var i=0;i<a.length;i++)
    if (a[i].summary=="Test List")
      if (a[i].rows.length==1)
        //hide all but the title bar
        //var x =  a[i].parentNode.parentNode.parentNode.parentNode.parentNode
        //hide the entire web part
        var x =  a[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode"none";

How To: Remove link border from around image
   a img {border:none}
<a href="">
   <img src="">

OR via inline styles:

<a href="">
   <img src="" style="border:none;">


Monday, 10 March 2014

SharePoint 2010 on Windows Server 2012

When you try and run the SharePoint 2010 prerequisite on Windows Server 2012 R2, you will receive an error and it fails right away.

To get around the issue, Run PowerShell and execute this command:
Get-WindowsFeature | Where-Object {$ -like "*net*" }

If the above doesn't work for you, type Import-module servermanager to add the Get-WindowsFeature cmdlet.

The above command is to see which .NET features were installed. 3.5 is not installed and that might be our missing link:

To add it, you’ll need your Windows 2012 R2 source media. Assuming your media is in your D: drive, the command to add it would look like this:
Add-WindowsFeature Web-Asp-Net -Source D:\sources\sxs

If you have an .iso file, mount it to a drive and then replace the "D:\" with your own drive letter.

After executing the command, wait for few minutes until the new command line shows (as bellow) this will add the stuff that the SharePoint prerequisite installer wants.

Now if we run the perquisite again, it runs successfully and we can move on to install SharePoint.

Note: in my case, I had to restart windows first before continue the installation.

Sunday, 23 February 2014

Thursday, 20 February 2014

How to Change an Image's Size and Shape in SharePoint


Scenario: I see it all the time: SharePoint content owners create sites using images that are much too large for Web consumption. It’s easy to understand why this happens. Sally Site-Owner gets a photo or image from the marketing department that was created for print or some other high-resolution format. Sally uploads the image to SharePoint and simply resizes its height and width using the ribbon controls to make the page look nice. Of course, resizing an image in this way doesn’t actually make the file size any smaller, and now end users (potentially even users on slow or metered mobile connections) will have to patiently download the large image to see the page.

SharePoint 2013 answers this problem with a SharePoint Server publishing feature known as image renditions. With image renditions, you can add images to a library and easily add them to pages using various predetermined widths and heights without downloading the full-sized image.
I’ll assume the first two are pretty easy to figure out without me going through the steps. To turn on Blob Caching, simply navigate to the web.config file for your SharePoint site on the physical server. It is usually located in a directory similar to C:\inetpub\wwwroot\wss\VirtualDirectories\80. You can use IIS to help find the directory if you want. Open web.config in an editor like Notepad (when you hit Save, IIS will reset the SharePoint site, so make sure not to do this on production during peak hours) and use Control-F to find the first instance of “<BlobCache”. In this line, you will see enabled="false". Simply change this to “true” and hit save.

Now you can create your own image-rendition sizes fromSettings > Site settings > Look and Feel > Image Renditions. There should be a few predefined sizes you can use. To create your own, simply click Add new item, enter a name, width and height, then click Save. Now, when you add images to a picture library, you will have a rendition that matches that size that you can work with.
To work with the image renditions, navigate to your picture library and upload a picture. Once the picture thumbnail shows in the library, hover over it, click the ellipsis in the bottom-right, and then click Edit Renditions.

From here, you will see a list of all the renditions that are available, with images already created for each size. You can edit the sizing and cropping of a rendition from Click to change. This will show you a dashed box that is constrained to the size of the image rendition, and you can move and resize photo accordingly to show the image in the best possible way. This can be useful for showing faces or text in smaller sizes.
 With your image renditions set up and configured, now you can select from the different size options when you insert an image into a publishing page. After editing a page and inserting the image, from the ribbon you would just click the image tab and then choose from the Pick Rendition dropdown.
Because an image rendition is being used, the image in my example is actually a 150px by 150px file and should download quicker than a full-sized image. Pretty cool, right? What if you want to reference the image rendition directly using code or without the ribbon? Well that’s pretty easy: You can pass URL parameters to the image for either the RenditionID (the number in the image rendition list order: 1, 2, 3, etc.), or for width and/or height.

For example, in my sample to the right, the raw image URL inSharePoint was:
If I want to load the image rendition for 304x100, I can reference the image like this:

You can reference an image with just the height or width also, but if there are multiple matching renditions, the first will be returned.

Image rendition is a pretty handy feature for helping content authors create images that are sized appropriately for the Web. Oh hey, did I forget to mention that image renditions work with videos also? So be sure to try that out as well!​

Can’t crawl web apps you KNOW you should be able to crawl

To specify the host names that are mapped to the loopback address and can connect to Web sites on your computer, follow these steps:
  1. Set the
    registry entry to 1. For more information about how to do this, click the following article number to view the article in the Microsoft Knowledge Base:
    281308 Connecting to SMB share on a Windows 2000-based computer or a Windows Server 2003-based computer may not work with an alias name
  2. Click Start, click Run, type regedit, and then click OK.
  3. In Registry Editor, locate and then click the following registry key:
  4. Right-click MSV1_0, point to New, and then click Multi-String Value.
  5. Type BackConnectionHostNames, and then press ENTER.
  6. Right-click BackConnectionHostNames, and then click Modify.
  7. In the Value data box, type the host name or the host names for the sites that are on the local computer, and then clickOK.
  8. Quit Registry Editor, and then restart the IISAdmin service.

SharePoint Trick: Link to an Image Thumbnail

  • Navigate to the image in the image library where it is stored.
  • Click on the image so that you see the "item view" of the image. The default attributes such as Name, Title, and Preview will show up, along with an attribute called Thumbnail Preview.
  • The link to the Thumbnail Preview is not easily exposed, but you can "cheat" and find it by right clicking on the image and then selecting Properties.
  • Select the entire contents of the Address (URL) field shown in the thumbnail image properties. Be sure to keep scrolling in the Address (URL) field until you have captured the complete URL for the thumbnail. You will know if you have it right if you see _jpg.jpg at the end.
  • You can then paste this "secret" URL in a hyperlink column in your list and the link will show the thumbnail, not the image preview.
You can also create the link to the Thumbnail on your own by inserting the characters _t/ in front of the file name and the characters _jpg immediately after the file name in the default image URL as shown below:
Link to default image preview:
  • intranet/sitename/libraryname/foldername/imagename.jpg
Link to Thumbnail for the same image:

  • intranet/sitename/libraryname/foldername/_t/imagename_jpg.jpg

SharePoint Governance: To get started, it’s important to have the right conversations!


patterns & practices SharePoint Guidance

patterns & practices SharePoint Guidance​
Error Logging in SharePoint

SharePoint 2013 development overview

Put the JavaScript or XAP files in a SharePoint library, and enable binary large object (BLOB) caching. BLOB caching instructs SharePoint to cache BLOB content, such as JavaScript and XAP files, on the SharePoint Web front-end servers. It also enables client browsers to cache the content. If BLOB caching is not enabled, the HTTP header that returns the JavaScript or XAP resources to the client will instruct the browser not to cache the files. It does this by including a cache-control: private directive and by setting an expiration time in the past. As a result, neither the client browser nor the web front-end server will cache the content, which instead will be retrieved from the content database on every request. BLOB caching is a SharePoint Server 2010 feature and must be enabled in the configuration files for the SharePoint web applications, so to some degree you are at the mercy of the farm administrator. For more information on BLOB caching, see Disk-Based Caching for Binary Large Objects. 

REST in SP2010


SharePoint Development Debugging

I've been reading a lot of posts on how to get debugging going when attaching to the w3wp.exe process.

Disable 'Enable Just My Code' in Visual Studio

This blog post started me off in the correct direction by setting the Tools | Options | Debugging setting correctly.

Modify the web.config

Furthermore, it prompted me to change the web.config value from debug="false" to debug="true". The web.config file can be found in the Inetpub\wwwroot\wss\VirtualDirectories\ folder, each folder in there maps to an IIS Web Application which you can find by going to IIS Manager and looking at the Home Directory.
To get full blown ASP.NET errors rather than SharePoint branded "useless" ones follow these steps:

Setting CallStack=true

By default, WSS will redirect a user to the error page whenever an unhandled exception is encountered during the render cycle.  To disable this behavior, open your web.config and set CallStack="true" in the <SafeMode> node.  This allows you to see a typical error page.

Setting customErrors mode...

The next step would be set mode="Off" in the <customErrors> node.  This instructs to show you a complete error report rather than a generic "Server Error" page.

Creating pdbs

For each project you wish to debug, you need to ensure that you are creating pdbs. I am using the really cool stsdev app to create my projects and had to modify it to create pdbs by going to Project Properties and on the Build tab in the Output Section click the Advanced button. 
Then ensure that Debug Info is set to pdb-only. 

Attach to Process

The author of the previous referenced post also pointed me to running iisapp on the command line to output a list of all the running instance to know which process to attach to:
Then when you select Debug | Attach to Process the ID matches to the PID in the output of iisapp. Note you need to check 'Show processes from all users' as w3wp.exe will be typically running as another account.

You can check that you have the correct id by pressing CTRL-ALT-U and this will list all the Modules that are loaded with statuses on the symbols that are available (e.g. that when you create a breakpoint it'll work rather than giving you a 'No symbols loaded' errror).

Sometimes there are just too many instances of w3wp.exe to pick from. An easy way to just let the system sort things out for you, rather than inserting a breakpoint, is to insert the following line in your code:

Notes for Visual Studio Debugging Newbies

Once you are actually debugging and can step through code after it breaks on a can also use the Immediate window to inspect objects by pressing CTRL-ALT-I. From here you can get up intellisense on any object in context which is a great way to inspect things like whether a SharePoint list has an Event Receiver on it or not. 

The web server process that was being debugged has been terminated by Internet Information Services (IIS)

If you are debugging in IIS7.0 you will find that you will receive this error if you leave it on a break point for too long.

Unknown macro: {NewCode}
Microsoft Visual Studio
The web server process that was being debugged has been terminated by Internet Information Services (IIS). This can be avoided by configuring Application Pool ping settings in IIS. See help for further details.
OK Help

The Resolution is to follow these steps on MSDN - Error: Web site worker process has been terminated by IIS

Optimizing SharePoint sites


Get SharePoint fields internal name

Use this powershell command:
$list = (Get-SPWeb "").Lists["Demo List"]
$list.Fields | ?{$_.title -eq "Title"} | FT Title, InternalName
PS C:\Users\> $list = (Get-SPWeb "http://emflow").Lists["work items"]
PS C:\Users\> $list.Fields | ?{$_.title -eq "Title"} | FT Title, InternalName
Title                                   InternalName
-----                                   ------------
Title                                   Title
Title                                   LinkTitleNoMenu
Title                                   LinkTitle
Title                                   LinkTitle2

PS C:\Users\> $list.Views | FT viewfields

{Activity_x0020_ID, Status, Entry_x0020_Date, SLA_x0020_Date...}
{Modified, Activity_x0020_ID, Status, Entry_x0020_Date...}
{Modified, Activity_x0020_ID, Assign_x0020_Bucket_x003a_Group_, Entry_x0020_...
{Activity_x0020_ID, Status, Entry_x0020_Date, SLA_x0020_Date...}
{Modified, Activity_x0020_ID, Assign_x0020_Bucket_x003a_Group_, Entry_x0020_...
{Modified, Activity_x0020_ID, Status, Entry_x0020_Date...}
{Activity_x0020_ID, Status, Entry_x0020_Date, SLA_x0020_Date...}
{Activity_x0020_ID, Assign_x0020_Bucket_x003a_Group_, Entry_x0020_Date, SLA_...
{Activity_x0020_ID, Assign_x0020_Bucket_x003a_Group_, Entry_x0020_Date, SLA_...
{Activity_x0020_ID, Status, Entry_x0020_Date, SLA_x0020_Date...}
{Activity_x0020_ID, Status, Entry_x0020_Date, SLA_x0020_Date...}
{Activity_x0020_ID, Status, Entry_x0020_Date, SLA_x0020_Date...}
{Activity_x0020_ID, Status, Entry_x0020_Date, SLA_x0020_Date...}

PS C:\Users\>

SharePoint 2013 REST API endpoint links

 SharePoint REST request syntax

To access a specific site collection, use the following construction:
To access a specific site, use the following construction:

Feature area
Access point
User Profile
http:// server/site/_api/SP.UserProfiles.PeopleManager
http:// server/site/_api/search
http:// server/site/_api/publishing

Client object model API
REST endpoint

SharePoint REST parameter syntax

SharePoint REST service method parameter syntax

To construct URIs that correspond to static methods or properties, use the corresponding API name from the ECMAScript object model, starting with the namespace declaration and using dot notation. For example, SP.Utilities.Utility.getImageUrl(imageName) in the ECMAScript client object model would have the following REST equivalent:


The following example shows how to retrieve all of a list’s items.
url: http://site url/_api/web/lists/GetByTitle(‘Test')/items
method: GET
    Authorization: "Bearer " + accessToken
    accept: "application/json;odata=verbose" or “application/atom+xml”

The following example shows how to retrieve a specific list item.

url: http://site url/_api/web/lists/GetByTitle(‘Test')/items(item id)
method: GET
    Authorization: "Bearer " + accessToken
    accept: "application/json;odata=verbose" or “application/atom+xml”


URI Conventions - Filter System Query Option ($filter)

web/lists/getByTitle('ListName')/Items?$select=Title&$filter=AverageRating gt 3


Making the Newsfeed web part available outside of My Sites in SharePoint 2013

This is actually a web part titled Newsfeed, and can be found under the Social Collaboration category. Now, you may want to have the Newsfeed on the homepage of your main portal rather than My Site. To make this web part available in your site collection, you will need to activate the feature with title “My Site Layouts Feature“. This is a hidden site collection feature so you will need to use SharePoint Manager or PowerShell. The feature ID is 6928B0E5-5707-46a1-AE16-D6E52522D52B. Its physical location under {SharePointRoot} is TEMPLATE\FEATURES\MySiteLayouts.
This feature brings a number of other web parts and also the MySite.master master page. Check its manifest for further details.
Enable-SPFeature -Identity 6928B0E5-5707-46a1-AE16-D6E52522D52B -Url http://yourSiteCollection

The SiteFeedWebPart is in the Microsoft.SharePoint.Portal.WebControls namespace.

Making My Tasks web part available outside of MySites

The My Tasks web part exists in MySites by default, and can be found under the Content Rollup category. To make this web part available outside of MySites, activate the “My Tasks Dashboard” feature.

This is a hidden Web-scoped feature. The feature ID is 89D1184C-8191-4303-A430-7A24291531C9, and the feature folder under SharePointRoot is MyTasksDashboard.


How to Get Login Name and Display Name using SharePoint 2013 REST API

    url: "/SiteName/_api/web/lists/getbytitle('ListName')/items",
    type: "GET",
    headers: { "Accept": "application/json;odata=verbose" },
    success: function(data, textStatus, xhr) {
        var dataResults = data.d.results;
        var resultId = dataResults[0].AuthorId.results[0];        
    error: function(xhr, textStatus, errorThrown) {

function getUser(id){
var returnValue;
   url: "http://YourSite/_api/Web/GetUserById(" + id + ")",
   type: "GET",
   headers: { "Accept": "application/json;odata=verbose" },
   success: function(data) {
           var dataResults = data.d;
      //get login name  
      var loginName  = dataResults.LoginName.split('|')[1];
      //get display name
How to Get Login Name and Display Name using SharePoint 2013 REST API


SharePoint 2013 Apps and AngularJS - The basics
SharePoint Hosted App with CSOM & AngularJS for MVC Javascript
Marc D Anderson
Mark Rackley
Andrew Connell
SharePoint Hosted App with CSOM & AngularJS for MVC Javascript

"Sign in as Different User" menu option is missing in SharePoint Server 2013


Bookmarklet to Sign in as a Different User

"Sign in as Different User" menu option is missing in SharePoint Server 2013

User Profile (issues when NetBIOS name is different from FQDN)

After installing user profile and sync with active directory, all the users prefix is changed to "corp/".
user Profile 1.PNG

For any profile which you click on "Edit My Profile", even without making any changes, the prefix will change to "NTDOMAIN\".
user Profile 2.PNG

HBF adctive directory domain name and DNS name is different:​
  • First, delete the AD connections from the user profile manage page.
  • then, run this powershell command
$upsa = Get-SPServiceApplication -Id <GUID of User Profile Service Application>
$upsa.NetBIOSDomainNamesEnabled = 1
Replace <GUID of User Profile Service Application> with the service guid above.

  • Restart IIS and OWSTimer
  • Recreate the AD connection
  • Run full import twice
  • Run incremental sync

Use case: Automatically importing user profile pictures to SharePoint 2013 (and 2010)

SP2010 User Profile Service Application Setup and NetBIOSDomainNamesEnabled Issues 

err 5766 - Error provisioning the local timer service instance during deploying of administration application pool credentials

this error happens when the application pool account password has been changed.
log err jww virtual.PNG

"Error provisioning the local timer service instance during deploying of administration application pool credentials, please provision manually. The password for the account NTDOMAIN\spa, as currently stored in SharePoint, is not the same as the current password for the account within Active Directory. To fix this with PowerShell, run Set-SPManagedAccount -UseExistingPassword."
To resolve the issue, run this powershell command.
Set-SPManagedAccount -UseExistingPassword 


Hide SharePoint Navigation

<style type="text/css"> s4-ribbonrowhidetitle.s4-notdlg noindex#ms-cui-ribbonTopBars#s4-titlerow#s4-pr s4-notdlg s4-titlerowhidetitle#s4-leftpanel-content {display:none !important;}
    .s4-ca{margin-left:0px !importantmargin-right:0px !important;}

Hide ScrollBar

<style type="text/css">
body.v4master { overflow: visible; height: inherit; width: inherit;}
body #s4-workspace { overflow: visible !important; }
body #s4-ribbonrow { position: fixed; z-index: 1000; overflow-y:visible;}
#s4-ribbonrow .ms-MenuUIPopupBody, #s4-ribbonrow .ms-popoutMenu, .ms-cui-menu[id ^= "Ribbon."] { position: fixed !important; }
.ms-dlgOverlay { width: 100% !important; }

my notes:

Corporate Library

Remove webpart:

Add css below:
<style type="text/css">
    #s4-ribbonrow, .ms-cui-topBar2, .s4-notdlg, .s4-pr s4-ribbonrowhidetitle, .s4-notdlg noindex, #ms-cui-ribbonTopBars, #s4-titlerow, #s4-pr s4-notdlg s4-titlerowhidetitle, #s4-leftpanel-content {display:none !important;}
    .s4-ca{margin-left:0px !important; margin-right:0px !important;}

body.v4master { overflow: visible; height: inherit; width: inherit;}
body #s4-workspace { overflow: visible !important; }
body #s4-ribbonrow { position: fixed; z-index: 1000; overflow-y:visible;}
#s4-ribbonrow .ms-MenuUIPopupBody, #s4-ribbonrow .ms-popoutMenu, .ms-cui-menu[id ^= "Ribbon."] { position: fixed !important; }
.ms-dlgOverlay { width: 100% !important; }