Archive for the ‘SP2013 UI’ Category

I’ve been struggling for the past week to get some custom Access Denied, Signout, and Login pages implemented in our environment. There is a lot of agreement that Get-SPCustomLayoutsPage, Set-SPCustomLayoutsPage, and Microsoft.SharePoint.Administration.SPWebApplication.UpdateMappedPage() were great additions to SharePoint 2010, but there’s been quite the struggle getting these to work in SharePoint 2013.

The first question to ask is: Are you running the April 2013 CU or later? This is critical! There was a bug in earlier versions of SharePoint which made it so you could set a custom layouts page, but it wouldn’t use it. Be patient after you upgrade your farm, it took several days before ours finally started behaving itself after the CU (go ask the Computer Gods if you want to know why–I just thanked them when it finally worked.)

The next question to ask is: What UI is your site using? Is it using the 2010 UI or the 2013 UI? In many cases, you have upgraded your farm to SP2013, but haven’t upgraded your sites, yet.

As it turns out, the question about the UI is quite important. If your site is using the 2013 UI, you’re fine: By default Get-SPCustomLayoutsPage, Set-SPCustomLayoutsPage, and SPWebApplication.UpdateMappedPage(...) work with a CompatibilityLevel = 15. That’s right, CompatibilityLevel! There is an undocumented parameter on these cmdlets and method (presumably added with the April 2014 CU). If your site is using the 2010 UI, you’ll need to specify a CompatibilityLevel = 14 when using these cmdlets or method. Just be sure to give the correct path for the correct hive/UI: The path must start with “/_layouts/15/” for the 2013 UI (CompatibilityLevel = 15, or omitted), and must start with “/_layouts/” for the 2010 UI (CompatibilityLevel = 14).

Just be sure you deploy your custom pages to both hives. For me, I had packaged the custom pages in a farm solution. Just needed to deploy the pages to both hives by specifying CompatibilityLevel = All when executing Install-SPSolution. (Unfortunately, there’s no way to do this from the deployment in CA.)

Of course, this means you are able to have different pages for each of the mapped pages for each of the hives. Want one Access Denied page for the 2010 UI and a different one for the 2013 UI? No problem!


Read Full Post »

Radu Tut did a wonderful blog about how to get Search Analytics Reports programmatically in SharePoint 2013. I am quite grateful for his guidance and it’s undoubtedly the most referenced article on the topic (even being referenced in Microsoft blogs and other documentation).

I followed Radu’s guidance and have successfully retrieved usage data from my site collections in 2013, but I’ve discovered a few things I’ve not seen anyone talking about:

  1. It is important to note that the DateTime value you use should be UTC. If not, you will, at some time during the day–depending on your offset–get a “Specified argument was out of the range of valid values” error when trying to get the furthest back data (example: -14 days for Day) if you use Local time. Internally, SharePoint uses DateTime.UtcNow.Date (see reflection of Microsoft.Office.Server.Search.Analytics.AnalyticsItemData in the Microsoft.Office.Server.Search.Applications.dll).
  2. To my surprise, I was able to retrieve usage data from a 2010 site collection in SP2013! Apparently, SharePoint is tracking and compiling this data, but the 2010 UI has no way to interface with the data. Thus, if you need usage data for a 2010 UI site collection in SharePoint 2013, turn to your Devs or PowerShell-savvy Admins: If your site is being crawled, the 2013 usage data you seek is in there!
  3. The time period for SP2013 to compile usage data is fairly lengthy (at least 15 minutes in my tiny dev farm). If you attempt to retrieve the data while SharePoint is compiling it, you’ll get back a big fat ‘0’. For expected results, make sure you’re not retrieving the data while SharePoint is compiling it. 🙂 I believe this compilation is done by a timer job once a day at midnight, by default (I was up pretty late working on my project when I discovered this behavior).

Happy reporting!

Read Full Post »

Another day, another discovery on my quest to migrate our farm from SharePoint 2010 to SharePoint 2013. I started noticing image quality problems with the user thumbnail images in my upgraded farm: The small and large thumbnail images were looking very blurry. This was particularly evident when I viewed my My Site Host’s People page (MyPeople.aspx). The photo of myself on the left side was fairly blurry, but the small photos of the people I am following were nearly indistinguishable. Okay, what’s going on here?

Well, it turns out that Microsoft has changed the default thumbnail sizes for User Profile photos in SharePoint 2013. Here’s a comparison of the maximum dimensions (pixels) as given in Microsoft.Office.Server.UserProfiles.UserProfilePhotos:

Max pixels
Thumbnail SP2010 SP2013
Large 144 300
Medium 96 72
Small 32 48

As you can see, the dimensions for the large and small images have increased but has decreased for the medium image.

The new dimensions for the medium and small images isn’t much of a problem thanks to the handy dandy PowerShell cmdlet Update-SPProfilePhotoStore (read more at TechNet). The detailed description given in the TechNet reference still refers to 2007, but what this cmdlet does still apply to upgrades from 2010. By executing Update-SPProfilePhotoStore -MySiteHostCollection http://sppaule/my my thumbnail images were regenerated to match the default sizes desired by the system.

There’s still one gliche: SharePoint’s thumbnail image creation routine (found in Microsoft.Office.Server.UserProfiles.UserProfilePhotos) won’t enlarge images. (I’ve got a background in design and photography and can say with assurity that this is a good thing!) This means the large thumbnails stay at a maximum 144 pixels. Since they are displayed at 200 pixels, the image is thus enlarged by the browser by 38% causing bluriness. Unfortunately, unless you have a repository of higher resolution images of your users, you’re stuck.

This is where I think the new Image Renditions can come in quite handy. For more information about Image Renditions, I highly recommend MVP Waldek Mastykarz’s wonderful post “Image Renditions in SharePoint 2013.” If the User Profile Photos were to use Image Renditions, your originally uploaded file could be stored for use whenever the preset thumbnail sizes were inadequate. This would allow for a regeneration of the large thumbnail image should it’s default size increase again in the future. Not only that, but uploading a file could conceivably trigger a scaling-and-cropping UI similar to that used by Image Renditions (hopefully a little simpler) wherein the user uploading the photo could scale and crop the original photo right in the browser!

For SP2010, I gave our HR department a webpart which did allow them to scale and crop the original right in the browser (using Jcrop) and stored the original photo in another photo library. Now I’m just kicking myself for not storing the cropping information as properties/fields along with the original photo. Had I done so, I’d be able to programmatically regenerate the large thumbnail images at the new SharePoint 2013 largeThumbnailSize of 300 pixels and perhaps even implement something using Image Renditions. (Fortunately, my webpart actually saves the cropped image at full resolution. So, I only need to rescale the images programmatically in order to generate new large thumbnails for SharePoint 2013. Phew!)

One final note: Update-SPProfilePhotoStore has one other side benefit for which I’d like to give my gratitude to the Microsoft team who put it together! In our migration to SharePoint 2013, we are changing our web application’s default zone to a different domain name and moving the My Site Host under this web application (lots of work and not particularly recommended to have the My Site Host under the same web application, but it’s going to save our users–and thus me–a lot of headache). Thus, when the User Profile Service was upgraded from SharePoint 2010 to SharePoint 2013, all of the user’s profile photos were still pointing to the old domain name. Fortunately, the old farm was still running and accessible under the old domain name. Having not migrated the My Sites Host content (I wanted to start clean with a 2013 My Sites Host), I didn’t have the user photos in the new SP2013 farm. I ended up writing a console application which would copy the user photos I needed from the old farm to the new farm (hence my last post). Turns out, that wasn’t necessary. To my surprise–and the credit of the Microsoft team–Update-SPProfilePhotoStore retrieved the photo from the old farm using the URLs in the new farm’s user profiles, resized them (except for the large thumbnail as spoken of above), stored the sizes (144, 72, and 48) in the new farm, and updated the URL in the user profile to point to the new 2013 My Sites Host > User Photos > Profile Photos. SLICK!

So, despite the shift in default image sizes for User Photo thumbnails, there is a convenient way to update your thumbnails. If Microsoft were to integrate Image Renditions with the User Photos, the whole process will become much more robust for all SharePoint consumers. I’m crossing my fingers!


Read Full Post »

Warning: Fluffy explanation content ahead! If you want to skip the background info and get straight to the meat of this post, skip the next few paragraphs.

I would like to start this post by giving credit where credit is due. A few years ago, Mark Wilson wrote a blog post on how to use calculated fields to control the coloring of calendar items in the calendar view with some custom JavaScript (see SharePoint 2010 Colour Calendar post SP1 update). Without thinking too terribly much about how it was put together or worked, I put it into play with a solution that used event receivers to update a Single Line Text field to the values needed for Mark’s script (a Calculated field was too simple to meet the full business requirements). Worked beautifully!

Upon testing the solution in SharePoint 2013, I found it didn’t work. And, not just a little: Badly! No calendar events would show on the calendar and the ribbon would get stuck in “Loading…” So, I returned to Mark’s blog and was happy to find his update, SharePoint 2013 Colour Calendar. Reading through the comments, I was surprised to see a stream of people mentioning Mark’s script wasn’t working shortly followed by Mark’s “I fixed it” reply. Something was wrong here that needed a deeper look.

Turns out, Mark has been copying the code from Microsoft’s scripts and appending a line to execute his ColourCalendar function. That works just fine until Microsoft modifies their scripts–which is precisely what has been happening frequently in SharePoint Online (o365). Even his 2010 version of the scripts had to handle the pre- and post-SP1 releases differently. (No fault of Mark. The changes were just too drastic.) I, for one, wasn’t interested in getting into a “test and modify” loop every time I needed to deploy a Cumulative Update. Not only that, but the scripts Mark provides are UI specific. I wanted–and pretty much needed (see my last post)–one script that could handle the different UIs by itself and not be subject to continual necessary updates because of changes made by Microsoft.

There were two key elements to meeting my requirements to handle the UI versions and cumulative updates without troubles:

  1. _spPageContextInfo.webUIVersion: This allows us to test which UIVersion is being used by the page. Important when you consider that the DOM changes quite considerably with each UI version.
  2. Extending JavaScript functions without overwriting them: This allows us to insert our own function call without needing to copy the original function’s code. (My thanks to “xdazz” for the answer to this one on Stack Overflow.)

Integrating all of this together with the Module Pattern best practice gained from Scot Hillier’s SPC2012 session, “A Primer in HTML5 and JavaScript,” I came up with a new script that can be used in UI version 4 or 15 in SharePoint 2013.

Script source: DynamicCalendarColor.docx

To use the script source, download it and save the contents as text-only as ‘DynamicCalendarColor.js’ (you can use a different name, but be sure to modify the last line accordingly). From there, follow Mark’s rather well written instructions on SharePoint 2013 Colour Calendar. Be sure your page also loads the jQuery libraries! (I don’t include that in my script because jQuery is often used in many other solutions, as well. Don’t want to be loading it twice.)

There you go: You’re now a SharePoint Calendar Artiste!

Read Full Post »

This past week, I’ve been updating a custom solution to work in SharePoint 2013. Part of the feature modifies the out-of-box user interface using JavaScript. Only problem was: I needed different JavaScript for the different UI versions.

At first, I figured there should be some way to test the UIversion in the script and branch accrodingly, but I couldn’t find the UI version there.

So, I turned to the SharePoint:UIVersionedContent tag to control which JS file would load (one file for UI version 4 [SP2010] and one for UI version 15 [SP2013]). Unfortunately–as of the SP2013 March 2013 CU–the internal static method used to compare the versions (Microsoft.SharePoint.Utilities.SPUtility.UIVersionsAreCompatible(int, string), Microsoft.SharePoint, Version= will only accept version 3 or 4. Any other version numbers passed in throws an SPException with “Invalid UI string.” That knocked out most version control functions made available by Microsoft.SharePoint.dll (also affects ScriptLink.Register).

Finally, I found a workaround which turned out to be a better solution, overall (I’ll blog about that next).

It wasn’t until I was wrapping up a loose end on the new-and-improved solution that I was reviewing Scot Hillier’s SPC2012 session, “A Primer in HTML5 and JavaScript.” Within that session, Scot spoke of a little-used gem in the SharePoint JavaScript world: _spPageContextInfo. One of the variables available on _spPageContextInfo is webUIVersion. Bingo! But too late. Na ja!

In conclusion, if you need to know the UIVersion in JavaScript used for a SharePoint page, simply call:



Read Full Post »

Any of the following sound familiar?

  • I’m getting an error when viewing my calendar. The error says, “The Web application at [your URL] could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.”
  • My calendar view gives the error, “Unable to find specified web in the given URL – [URL].”
  • When I try to edit my calendar overlay, I get a “File Not Found.” error message.

You’ve probably become a victim of the Calendar Overlay’s propensity to use fully qualified URLs. You’ll likely notice when you see the first error I gave above that the domain name given in the URL does not match the domain name you are browsing the page from. Unfortunately, Calendar Overlay won’t take a relative URL. (From a development standpoint, this only makes sense when you consider that the developer short-cutted his/her code writing. Bad. Just bad. There’s plenty of people talking about this–people who have surely been listened to by Microsoft–but that’s not the point of this blog. So, moving on.)

If you’ve extended your SharePoint web application or changed your Default zone’s domain name at any time, you’ve likely become a victim of the Calendar Overlay fully qualified URLs.

Aside from the errors given above, how can I tell? Using SharePoint Management Shell, take a look at the CalendarSettings property of your views:

$w = Get-SPWeb [your site URL]
$l = $w.Lists["[your list name"]"]
$l.Views | ? { $_.CalendarSettings -ne $null } | % { $_.CalendarSettings }

CalendarSettings is a string object that contains a serialized object (i.e. the string is XML). Within that XML string is a WebUrl property like WebUrl="http://sppaule/Lists/Calendar/calendar.aspx". If the protocol and domain (ex: “http://sppaule”) don’t match the protocol and domain you browse from, you’ve got a problem (which is why you’re here reading this). From what I’ve read, both the protocol and domain must match.

“Okay, so they got me? Now what?” It’s really quite easy to fix. If you understood the PowerShell code above, you’ve probably got a really good idea of how to do it. Following is a script you can save to a .ps1 file and execute to update all the views across your entire web application. Just be patient when running it: there could be a lot of views to iterate through!

[bool]$do = $pscmdlet.ShouldProcess($currentWebApplicationURL);
if((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null){
  $ver = $host | select version
  if ($ver.Version.Major -gt 1) {$Host.Runspace.ThreadOptions = "ReuseThread"}
  Add-PsSnapin Microsoft.SharePoint.PowerShell
  Set-location $home
  write-host "Updating CalendarSettings..."
  $gc = Start-SPAssignment
  $views = $gc | get-spwebapplication $currentWebApplicationURL | get-spsite -limit all | get-spweb -limit all | % { $_.Lists | % { $_.Views | ? { $_.CalendarSettings -ne $null -and $_.CalendarSettings -like '*'+$oldWebApplicationURL+'*' } }}
  $views | % { $_.CalendarSettings = $_.CalendarSettings.Replace($oldWebApplicationURL, $currentWebApplicationURL); $_.Update() }
  write-host $views.Count "views updated.";
  Stop-SPAssignment -SemiGlobal $gc
} else {
  write-host "Operation cancelled."

(Notice I include the loading of the SharePoint snapin just in case the file gets executed from a regular PowerShell session or the Windows PowerShell ISE–which I like to use for writing and debugging scripts.)

I saved mine on my desktop as “Update-CalendarSettings.ps1”. Then, simply execute the script like the following:

PS C:\Users\sppaule\Desktop> Update-CalendarSettings.ps1 [currentWebAppUrl] [oldWebAppUrl]

Replace [currentWebAppUrl] with your web app’s Default zone URL (ex: “http://sppaule”) and [oldWebAppUrl] with the protocol and domain that is incorrect in the CalendarSettings (ex: “http://paule”).

Note: This will replace all occurences of [oldWebAppUrl] with [currentWebAppUrl] within your whole CalendarSettings. I couldn’t think of any case where this would be bad for us, but you may know of some for yourself. If so, be sure to modify the Replace(...) as necessary.

A few other tidbits of learning to consider:

  1. If you are using a Microsoft Forefront Unified Access Gateway, you may be saying, “Well, my browser protocol and/or domain don’t match what is in CalendarSettings. Why don’t I have a problem?” I wondered the exact same. It’s because Forefront UAG translates the protocol and domain for you. Your browser may show “https://extranet.sppaule.me”, but the request from UAG to the SharePoint farm is most likely something like “http://sppaule”. When SharePoint responds back, the UAG translates any “http://sppaule” URLs to “https://extranet.sppaule.me”.
  2. It wasn’t until researching this that I realized that ListViewWebPart views are actually stored on the SPList. They’re stored as Hidden views. Makes updating the CalendarSettings WebUrl paths across the board a lot easier.

Read Full Post »