Posts Tagged ‘Development’

Author: Tobias Zimmergren
http://www.zimmergren.net | http://www.tozit.com | @zimmergren

Introduction

In one of my previous articles where we investigated some of the new and awesome delegate controls in SharePoint 2013. It walks you through some of the interesting DelegateControl additions that I was playing around with. On top of that I got a comment about how you could extend it further by adding the current site title in the Suite bar:

image

Sure enough, I took a dive into the Seattle.master to take a look at how the title is rendered and found the control called SPTitleBreadcrumb. This is the control that is responsible for rendering the default out of the box title in a normal SharePoint team site like this:

image

So to follow the question through and provide an answer to get you started, we’ll take a quick look on how we can build further on our old sample from the previous blog post and add the site title (including or excluding breadcrumb-functionality) to the Suite bar.

Investigating the out of the box Seattle.master

In the OOTB Seattle.master, the title is rendered using the following code snippet:

<h1 id="pageTitle" class="ms-core-pageTitle">
  <SharePoint:AjaxDelta id="DeltaPlaceHolderPageTitleInTitleArea" runat="server">
    <asp:ContentPlaceHolder id="PlaceHolderPageTitleInTitleArea" runat="server">
      <SharePoint:SPTitleBreadcrumb
              runat="server"
              RenderCurrentNodeAsLink="true"
                  SiteMapProvider="SPContentMapProvider"
              CentralAdminSiteMapProvider="SPXmlAdminContentMapProvider">
        <PATHSEPARATORTEMPLATE>
          <SharePoint:ClusteredDirectionalSeparatorArrow runat="server" />
        </PATHSEPARATORTEMPLATE>
      </SharePoint:SPTitleBreadcrumb>
    </asp:ContentPlaceHolder>
  </SharePoint:AjaxDelta>
  <SharePoint:AjaxDelta BlockElement="true" id="DeltaPlaceHolderPageDescription" CssClass="ms-displayInlineBlock ms-normalWrap" runat="server">
    <a href="javascript:;" id="ms-pageDescriptionDiv" style="display:none;">
      <span id="ms-pageDescriptionImage">&#160;</span>
    </a>
    <span class="ms-accessible" id="ms-pageDescription">
      <asp:ContentPlaceHolder id="PlaceHolderPageDescription" runat="server" />
    </span>
    <SharePoint:ScriptBlock runat="server">
      _spBodyOnLoadFunctionNames.push("setupPageDescriptionCallout");
    </SharePoint:ScriptBlock>
  </SharePoint:AjaxDelta>
</h1>

What we can see in this file is that there’s a lot of action going on to simply render the title (or title + breadcrumb). You can play around with this in tons of ways, both server-side and client side. In this article we’ll take a look at how we can extend the Suite bar delegate control from my previous article in order to – using server side code – modify the title and breadcrumb and move it around a bit.

Should you want to get the title using jQuery or client side object models, that works fine too. But we can save that for another post.

Adding the Title Breadcrumb to the Suite bar

I’m going to make this short and easy. The very first thing you should do is head on over to my previous article “Some new DelegateControl additions to the SharePoint 2013 master pages” and take a look at the “SuiteBarBrandingDelegate Delegate Control” section and make sure you’ve got that covered.

Once you’ve setup like that, here’s some simple additional tweaks you can add to your Delegate Control in order for the breadcrumb to be displayed in the top row of SharePoint. Modify the content of the “SuiteBarBrandingDelegate.ascx.cx” (the file in my previous sample is named like that, in your case it may differ) to now look something like this:

protected void Page_Load(object sender, EventArgs e)
{
    // Register any custom CSS we may need to inject, unless we've added it previously through the masterpage or another delegate control...
    Controls.Add(new CssRegistration { Name = "/_layouts/15/Zimmergren.DelegateControls/Styles.css", ID = "CssReg_SuiteBarBrandingDelegate", After = "corev5.css" });

    BrandingTextControl.Controls.Add(new Literal
    {
        Text = string.Format("<a href='{0}'><img src='{1}' alt='{2}' /></a>",
            SPContext.Current.Site.Url,
            "/_layouts/15/images/Zimmergren.DelegateControls/tozit36light.png",
            SPContext.Current.Site.RootWeb.Title)
    });

    // Create a new Title Breadcrumb Control
    SPTitleBreadcrumb titleBc = new SPTitleBreadcrumb();
    titleBc.RenderCurrentNodeAsLink = true;
    titleBc.SiteMapProvider = "SPContentMapProvider";
    titleBc.CentralAdminSiteMapProvider = "SPXmlAdminContentMapProvider";
    titleBc.CssClass = "suitebar-titlebreadcrumb";
    titleBc.DefaultParentLevelsDisplayed = 5;

    // Add the Title Breadcrumb Control
    BrandingTextControl.Controls.Add(titleBc);
}

As an indication, the end-result might look something like this when you’re done. What we’ve done is simply copied the logic from the Seattle.master into the code behind file of our delegate control and set the “DefaultParentLevelsDisplayed” to a higher number than 0 so it’ll render the actual breadcrumb. By setting this value to 0, only the title will be displayed.

image

Then if you want to hide the default title, you can do that by using this small CSS snippet:

#pageTitle 
{
    display: none;
}

And it’s gone:

image

From there you should be able to take it onwards and upwards in term of the styling. I haven’t really put any effort into making it pretty here :-)

Summary

With these small additions and changes to my original code samples you can make the title bar, including or excluding the breadcrumb, appear in the top bar instead of in the default title-area.

Additional important comments:

You may need to consider ensuring that the Site Map datasource is available on every page, including system pages for example. If it isn’t or you land on a page that don’t want to render your breadcrumb/title, it may not be able to properly render your navigation as you would expect it to. However that’s something to look into further from that point.

For example, by default the “Site Content” link will not render the full breadcrumb properly, but rather just say “Home”. In order to fix smaller issues like that, we can further extend the code logic a few lines and take care of those bits.

My recommendation:

Always make sure you consider the approach you take for any type of customization and development. For this specific case, we’ve already used some code-behind to display our logo in the top left corner, so we’ve just built some additional sample code on top of that to render the breadcrumbs. However should we only want to do that and not move further onwards with the logic from here – I would most likely suggest you do this using jQuery/CSOM instead to be “Office 365 compliant” and keeping your customizations to a minimum.

Hope you enjoyed this small tweak. And keep in mind: Recommendations going forward (however hard it’ll be to conform to them) are to keep customizations to a minimum!

Cheers, Tob.

Author: Tobias Zimmergren
http://www.zimmergren.net | http://www.tozit.com | @zimmergren

Introduction

Recently someone asked me about how to attack the major pain of upgrading their custom coded projects and solution from SharePoint 2010 to SharePoint 2013. Given that question and my experiences thus far I’ll try to pinpoint the most important things to consider when upgrading. There’s TONS of things you need to consider, but we’ll touch on the most fundamental things to consider just to get up and running. After that I’m sure you’ll bump into a few more issues, and then you’re on your way ;-)

Keep your developer tools updated

Visual Studio 2012 Update 1

The first step is to make sure that you’re running the latest version of Visual Studio 2012. As of this writing that means you should be running Visual Studio 2012 and then apply the Visual Studio 2012 Update 1 pack (vsupdate_KB2707250.exe) if it isn’t installed on your system already.

Download Visual Studio 2012 Update 1 here: http://tz.nu/Y28FCd

Visual Studio 2012 Office Developer Tools

The second step is to make sure you’ve got the latest developer tools for SharePoint installed. The package comes as an update in the Web Platform Installer which I urge you to have installed on your dev-box if you for some reason don’t already have it installed.

So, launch the Web Platform Installer and make a quick search for “SharePoint” and you should see the new developer tools there (note that the release date is 2013-02-26, which is the release date for the RTM tools):

image

Select the “Microsoft Office Developer Tools for Visual Studio 2012” and click “Add“. It will ask you to install a bunch of prerequisites which you should accept if you want to continue:

image

Let the tools be installed and the components updated. This could take anywhere from a few seconds to a few Microsoft minutes. It took about 5 minutes on my current development environment, so that wasn’t too bad.

image

Once the tools are installed, you are ready to get going with your upgrade.

Open your projects/solutions after upgrading Visual Studio 2012 with the latest tools

When the tools have been successfully installed and you open your solution the new tools will be in effect. If you’re opening a SharePoint 2010 project that you wish to upgrade to SharePoint 2013, you’ll get a dialog saying “Do you want to upgrade <project name> to a SharePoint 2013 solution? Once the upgrade is complete, the solution can’t be deployed to SharePoint 2010. Do you want to continue?”

image

Hit Yes if you get this dialog. If you want to upgrade your project to SharePoint 2013.

Once the project is loaded and have made all the necessary changes to the project files (which it now does automatically, unlike in the beta/preview tools where we had to do some manual tweaks), you should get an upgrade report telling you how things went. Hopefully there’ll be no Errors, only warnings and Messages.

image

If you check out the assembly references in your project that are pointing to any SharePoint assemblies, note that they have automatically been updated to the correct version of the SharePoint 2013 assembly:

image

Additional notes

If you upgraded without the latest version of the developer tools you only had the option to launch your projects in 2013-mode if you manually went into the .csproj file to modify (or add if one of them were missing) the following two lines:

<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetOfficeVersion>15.0</TargetOfficeVersion>

This was true when the developer tools were in Preview/beta. But now when they’re released to RTM you shouldn’t be doing those manual hacks anymore. Trust the tools!

Tip: Some general code updates that may be required

When you deploy artifacts to the SharePointRoot folder in SharePoint 2013 they are now deployed to the /15 folder instead of the older /14 folder. SharePoint 2013 has a much better support for upgrade scenarios than previous versions of SharePoint (2010) which is why we’ve got the double hives. So, if you want to properly upgrade your solution you should also make sure to replace all the paths in your project from:

Path to the Images folder

From the images folder:

/_layouts/images/

To

/_layouts/15/images/

Path to the layouts folder

Make sure to not forget the general layouts path:

/_layouts/

To:

/_layouts/15/

Path to the ControlTemplates folder

Also make sure to replace the following paths:

/_controltemplates/

To:

/_controltemplates/15/

Well you get the general idea here.. Should you find paths pointing to your old 14-hive instead of the new 15-folder, make sure to change the path/url.

Tool-tip

As always, you will not be an efficient developer without the proper tools at hand to make the daily tasks easier.

If you enjoyed using CKS Dev for SharePoint 2010 development, you’ll still be able to enjoy some of that awesomeness by simply installing the CKS Dev tools for SharePoint 2010 on your Visual Studio 2012/SP2013 box. They seem to work fine on Visual Studio 2012 as well – so until there’s a proper update of the tools, you’ll be able to knacker some of your code with the old tools.

Do note that there’s certain features of the CKS Dev that doesn’t work fully, so should you encounter issues with the tool in various scenarios that’ll most likely be because they’re not engineered for Visual Studio 2012 (yet).

Deploy-time

After you’ve done enough tinkering you’ll be ready to rock this baby up on SharePoint 2013.

Enjoy!

Author: Tobias Zimmergren | www.tozit.com | @zimmergren

Introduction

Sometimes when you’re in a development project you can feel the pain of debugging. If there’s a lot of code floating around it may be hard to sort out the method calls and how the depend on each other if it’s a very complex solution. To ease the task of debugging there’s a great VS 2010 plugin called Debugger Canvas, which will help you to sort out a lot of the hassle while debugging.

In this article we’ll just take a quick look at what Debugger Canvas is and how it can assist us in our daily debugging adventures.

Getting Started with Debugger Canvas

Firstly, you obviously need to download the extension for Visual Studio 2010, which can be done HERE.

Please note: The Debugger Canvas Extensions are only available for VS 2010 Ultimate

Debugger Canvas in Action

When you’ve installed the extension, there’s a few new opportunities presented when debugging. Your new “F5” experience will be based on the new Debugger Canvas UI instead of the traditional debugging experience which means you’ll be able to more easily follow the calls within your code, like this:

image

When you step into the code deeper, you’ll see how the calls were made quite easily:

image

Summary

You should definitely take a look at Debugger Canvas if you haven’t already as it’ll be most helpful for you in your development adventures.

Get a better overview here and watch the introductory video!

Enjoy.

Author: Tobias Zimmergren
http://www.zimmergren.net | http://www.tozit.com | @zimmergren

Introduction

In most of my recent projects I’ve been required to hook up some custom functionality and add custom forms, pages and Web Parts. Some of the forms and pages I designed needed to be launched from the Ribbon menu, which of course is contextual. This basically means that when you visit a specific list which inherits from a specific content type, we can choose to display our custom Ribbon controls. One of the most common requirements I bumped into was having some kind of conditional check whether to enable or disable the button based on a set of conditions.

In your Ribbon XML for the CommandUIHandler there’s a property called “EnabledScript” which is a tag that enables you to enter a validation script to determine whether or not the ribbon button should be enabled. In my case I need to disable the custom Ribbon-controls if one item is selected, but otherwise always disable it.

Use the following snippet from the SP.ListOperation, which contains the Selection.getSelectedItems method:

<CommandUIHandler
Command=”Ribbon.Awesome.NavButton_CMD”
CommandAction=”javascript:Alert(‘My Awesome Button Was Clicked’);
          EnabledScript=”javascript:SP.ListOperation.Selection.getSelectedItems().length == 1;” />

It’s really only the last line that is of interest here since that’s where the script magic happens to determine if the control should be enabled or not.

MSDN have some nice samples in one of their articles over here.

Results

If you select one (and only one) item in the list, your custom command will be enabled:

image

If you didn’t select or selected more than one item, the command will be disabled as such:

imageimage

Summary

I know many people have been struggling with the Ribbon and making it behave. In this article I simply wanted to highlight one of the very common tasks I’ve seen developers looking for and trying to achieve in some of the last few projects I’ve been involved.

Since my awesome mate Wictor covered a bunch of awesome posts about the Ribbon, I’m not going to dive into any more details than so :-)

Enjoy.