More fun with deploying Document Sets via XML

To finish a set of posts about the fun I’ve had in deploying document sets as XML content types, here’s a fun little bug vagary I encountered. In the video walkthrough, there’s a section on deploying the custom WelcomePage to your site, and provisioning some WebParts automatically to that page.

You achieve this in the Elements.xml file of your WelcomePage module by including some > sections. Within those tags, you enter the definition of the webpart, and you can reuse the built-in webparts.

(Hint: to get at the required definition for built-in SP webparts, find the webpart in the Webparts Gallery in Site Settings, save a copy of the file to your hard drive (as a .dwp file) and then open that file in Visual Studio. You get the required info. Neat.)

You can then deploy your feature, and assuming you’ve covered all the bases your Document Sets, with custom Welcome Page should be deployed. But here’s a problem. Let’s say you make some changes to it, and redeploy the feature. You may experience one of a series of behaviours:

  1. None of your changes are displayed
  2. Your changes are displayed OK
  3. You end up with multiple webparts on your custom Welcome Page.

It’s the third issue I tripped over, and it seems to occur if/when you manually deactivate and reactivate your feature (using the “deploy” feature from VS doesn’t seem to cause this.) It makes some sense - the Elements.xml file says “add these webparts to this page”. Assuming you’ve not added any FeatureDeactivating event receiver to remove the webparts when the feature is deactivated, well, you’ll end up with lots of webparts on the one page.

This being the case, how do you actually go about getting rid of the extra webparts on the page? Retracting the solution doesn’t help. You could completely bin your site content type, site or even site collection. That would probably do it. But it’s a bit drastic. The alternative? Update the database manually. You can decide if this is more drastic than the previous options.

To be clear, you should never, ever, on any account, ever, manually hack the SharePoint content database!

But if you want to do it, here’s how:

Read more

Updating declarative XML content types

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.

Read more

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

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:

Read more

Provision Document Set + XMLDocuments and ???

SharePoint development is fraught with frustrations. Little things that should be simple, end up taking far longer than they should. Take this example. I’m trying to provision a Document Set content type via XML in a VS feature. I was using this video and the supporting article as a guide. I get all the way through, and everything is working… ish. That is, the Document Set content type is created, but the extra stuff to do with it, such as the custom welcome page and the extra properties (shared fields, etc.), defined in the XmlDocuments section of the content type, don’t appear. No manner of tweaking and reducing code had any effect. I got a hold of the source code from the tutorial - lo and behold, that works fine. So the theory is sound, it should work, and so something somewhere was different. The job was tracking down said difference.

Read more

the specified value for the locstringid parameter is outside the bounds of this enum

This was a rarity. SharePoint 2010 threw up the error, whilst trying to create a new Web Application:

The error was:

the specified value for the locstringid parameter is outside the bounds of this enum

and there’s nothing extra in the logs about the specifics of the problem. So, as usual, I put that in to Google - and it was completely clueless!

Read more

SharePoint 2010: Visual Webpart tutorial

One of the scourges of software development, and it seems especially SharePoint development, is that more often than not, when faced with a new task, Google is your first stop, looking for tutorials or guides. Frequently, however, people posting the tutorials (MSDN/Microsoft included) are guilty of putting up guides and source code that is incorrect, or missing some vital info. I experienced this very issue recently when I needed to create a visual webpart.

The tutorial is good enough, but the actual source code posted, doesn’t work. What’s most infuriating, though, is when the author then goes radio silence, and the comments fill up with bemused readers, all looking to achieve the same goal - but unable to do so.

Read more

SharePoint: Error occurred during deployment step activate features

Quick (annoying) thing. Whilst deploying a solution, you may see this error:

Error occurred in deployment step ‘Activate Features’: Key cannot be null. Parameter name: Key

This is unhelpfully connected to your Content Type definitions where you have FieldRefs and you’re closing them with the long tag, as opposed to the short tag, i.e.,

replace it with this to fix:

Thanks to Dhiraj.

Tip: Visual Studio + Batch replace GUIDs

A common method for creating Visual Studio-based SharePoint solutions is to actually create them in the SharePoint GUI first, and then save the site as a template, and import that .wsp file in to Visual Studio as a SharePoint project. This often saves a lot of the hard slog of starting from scratch in Visual Studio, but still giving you the reusability of Visual Studio based solution.

One small issue you may run in to though is the (re-)use of GUIDs in e.g., Site Columns. For safety, you may like to replace the GUIDs, but in the case where you have a lot to replace, doing this by hand could be cumbersome. Step up Visual Studio Macros. You can create a simple Macro to automate virtually any process. The only problem, in this case, though, is that my testing of macro-ing the Find/Replace was that I could easily find GUIDs in a file, but replacing them with a freshly generated one wasn’t obvious. So I created a custom macro.

Read more

Powershell tip for updating document sets

If you’re using the handy Document Sets feature in SharePoint 2010 you may run in to a small issue where you make some changes to your document set (e.g., add/remove content types from the allowed contents). When you do this, and push changes down to existing document sets, you’ll see a little yellow bar appear on each document set with the message

“Content Types that are available to this Document Set have been added or removed. Click here to update the Document Set.”

The reason is that the document set refresh date needs updating. Quite why SharePoint can’t manage this for you, is beyond me, but nevertheless, if you do click the yellow bar, it disappears. But it still remains for all your other document sets. Irritating. So here’s how to remove the little yellow bar with the message using Powershell. The neatest way is just to provision the document set.

Read more

Exchange Web Services and reading an EmailMessage to memory

The Exchange Web Services Managed API is a great tool for exposing Exchange Web Services to a .NET programming environment. You are able to work with all the key features of an Exchange Mailbox, such as downloading messages. In my particular case, I’ve been capturing emails and storing them in a SharePoint document library.

The upload to SharePoint can be achieved by passing in a MemoryStream object - that is, you read an EmailMessage to memory, and then upload it to SharePoint. The FileAttachment object has a neat Load() method which allows you to read a FileAttachment to a MemoryStream:

Read more