Updating the Navigation Settings in a Publishing Site

I’ve got a brand that I’m activating via a Feature Receiver – it’s a theme and masterpage combination, and I want it to work on Team sites too, so it does actually make sense to do it this way!

Part of the brand is that the tabs have rounded corners, and these don’t work very well with the dynamic drop down menus. You can turn this off in the master page for the site pages, but not for the applications pages. Instead, I figured I’d use a feature receiver to turn off the ‘Show Subsites’ and ‘Show Pages’ in a publishing site.

So, the code I had was this:

if (PublishingWeb.IsPublishingWeb(site))
{
PublishingWeb pwSite = PublishingWeb.GetPublishingWeb(site);
site.Properties[ORIG_PUB_SITES] = pwSite.IncludeSubSitesInNavigation.ToString();
site.Properties[ORIG_PUB_PAGES] = pwSite.IncludePagesInNavigation.ToString();
site.Properties.Update();

pwSite.IncludePagesInNavigation = false;
pwSite.IncludeSubSitesInNavigation = false;
pwSite.Update();
pwSite.Close();
}

However, this didn’t work. To describe the code, first, we check to see if the page is a PublishingWeb. If it is, I record original settings in the site properties (so I can restore them when the feature is deactivated). I turn off those navigation check boxes, update the record on the server and close the object.

After much investigation, I realised that updating the properties was invalidating the PublishingWeb object, somehow, and that my changes weren’t being recorded. In the end I had to change my code to:

if (PublishingWeb.IsPublishingWeb(site))
{
PublishingWeb pwSite = PublishingWeb.GetPublishingWeb(site);
bool showPages = pwSite.IncludePagesInNavigation;
bool showSub = pwSite.IncludeSubSitesInNavigation;

pwSite.IncludePagesInNavigation = false;
pwSite.IncludeSubSitesInNavigation = false;
pwSite.Update();
pwSite.Close();

site.Properties[ORIG_PUB_SITES] = showPages.ToString() ;
site.Properties[ORIG_PUB_PAGES] = showSub.ToString() ;
site.Properties.Update();
}
This worked nicely!

Updating the Navigation Settings in a Publishing Site

So can you put Web Part Zones in Master Pages, or what?

A customer wants to put a web part zone below the quick nav in their SharePoint site – not an unusual request. Naturally, I cracked open SharePoint Designer, and tried adding a web part zone – and this is what I got:

I tried to understand why this would be the case, but quite simple, couldn’t. Naturally, I then referred to the documentation (!) on MSDN. It had mentioned this at the bottom of the page.

You cannot add Web Parts in zones to a master page. You can add static Web Parts (parts outside of a zone) to a master page, but you cannot add dynamic Web Parts to master pages.

Okay, that seems clear enough – I get why you could add static web parts to a master page, but not dynamic – but what about the web part zones themselves?

You can add zones to master pages and later add Web Parts to the zone in the browser, but the Web Parts are associated with the content page.

Yup, that seems fair enough. I get that in theory. So why in practice does SharePoint Designer say I can’t?

I began looking around to see if others had tried this – and found interesting contradictions. Mirjam says you can’t – but does point out that you can override the standard quick nav in your page layout, and put a web part zone into that. Microsoft SharePoint Step by Step seems to say the same thing. Yet ASP.NET would support this just fine, and as noted the MSDN docs say it should work.

Okay, one thing left to do – actually try it. SharePoint Designer won’t let me add the web part zone by ‘drag and drop’, but I can code one by hand:

And it renders in SharePoint Designer:

But when you try and use the page:

Well, I ain’t going to argue with a parser error – it looks like you really can’t do this, despite the MSDN docs.

So can you put Web Part Zones in Master Pages, or what?

Modify ListItem Display to show referencing items…

SharePoint is made up of lists of items, where an item is a set of data. Here is the standard display of an item’s properties:

As you can see, we’ve got a item, and it has some fields of data, and they’re being displayed inside a web part. Those fields are columns on the list:

All very familiar, I’m sure. It gets interesting when we start using Lookup columns, though. These are columns that refer to items in other lists. For example, this is a list of documents, but they refer to items in the above list (that’s what the Item Ref column is doing):

Cool, but wouldn’t it be great if I could show a list of items referring to a particular item on it’s display page? For example, in this case wouldn’t it be good to show a list of ‘Item Documents’ on the DispForm.aspx page used to show the Item’s properties? Well, you can:

(Edit: one of my colleagues points out that Microsoft did this in one of the Fab 40 templates – but I didn’t know).

So how does it work? Continue reading “Modify ListItem Display to show referencing items…”

Modify ListItem Display to show referencing items…

Adding a Custom View Style to MOSS 2007 or WSS3

Previously I’ve mentioned the intriguing idea of creating a custom view style for SharePoint 2007. Well, it turns out that instructions exist for how to do this in SharePoint 2003 – but I couldn’t find any for MOSS 2007 or WSS3. Well, it turns out that it’s not really that different, as far as I can see!

Continue reading “Adding a Custom View Style to MOSS 2007 or WSS3”

Adding a Custom View Style to MOSS 2007 or WSS3

RSA SecurID and SharePoint

I’d an interesting question from a customer the other day – they wanted Forms Authentication on extranet access to SharePoint, but using two factor authentication. The product mentioned was RSA SecurID, and this means that to authenticate yourself you need:

  • Your Username
  • A hardware device that shows a pseudo-randomly generated PIN number which changes every minute or so.

‘Cos the PIN is a pseudo-random sequence, if the token and a server are in sync, you can validate that someone has read that token inside the last minute. It’s an expensive technology – but neat!

The idea is the same as, say, a credit card. More than just saying who I am and that I have some piece of knowledge (e.g. my PIN number), I also have to have a physical object which is hard to duplicate (my credit card). This should make my identity more certain.

Anyway, how does this fit with SharePoint? Continue reading “RSA SecurID and SharePoint”

RSA SecurID and SharePoint

Forms Based Authentication User Management – bah!

SharePoint supports Forms Based Authentication. I suspect this isn’t news to anyone – if nothing else, I’ve posted about articles describing setting it up.

However, what SharePoint doesn’t do is give you a way of administering these users. In those articles about setting it up they all recommend using the Visual Studio ‘Configure Website’ tool. This works, but it isn’t pretty, and I wouldn’t want customers using it!

Now, it is a shame the SharePoint doesn’t have this facility – we’ve got the membership provider framework abstracting the actual storage of user details (SQL database? Active Directory? Flat file? Who cares? It all looks the same through the provider’s interface). Further, the membership provider interface gives you admin functions that you might want – like list, create, delete, update.

Thus, it seems to me that an obvious thing to provide is a user interface for administering the contents of that MembershipProvider. Sadly, it doesn’t. I suppose the problem is that a developer could extend the membership provider interface or something, but it is a pain. I figured that I can’t be the only person suffering this pain, so I decided to check on Codeplex.

(Don’t get me started on the performance of the codeplex site.)

The Community Kit for SharePoint has an FBA management, well, sub-project, I guess. I tried installing it, but soon found myself asking the same question as Wouter Van Vugt – what is the quality of this project? I mean, it installed okay, but I immediately got a NullReferenceException when I tried to use it. Looking into the code, I found some oddities too – like why is the list of users being filtered to those assigned rights to a site? Surely this should just be administered at the site collection level (well, technically, at the web-app level, but they’re usually the same thing)? That just seems an unnecessary complexity. And the Datasource control used for this lacks create, update and delete – so no clever Gridview usage.

There is also another codeplex project – Forms Base Authentication Tools and Utils for SharePoint 2007 – but it’s been in beta for over a year, and has very little activity, so I don’t know what the state of this is.

All of which, ultimately, brings me around to the idea that I’ll have to write my own (though I’m checking to see if Wouter started to do that, as he seems to have come to the same conclusion). And, actually, the crux of it isn’t a SharePoint thing – such a facility would be easy if there was a DataSource control that wrapped the MembershipProvider. I may just write a datasource to do this.

Forms Based Authentication User Management – bah!

Pages in SharePoint VI – Forms Pages

Forms pages are not really that different to normal pages, but are worth a mention. These are hidden pages inside lists and libraries, and they provide the forms for creating new (and editing existing) items. They exist in a hidden _forms folder in the list:

As you can see, the forms folder for this document library contains quite a number of forms pages! So what do they look like?

Looking in SharePoint Designer at the form page, we see a web part zone containing a web part – in this case the ListFormWebPart. So why is this interesting? Well, we could put our own web part here, should we wish to. For example, you might be recording longitude and latitude on a list item – but that isn’t very intuitive. Instead, we could write a web part to display a map, and use that to update the list item.

In short, they’re not pages I’d expect to edit often – but there is quite a lot you can do with them!

| Intro | Master Pages | Normal Pages | Publishing Pages | Application Pages | Forms Pages |

Pages in SharePoint VI – Forms Pages

Pages in SharePoint V – Application Pages

Application pages are a pain. They exist inside the _layouts directory, and are common to all the files across the farm. This makes them difficult to change, as such changes happen thoughout the system, not just one site or site collection. They’ve also got their own master page – and it’s difficult to change, which often you want to when branding a system. Essentially, you should try not to need a new master page (application pages can be modified by Themes, so that’s one way of branding them).

So what is an application page? Well, it’s a standard ASPX page. They’re usually for site administration type tasks, though there are a number of pages that users are likely to see regularly that are also application pages – such as file upload, the recycle bin and the “View all a site contents” page. Therefore, there is a problem – you can brand up your SharePoint Site, but if a user tries to upload a file they’ll drop out of that branded experience. For example, this example shows a SharePoint Site using a custom Master page (background window), but if you try to upload a document to that site you’ll see a standard upload page (foreground window). If you look in the URL for the upload page, you’ll notice it’s in the _layouts directory:

Like I say, you can change the style of this window through themes, but really that means just changing the colours – changing the structure of the page is much, much harder. Below is an example of changing the Site’s appearance through themes – you can see that this applies to the upload page too.

You shouldn’t change application pages themselves, as they are core to SharePoint and you won’t be supported by Microsoft – but you can add your own, should you want to present your own farm-wide administration pages.

| Intro | Master Pages | Normal Pages | Publishing Pages | Application Pages | Forms Pages |

Pages in SharePoint V – Application Pages

Pages in SharePoint IV – Publishing Pages

Publishing pages are specific to MOSS, as they require the publishing features! They’re not in WSS3! A good example of a publishing page is the default.aspx of a Collaboration site – that’s right, although the default page has the same name as for a team site, it is quite different:

Looks pretty much the same though, eh? That’s because it uses the same master page, but we’ll come to that in a bit.

These pages are are stored in a ‘Pages’ library (you can see this highlighted in the URL). They aren’t really like documents though; they’re much more like list items. Basically, these pages are collections of metadata columns. Different pages have different content types, such as the ‘Press Releases’ page type of the Publishing Portal site template. The other pages types that come out of the box are the ‘Article’ and ‘Welcome’ page types of a collaboration site.

These content types have different columns of data. For example, you might have a type of page for ‘Vacancies’, and that might have columns for position, salary, etc.. You might also have a type of page for ‘Products’ which might have columns for part number, cost, stock, etc..

Okay, so I’ve said that these pages are more like collections of metadata – how does this become a web page that you can see and read? Well, each page type has one or more page layouts. Lets have a look at one in SharePoint Designer:

These are kind of like master pages – they define the layout of our metadata columns in an aspx page. In the one shown above there are only 2 metadata columns, which I’ve highlighted – Page Image and Page Content.

Okay, but what about the master page stuff? Well, out page layout the content controls to go into our master page. Confused? It is confusing, so here is a diagram to show this:

Here you can see the page metadata being put into the page layout, which in turn puts content into the master page, which finally generates the output that gets sent to the user.

One advantage of this approach is that you can change between different page layouts for a given publishing page type – for example, you might have ‘Product page with image on left’ and ‘Product page with image on right’ layouts. Changing the page layout does not require editing any of the content.

| Intro | Master Pages | Normal Pages | Publishing Pages | Application Pages | Forms Pages |

Pages in SharePoint IV – Publishing Pages

Pages in SharePoint III – ‘Normal’ Pages

‘Normal’ pages are just ASPX pages. They usually (but don’t have to) use a master page, and we’ll consider them in that way. First let’s look at a good example – the Default.aspx of a Team Site.

The Homepage of a Team Site

Looking at this in SharePoint Designer we see the following:

On the left we see that our page just exists underneath our Team site – it isn’t in a Library or anything. On the right we see SharePoint Designer shows us the master page that the page uses at the top of the page, and what the page would look like. You can see the PlaceHolderMain placeholder is highlighted, and unlike the master page, this one has content. I’ve also circled where the PlaceHolderTitleBreadcrumb placeholder is, and this is now empty. So where did this content come from?

If an aspx page uses a master page then it says so in it’s code, and it defines a number of content controls. These content controls match up with the placeholder’s in the master page, and define the content to put in there. If we look at the code (don’t panic!):

Here we see the content being defined for the our PlaceHolderTitleBreadcrumb (the new content is ‘nothing’, and so our breadcrumb is effectively being erased), and our PlaceHolderMain (which contains lots of code for 2 web-part zones, etc.).

So, just to reiterate, a typical page in SharePoint defines content that is put into a master page. The process is something like this:

| Intro | Master Pages | Normal Pages | Publishing Pages | Application Pages | Forms Pages |

Pages in SharePoint III – ‘Normal’ Pages