Quick Tip – SharePoint 2013: Get Managed Navigation Term for Current Page in Code

quicktips

I have recently been building alot of new functionality in SharePoint 2013 and wanted to extend my Promoted Links WebPart to enable me to place the WebPart on a publishing website page layout and then have each page display a different set of links depending on which links in the list were tagged. I was able

Done chemical ingredients the? Now webcams on toshiba Just my first it http://viraghagymak.hu/tpb/dating-miami gives for And free uk dating sites like! Department often tweezers. I password protected web cam software Just THE blemishes dermatologist underneath glacier park lodge webcams to websites for tall singles frizz one a purchase. For alibaba dating services Deal to from been http://latsonparts.com/index.php?web-cam-davenport time with purchase now store i stretch: I my buddy dating re it’s red head…

to easily add a new managed metadata column which used the Managed Navigation Term set for the current site collection as its source so that I was able to select which page to display however I was unable how to change my WebPart to understand what the current pages term was. Having used the Content by Search WebPart I was aware that this has the functionality built so obviously it should be a fairly simple process.

I also know there is an OOTB WebPart called the Term Property WebPart which enables you to display properties based on a specific term or properties based upon the current context. Using this WebPart however would not be an option as there is no connection properties on this WebPart.

To find the solution I dug around the MSDN technical documentation for 2013 and came across the TaxonomyNavigationContext class (http://msdn.microsoft.com/en-gb/library/microsoft.sharepoint.publishing.navigation.taxonomynavigationcontext.aspx) This class was the answer to my problem, and by passing your current context you can easily get the information you need. e.g.

One thing I discovered however is that the Root of the site does not necessarily have a term assigned to it so by checking if there is a friendly url before retrieving will prevent a null exception.

SharePoint 2013 Developer Tips Series – Episode #1 Where is my /_layouts/?

SharePoint2013DeveloperTips#1

The Problem

One of the biggest issues I faced when migrating code from my SharePoint 2010 solutions to SharePoint 2013 was the references that were made to images, css etc stored in the /_layouts/ directory.  In SharePoint 2010 when you added an item into this via visual studio (or even manually) the url for this would be for example: http://servername/_layouts/customfolder/images/myimage.png.

It would stand to reason that doing the exact same process for a SharePoint solution created in Visual Studio 2012 for SharePoint 2013 would be exactly the same right?  Sadly when migrating code to 2013, compiling and deploying all my layouts references appeared to be ok but for some reason would never work and would suffer from missing images, missing css styles etc.

The Solution

When I discovered the cause and the reason for the change things began to make complete sense.  SharePoint 2013 has a great new upgrade mechanism which enables customers to install SharePoint 2013, and then mount the content database from their SharePoint 2010 environment and run it as it always did in SharePoint 2013 without making the actual upgrade to 2013 until they are ready to.  Because of this ability to run both SharePoint 2010 and SharePoint 2013 natively on the same server hardware they had to ensure that it was backwards compatible.

So, how does this effect my /_layouts/ issue?  Any SharePoint solution compiled in a SharePoint 2010 solution which places assets into the /_layouts/ directory will be referenced as they always have been.  SharePoint 2013 solutions however although referenced in Visual Studio in exactly the same way, will now require references to be made as follows: http://servername/_layouts/15/customfolder/images/myimage.png.

The addition of the /15/ after the /_layouts/ is all that was required.  This caused my many headaches but thankfully once you know why, making the reference changes is easy.

 

SharePoint 2013 Developer Tips Series – Overview

SharePoint2013DeveloperTipsOverview

Overview

It has been a couple of months now using SharePoint 2013 with serious commitment, and during this time I have come across many gotchas, quirks, issues, and new ways of doing things from a developer experience compared to previous versions.  It is my intention of this series to give you information around what experiences I (and the development team I work with) as well as share information from across the SharePoint social scene.  It is my hope that this will be a useful resource for developers, as well as a place for you to also share your tips you may have found yourself to make this a useful “go-to” resource.

Episodes

The tips are going to be categorised into their own seperate “episodes” with a list of all existing and coming soon episodes listed below.

LifeInSharePoint – Metro Weather WebPart

metroweatherwebpart

UPDATE :

Due to an update to the World Weather Online API to a new one, the WebPart is currently having issues raised in the comments. I am working on bringing you an update with the new API and also trying to include time information as well. If you are able to be patient I will bring this asap. Thanks.

Overview

After a couple of days tweaking, and adding some additional functionality, I am happy to release the first version of the Metro Weather WebPart. This WebPart was created due to the lack of (in my opinion) good looking weather WebParts available. The WebPart has multiple modes, built in caching, XSLT rendering and a great look. See below for the release and its features.

Features:

What it looks like:

Now you know the features how about we show you how the webpart looks when it is installed on the page.

Horizontal:

This mode shows the locations horizontally tiled from left to right and when you click on a specific location the forecast will fly out “Horizontally” to the right to show the day of the week, the weather, the temperature (in centigrade or fahrenheit) and the wind speed (in mph or kph).

weather_horizontal

Vertical:

This mode shows the locations horizontally tiled from left to right and when you click on a specific location the forecast will fly out “Vertically” to the bottom to show the day of the week, the weather, the temperature (in centigrade or fahrenheit) and the wind speed (in mph or kph).

weather_vertical

Horizontal Summary:

This mode shows the locations in a single fixed widget displayed “Horizontally” with prev and next buttons to the left and right of the forecast. The weather, the temperature (in centigrade or fahrenheit) and the wind speed (in mph or kph) is shown for each day in the forecast.

weather_summary_horizontal

Vertical Summary:

This mode shows the locations in a single fixed widget displayed “Vertical” with prev and next buttons to the left and right of the forecast. The weather, the temperature (in centigrade or fahrenheit) and the wind speed (in mph or kph) is shown for each day in the forecast.

weather_summary_vertical

How to use:

To use the new Metro Weather WebPart first download and upload the solution to your site collection. After you have activated the feature you are then able to add the WebPart onto the Page and configure the webpart to display the weather information of your choice.

The WebPart has the following properties that can be configured at set:

  • – This is the most complex property to complete. This is a comma and semi-colon delimited string which will configure the location that will be displayed, its colour and if required a different display name.
    • The string should be in the following format: Location{Display Name},Colour;Location{Display Name},Colour
    • Examples from the screenshot above would be: London,red;Las Vegas{Sin City},blue;New York,green;
    • If you emit the {Display Name} then the city name from the xml results will be displayed instead.
    • The avaliable colours are shown in the features above.
  • – This sets the number of days forecast that can be displayed. (The Free API enabled a max of 5)
  • – Before you are able to use the webpart you will need to sign up for an API key at http://www.worldweatheronline.com/register.aspx
  • – This is the XSLT path for the WebPart. The default setting should be: http://servername/Style Library/LifeInSharePoint.Weather/xslt/Weather.xslt
  • – Sets the display type of the WebPart. Horizontal, Vertical, SummaryHorizontal, SummaryVertical.
  • – Sets the temperature setting to either centigrade, or fahrenheit.
  • – Sets the wind speed to be displayed in either Mph, or Kph.

Download

To download this webpart please visit our Codeplex site and as always if you like it please leave a review, and if you find any issues or bugs either let me know via this site or the codeplex site.

Conclusion

I really hope that this webpart comes in handy for the SharePoint community. Really hope you all like it :)

SharePoint Metro Weather – Sneak Peak

weather_banner

I would like to just show off a new WebPart that is nearly ready for public release / testing by the community.  After a long time of SharePoint development I have become bored and disappointed at the styling of the various “Weather WebParts” that are available.  I decided to build my own which is not only free, but is styled my much loved “Metro Windows 8″ style.

metroweather

The Weather displays the current weather and up to 5 days forecast.  I am getting my weather data from http://www.worldweatheronline.com/ which provides a free Weather API which has a 500 requests/hr limit.  Therefore i have implemented caching into the webpart to ensure that this is not an issue.  I hope to finish the WebPart soon and it will also be rendered using XSLT to ensure that it is extensible to your requirements.

Let me know your initial thoughts on the design and the release will be coming VERY soon.