Tuesday, January 26, 2016

Custom Date Formats in SharePoint XSL

Custom Date Formats in SharePoint XSL

There are quite a few posts out there on this topic, but I’m yet to find one comprehensive post that walks through this beginning to end and actually works.  Let’s give it a go.

A very common scenario for SharePoint publishing sites is to customize the look to suit the customers needs.  Usually this is done with a Content Query Web Part and some custom XSL.  When doing this very often you need to display a date.  You will quickly notice that just displaying the date that SharePoint gives you is not going to be sufficient.  If you just did the standard

<xsl:value-of select="@ArticleStartDate"/>
You get back a pretty nasty looking result

2009-03-23 00:00:00

However if you use the “FormatDate” function, you can make this look a lot better.

<xsl:value-of select="ddwrt:FormatDate(@ArticleStartDate, 2057, 3)"/>

Results in this

23 March 2009

All you need to do to make sure the “FormatDate” function is available in your custom XSL files is to make sure you reference the ddwrt namespace.

Once this has been added to the rest of your namespace declarations at the top of your <xsl:stylesheet> tag, you should be able to use the “FormatDate” function anywhere you like.  Here is sample of what a full XSL file would look like that does this.

  exclude-result-prefixes="x d xsl msxsl cmswrt"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    <xsl:template name="Default" match="*" mode="itemstyle">
 <xsl:value-of select="ddwrt:FormatDate(@ArticleStartDate, 2057, 3)"/>   

Here are the details on the different formats you can get by changing the parameters.  March 23 12:00 AM was used as input for all outputs.

3/23/2009 12:00 AM10332
Monday, March 23 200910333
12:00 AM10334
Monday, March 23, 2009 12:00 AM10337
3/23/2009 12:00:00 AM103313
Monday, March 23, 2009 12:00:00 AM103315
3/23/2009 12:00 AM20572
23 March 200920573
23/03/2009 00:0020575
23 March 2009 00:0020577
23/03/2009 00:00:00205713
23 March 2009 00:00:00205715

You can also get a list of all the available locale’s here.

Hope this help,
Oumaima Achkari

Wednesday, January 6, 2016

Server Error: This file may not be moved, deleted or renamed or otherwise edited

How to: resolve ‘Server Error: This file may not be moved, deleted … ‘ when working with SharePoint master page

Does this error look familiar to you "Server error : This file may not be removed, deleted or renamed or otherwise edited"
Let’s see if I can guess what you’ve been up to.
You opened your site with SharePoint Designer or Master page gallery through SharePoint UI and copied an existing masterpage, say a copy of seattle.master, into the gallery; now you’re trying to rename it and above is the error you’re getting. So far so good? The read on …
SharePoint 2013 has an *.HTML file associated with each *.master and you’re really supposed to edit the *.HTML file and not touch the *.master. But if you created the *.master file by other means and try to rename, delete, or edit it’s properties, SharePoint will try to access the associated *.html file and there isn’t one …. and being SharePoint, you will get an error.
To solve this and get rid of the error, do this:
-Copy the existing *.html file in the gallery
-Rename the copied *.html file to the name you wish to give (or have already given) to your custom master page
-To delete the masterpage, delete respective *.html file instead, etc
That’s it, enjoy!
Oumaima Achkari

Clear Designer Cache

Clear Designer Cache

When using SharePoint Designer, especially in a development environment where content and assemblies can frequently change, SPD can start to behave erratically, sometimes loading content that has been removed from the web site, or using an older version of an assembly. This is due to how SPD caches content, which thankfully, is easy enough to clear.
First, close SPD and then remove all files from the following folder:
%APPDATA%\Microsoft\Web Server Extensions\Cache
This contains things like page caches.
Then, do the same for this folder:
This contains cached items such as assemblies used and lots of other xml configuration files.
Restart SPD and all should be good in the world :)

Hope this help,
Oumaima Achkari

Things to Note about Indexed Columns in SharePoint

Things to Note about Indexed Columns in SharePoint

Indexed Columns were introduced in SharePoint 2010 to help view Items from a Large Lists.
Large Lists are lists that contains more than 5000 items.
When a SharePoint list gets large, you might see warnings such as, “This list exceeds the list view threshold,” or “Displaying the newest results below.” When this is a case, it’s recommend to either Create a View with an Indexed Column(s) or simply let users access large lists during the daily window set by administrator (“Daily Time Window for Large Queries”) duration.
Daily Time Window for Large Queries effectively disables large list throttling (generally set to 5000) for that web application during that window.
In this post however, we will discuss few things to Note about Indexed Columns in SharePoint –
* You can Index up to 20 columns in a large list.
* You can Create two types of Index columns –
– Simple (Specify one Primary column for index)
– Compound (Specify one Primary and one Secondary Column for index).
* Any column that you define to have a unique value requires an index.So whenever you use a unique column in SharePoint 2010, make sure the Column is an Index column.
* When you use a view to display items from a large list, the first column that you specify in the filter of a view must be an Indexed Column.
* If you are filtering a list by an indexed field, check your recycle bin for deleted items.Items in the recycle bin aren’t actually deleted from the back-end database until they are removed from the recycle bin. If the total number of filtered items in the list and in the recycle bin is greater than the List Threshold limit, then you may get an incomplete set of results, or none at all.
* Because creating an index requires accessing all items in the list, it’s possible you may be blocked from creating an index Column if the entire list exceeds the List View Threshold.If this occurs, create an Index column during the daily window set for large queries by an administrators.
* An alternative way to access documents or items in a large library or list is by using search. Search has its own indexing mechanisms which you should not confuse with Index Columns that you can manually create on Large Lists or Libraries.
* If you use a CAML query to pull in the items from a Large list, make sure the column you use in FieldRef is a Index column.
* Each additional column index consumes extra resources in the database and adds some overhead to every operation to maintain the index. Therefore, you should add indexes only to columns that will be used actively for filtering in views on the list or library.
* Some SharePoint Server 2010 features add indexes when they are enabled. For example, SharePoint Server 2010 requires at least three index slots if you use the expiration and eDiscovery features. Consider keeping at least three index slots available in case you must create new indexes later.
* By default, the metadata navigation feature automatically creates single and compound indexes. From the metadata navigation settings page, you can disable this option. The metadata navigation feature automatically creates a single index for each supported column type and compound indexes for each supported combination of navigation hierarchies and key filters.
I will explain in the next article how to configure  "Daily Time Window for Large Queries".

Hope this help,
Oumaima Achkari

Tuesday, January 5, 2016

The number of items in this list exceeds the list view threshold, which is 5000 items

The number of items in this list exceeds the list view threshold, which is 5000 items

Isn’t SharePoint great for storing all your information? Tasks, Contacts, Documents, Issues, Customer Information, Invoices, a list of celebrities hacked cell phone pictures, the possibilities are pretty endless.
But what happens when you are cruising along, doing your job, enjoying life and you store that 5,001st item? Yep… things start breaking… and pretty spectacularly…  That list view that you had grouped by a field?
How about that filtered list view?
Dang it!!!
If I see “This view cannot be displayed because it exceeds the list view threshold (5000 items) enforced by the administrator.” one more time…
Oh!  I know.. I’ll just do a flat list view and then select a filter from the view itself:
hmmmmmmmmmmmmmmmmmm…. okay…  there’s got to be a way around this. I mean, SharePoint can store MILLIONS of items in a list. How in the world can I recommend this platform to a customer if they can’t effectively manipulate more than 5,000 rows of data?
Ah HA! I’m a developer by trade. Developers write code. Let’s take advantage of that awesome SharePoint 2013 REST interface to filter our list. 

What To Do

First of all, you should read the following link and put some planning and forethought into your list architecture:  Manage lists and libraries with many items
Microsoft has a lot of good advice in that article. I’ll break some of it down in my own language below if you don’t want to go and read it all. Still, go read it.
I should point out, if you have On-Premises SharePoint you can beg your Farm Admin with donuts and a cup off tea (Moroccan tea ;) ) to increase your list view threshold in Central Administration, however, keep in mind there is very good reasons to have a list view threshold as mentioned in the above referenced article that I’m sure you haven’t read yet. Anyway, to change the list view threshold, go into Central Administration under “Application Management.” Click on “Manage web applications”. Then select the Web Application you wish to adjust the list view threshold for and click on the “General Settings” button in the ribbon followed by “Resource Throttling”.
From here you can set several options concerning List View Thresholds. Again, you do not have the option of overriding the List View Threshold in Office 365 / SharePoint Online. Sorry.

But what do I do if I can’t change the list view threshold?

Excellent question. First of all, stop being so stubborn and go read Microsoft’s guidance about the issue.  From the article I take away the following main points.

Plan ahead

Some people like to punt on this issue and say things like “You shouldn’t be storing more than 5,000 items in a list” or “Just break it up into multiple lists.”. However, for those of us that live in the real world we understand that there are times when you need to store more than 5,000 things! I would argue that unless you can effectively work with more than 5,000 items, you are NOT dealing with a platform that should see the light of day in an enterprise environment.
It is critical to understand the limitations of the list view threshold, these will start to impact you in multiple locations in your site. Just a few common pieces of functionality that will break include:
  • List Views that Group By a field
  • List Views that Total or Sum fields
  • Lookup Fields that use lists with more than 5,000 rows
  • Filtering a list view (unless fields are indexed)
  • Accessing data with the Client Object Model or REST
Probably the biggest obstacle from the list above is if you use a lookup field to a list with more than 5,000 items. In this instance I could see a very valid point being made that you probably shouldn’t be doing a lookup to a list that has so many records. That won’t be very usable to your clients.  Even THEN there are some ways around that issue with a little bit of client side development.
So, plan. Plan your lists and fields. Identify those areas where you may have a need for more than 5,000 items. If it makes sense, place some retention polices around those lists to archive and delete old items. Keep your lists clean of junk. An ounce of of prevention is worth about a ton and a half of cure here folks. If you know you are going to have a list that will contain more than 5,000 items plan for how you will retrieve that data.

Use Indexes

You can index up to 20 fields in your SharePoint Lists and Libraries in SharePoint 2013.  If you have a list that has more than 5,000 items you CANNOT filter (using List Views or Web Services) on fields that have not been indexed.  That REST error I was getting before? I had not indexed the field I was filtering against.
And guess what? You can’t add an index to a field once the list has gone above 5,000 items! Take this into account too during your planning. Index those fields before it becomes an issue.  What if you already have this issue and need to index a field? You have two choices as I see it my friend. You can either delete enough items from your list so that you have fewer than 5,000 items and then index your fields, or create a new list, index those fields, and migrate your content to the new list.
Plan ahead.
After you index your fields, you can then create custom List Views where you filter on those indexed fields. You can even filter on “begins with” which allows you to do some more dynamic views. 
Keep i mond, plan ahead.
Hope thi help,
Oumaima Achkari #OumaimaSharepoint

Sharepoint Designer 2013, XSLT List View Options ribbon option is not showing

Sharepoint Designer 2013, XSLT List View Options ribbon option is not showing I have an ordinary Wiki Page, also tried making an Article...