Posts Tagged ‘contenttype’

Updating declarative XML content types

Thursday, September 15th, 2011

Becoming a SharePoint developer is always a journey – every new day you spend doing something, the more you learn. More often than not, the more “little subtleties” you uncover about the great wide SharePoint platform. I recently tripped over one such example. This “issue” is not new in SharePoint development – it certainly goes back as far as MOSS2007, but unless you’re actually doing it, it’s not something you’d instinctively just know.

Creating content types via XML Visual Studio

As soon as you start building SharePoint solutions of any real size and complexity, you’ll quickly learn that creating fields and content types via the UI, or SharePoint Designer, is not a great solution. For instance, there’s no supported way to move a SPD designed solution from e.g., Dev to Live – that is, with SPD, you design directly against live. This can be OK for initial deployments, but as soon as the system has data in and you need to start potentially breaking things, this is not a good place to be in. The alternative to this is develop Visual Studio solutions and features, which are deployable pretty much wherever you’d like. You can define fields and content types in XML, and when you’re finished, package it all up and deploy. Simple, right? Well, no, not necessarily – as I mentioned recently, this process is not without its bugs and issues.

I’ve deployed a few solutions in this way, and was (until today) singing the praises of deploying content types via XML, thinking how wonderful it was to have the flexibility to build in dev, test and then deploy (i.e. what you can’t do with SPD). And of course, if you make any changes, you can update your solution and hey presto, nice neat update.
(more…)

Error occurred in deployment step ‘Activate Features’: Invalid field name.

Monday, September 12th, 2011

I posted about an issue I had been facing with deploying document sets via XML, where things like the custom welcome page and the shared fields (defined in XmlDocuments) wasn’t showing up.

Here’s a further issue I encountered. I defined my Document Set content type in the usual way. A bunch of Site Fields, then the Content Type definition, and then within the FieldRefs section some FieldRef elements for the fields to use.

At some point, I started to experience a strange error – when I was deploying the solution, I would get an error:

Error occurred in deployment step ‘Activate Features’: Invalid field name.

After a bit of research, things pointed to the fact that this error was caused by not declaring a Name attribute in the FieldRef. And adding a Name in to the FieldRef resolved the problem. However, I had another solution, doing the same thing, which would deploy successfully, but didn’t specify the Name attribute!

After some trial and error, I narrowed it down to the Overwrite attribute of the content type declaration. According to MSDN:

Optional Boolean. TRUE to overwrite an existing content type with the same ID.
The default is FALSE.

I’d set this to true, for obvious reasons. If you remove the attribute, then FieldRef with no Name attribute deploy successfully. And the existing content type is overwritten as well!

Yet another bug/feature/futureproof attribute (like Version, it seems) that displays inconsistent behaviour and can cause lots of issues! Well worth getting used to the ContentType and Field schemas, and I’d suggest using the bare minimum of attributes required.