Navigation

Wednesday, 3 December 2008

Joining Content & Code as a Solutions Architect! (on Monday)

Ok .. so here is another reason why my posts have been few & far between recently .. yep ... I'm moving on to pastures new, and Friday is my last day at Ratio One!

Thankfully I have not succumb to the dreaded "credit crunch" but have decided to take a fantastic opportunity to join the Solutions Team at Content & Code as one of their Solution Architects, helping to design and scope solutions, aiding the consultants and developers in their technical delivery, drive best practice in the business and also try to get more involved in the SharePoint Community.

What does this mean? Well, I will still be making the same blog posts, and be just as active on the MSDN forums (if not more so!). It also means you'll be seeing a bit more of me at the User Groups and community events around London (and possibly elsewhere in Europe?).

I would also like to take this opportunity to both thank Content & Code for this great opportunity, and also to thank Ratio One for their support over the past 2 (and a bit) years. I've certainly come on a long way since my first forays into SharePoint, and (generally) loved every minute of it!



Tuesday, 2 December 2008

Creating "External" URLs in the Quick Launch menu

This post was prompted by the problems I've been having trying to get header nodes to be added to a site when it is provisioned, which have a custom URL pointing at a different site in the site collection.

Despite the NavBar element in the onet.xml having a URL attribute, this had no effect on my quick launch and it was always created using the current web's URL (i.e. on click it just took me straight to the current web site home page).

So, I embarked on a simple feature which I could use to create those navigation headers.

The code is pretty simple:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            // get the current "Web" object
            using (SPWeb web = (SPWeb)properties.Feature.Parent)
            {
                    // create the new navigation node
                    SPNavigationNode newNode =
                        new SPNavigationNode("Go to any sub site", "/anysite/anysubsite", true);

                    // add the node to the quicklaunch menu
                    web.Navigation.QuickLaunch.AddAsLast(newNode);

                    // save the changes
                    newNode.Update();
            }
        }

Now, the main thing to note is that when you create your SPNavigationNode object to use the true argument in the constructor!

This tells SharePoint that the URL is an External URL (and by External .. I mean "not in the current web"). If you don't set this then you will get an error telling you that the URL is invalid, or that the page/file cannot be found.

Even if the URL is a relative URL to the same site collection, you still have to set this value to true! Not entirely obvious that one, so one to watch out for.



Sad news ...

Sorry that my activity in the past week has been a bit poor ... but my mother-in-law died last week. I've basically been buried in the subsequent activities (funeral directors, coroner, registrar, church, etc) which was made much harder because my father-in-law is deaf and cannot use the telephone.

Funeral on Thursday .. hopefully be back to my old self by the weekend.



Saturday, 8 November 2008

New (Old) Car !!

Yay ... I just bought me a new (old) car ..
Been needing a second car for a while (the Mrs always nicks my main car to drive to work everyday) and been needing a run-about to take rubbish to the tip and to get me to the train station and back :)

So .. got myself a nice little Ford Fiesta .. 1.3 engine, ABS, Power Steering, new CD player ... and only 70,000 miles on the clock (despite being over 10 years old). Not bad for only £700 (at least I think so). Very pleased with it :)

Thursday, 30 October 2008

Adding FAVICONS to SharePoint

Ok .. I admit it .. this isn't really just a SharePoint thing, it's a "web" thing, but quite frankly I am astounded that this isn't something provided out of the box.

So what are these favicon things anyway?

Favicons are the icons that appear in your web browser when you are surfing. They usually appear in the address bar (depending on your browser) and were originally created for older IE environments to help identify web sites in the Favourites folder (hence the name "favicon" = "favourites icon").

example favicons

Ok, thats great, so how do I get them in SharePoint?

Well, it's really quite simple. Favicons are represented by small "link" tags in your HTML. In SharePoint the most sensible place to put them is in the Master Page. The reason for this is that (generally) your Master Page is rendered for pretty much every page .. therefore you don't have to add favicon links all over the place.

All you need to do is put a "link" tag into your Master Page, within the "<head>" tags (i.e. it needs to be in the page header!)

<link rel="shortcut icon" href="/Portal Images/favicon.jpg" />

How to "SharePoint'ise" it!

I know, that's not a real word, but the best approach you can take is to place your icon image (either an icon or image file) into an Image Library. You can then place a relative URL to a specific image in that image library, and it allows the content editors to upload a new favicon whenever they want :) (with the same version control and content approval you would normally have).

Thats exactly what I did with the sample line of code above, with a file called "favicon.jpg" which is located in an Image Library called "Portal Images" at the top level of the site collection.

Now, if you want to get REALLY fancy, then you could change it to be relative to the Site Collection (so each site collection could potentially have a different favicon). Do you that, just follow my earlier post on creating "Site Collection Relative URLs in MOSS 2007".

Neat eh?



Wednesday, 29 October 2008

Word, Excel and PowerPoint running from the browser .. it must be Office 14 for Web

This is a great "first look" video from Channel9 (http://channel9.msdn.com/posts/PDCNews/First-Look-Office-14-for-Web/) showing off the new browser based features of the Office 14 for web (still in beta, still in development!) at this weeks PDC!

It's hot off the press, and it's going to blow your socks off!

According to the video they have made heavy use of Silverlight and AJAX to create rich office clients that run through a web browser. Due to the user of Silverlight the rendering is crisp and detailed, and to be honest I couldn't tell the difference between the web version and the desktop client!

Multi-User editing (including from the browser!) allowing multiple users to edit the same document at the same time is demo'd, including talk about integrating better collaboration tools!

To get you even more excited, the web browser based application is demo'd from FireFox! That's right, the new Office 14 apps are being designed with complete and total cross-browser compatibility.

Excited about the next version of Office?? (i.e. SharePoint!!!) I am!



Thursday, 23 October 2008

Blank "Web File Properties" when saving document from Word 2003

This is a problem that I encountered with a MOSS 2007 system that was upgraded from SPS 2003.

Specifically, we were developing a custom document library, and found that if we had libraries with multiple content types, when we tried to save documents from Microsoft Word 2003 the "Web File Properties" dialog (the pop-up window that asks you for metadata before the file hits the document library) was completely empty.

None of the fields were visible, not even the Content Type drop-down box!

Well, It seems that this problem is documented and known about, and there is a Microsoft Hotfix available (upon request).

(KB934253) The Web File Properties dialog box displays incorrect properties for a document that is saved in a Windows SharePoint Services 3.0 document library - http://support.microsoft.com/default.aspx?scid=kb;EN-US;934253

The solution to the issue above has been included in to a hotfix, which you can get the information from the following KB article:

(KB934790) Description of the Windows SharePoint Services 3.0 hotfix package: April 12, 2007 - http://support.microsoft.com/default.aspx?scid=kb;EN-US;934790

*files this one away for later*



Wednesday, 22 October 2008

Medals in the MSDN Forums .. what do they mean?

If you are a regular user of the MSDN Forums then you may (or may not?) that each user is granted a number of "medals" (they used to be stars, for the old timers).
Well, I've taken a sneak peak through the members list, and deduced that medals = points.
 
Exactly how many points you have depend on a lot of things, including posts, answers, "helpful" tags and how "popular" your threads are.
 
I have got the following list though:
  • 0 Medals - 0 points (1 or 2 posts)
  • 1 Medal - 10 points (usually 1-5 posts)
  • 2 Medals - 750 points (roughly 30 "answers")
  • 3 Medals - 2,000 points (roughly 150 "answers")
  • 4 Medals - 7,500 points (roughly 300 - 500 answers)
  • 5 Medals - 50,000 points (roughly 1000 answers)

To find your own account (and how many "points" you have) you can use the search page.



Number of certified SharePoint Developers increase by 500% in 12 months ...

So demand slowly catches up with the market. Despite the credit crunch, and supposed "global economic recession", the SharePoint markets (and IT in general) continue to buck the trend.
 
 
There are now 2,360 MCTS WSS 3.0 Application Developers in the world. Last time I checked (about this time last year) there was less than 450! Not bad growth, I think.


The onet.xml order of execution (shown in 8 easy steps)

This post was prompted by a post in the MSDN Forums. Simply put … what order do things happen in the onet.xml?

This may seem like a trivial question .. but if you are writing custom features, it is important (to say vital) that you know whether or not your feature will activate before a list is created or after, or whether or not your files in modules will have been provisioned or not.

The order that I discovered is as follows:

  1. *<SiteFeatures> in onet.xml
  2. *Stapled Site Features (stapled using FeatureSiteTemplateAssociation)
  3. <WebFeature> in onet.xml
  4. Stapled Web Features (using FeatureSiteTemplateAssociation)
  5. <Lists> in onet.xml
  6. <Modules> in onet.xml

* note - obviously Site Features will only activate if you are creating a Site Collection, as opposed to a normal web site

How I worked this out

Well, you can copy the steps yourself, in 8 easy steps:

First off, create a new Custom Site Definition (a simple copy of STS). In my example, I called it MHSTS with a single configuration (#0) and created a WEBTEMP file to register it.

Second, create a new SPFeatureEventReceiver class (in an assembly from a class library). The code in the "FeatureActivated" should be something like this:

 
// this will let you check which feature is being activated .. so you can work out the order
string strFeature = properties.Definition.DisplayName;
 
// Add more code to check the SPWeb.Features, SPSite.Features, SPWeb.Lists and SPWeb.Files …
// this will tell you what has been created in the site, and what other features have been activated

Third, create 5 features (the scope is in [ ])

  • mhOnetSiteFeature [Site]
  • mhStapledSiteFeature [Site]
  • mhOnetWebFeature [WEB]
  • mhStapledWebFeature [WEB
  • mhManualWebFeature [WEB]

Each of these needs to be attached to the same SPFeatureEventReceiver class that we referenced earlier. This allows your debugger to work out which feature is activating … so each time your code steps into breakpoints, you can check the "Feature.Definition" properties and work out which feature is being activated.

Fourth step, create 2 more features which will act as Feature Staplers (using FeatureSiteTemplateAssociation elements).

  • mhWebStapler [Site]
    • Staples the mhStapledWebFeature to the MHSTS#0 template (when used to create a new Site or Site Collection).
  • mhSiteStapler [WebApplication]
    • Staples the mhStapledSiteFeature to the MHSTS#0 template (when used to create a Site Collection)

Fifth.. in your custom site definition (MHSTS) add the following features into the onet.xml:

  • <SiteFeatures>
    • mhOnetSiteFeature
    • mhWebStapler
  • <WebFeatures>
    • mhOnetWebFeature

Sixth; Install all of the features using STSADM, and (in Central Administration) activate the "mhSiteStapler" feature within a test Web Application.

Seventh; Within that Web Application, create a new Site Collection using your new site definition (MHSTS). This should fire off all of your features in the following order;

  1. mhOnetSiteFeature
  2. mhStapledSiteFeature
  3. mhOnetWebFeature
  4. mhStapledWebFeature

(you can check this by debugging your event handler, and setting a watch on the properties.Definition.DisplayName value)

Now .. if you are keeping a close eye on your debugging window, then you can also start to look at the state of the SPWeb itself. The main thing is that None of the Lists or pages will have been created … at ANY point in this process. This means that <Lists> and <Modules> will not be executed until ALL of your features have activated.

Eighth; Now you can double-check the theory … navigate to your new Site Collection .. and activate your remaining feature manually (mhManualWebFeature).

You should still have your debugging window open .. which should let you know that now (after the site is provisioned) all of the Lists and web pages are now accessible from Code.

Ok .. that's great … errrr … so What ??

Well, this has quite a lot of importance for writing custom features. If you want to write features which automatically manipulate pages and lists then you are going to be a bit stuck, as the lists and pages won't have been created until after your feature activates! (bummer eh? But what you gonna do?)

To get around this problem you really have 2 options:

  1. Make your own custom definition. Strip the lists out of the onet.xml, and create ListInstance Features. These can then be created during the feature activation stage, allowing them to be modified by other features that are being activated / stapled.
  2. Put some While Loops with Thread.Sleep() statements in your code, basically waiting until the lists have been created. This is not a very elegant solution but you don't have much choice if you are trying to use staplers to modify out of the box definitions (or if you don't want to touch the onet.xml).

Thats it ... comments welcome as always :)