Useful SharePoint script to restart SharePoint services and IIS

A SharePoint developer’s life is filled with many things, but one of the most common is the old faithful iisreset, coupled with a reset of the Timer Service and the Admin Service. When you’re working on timer jobs, it can get tedious quickly to have to  keep resetting things.

So I’m sharing a useful batch script I knocked together to do it for you. It will perform three functions - restart the SharePoint 2010 Timer Service, the SharePoint 2010 Administration Service and do an IISReset. It will prompt you if you want to do each of them, and if you don’t reply within 5 seconds automatically do it.

Read more

Configuring certificates and trust in SharePoint 2010 for accessing Exchange Web Services

Exchange is built on web services and as I posted about a while about accessing EWS from SharePoint can be pretty neat. There is a managed API to make your life even easier. However, one issue you may come across is actually getting SharePoint and Exchange to talk nicely to each other. This will walk you through some of the steps required to get things going.

Read more

SharePoint 2010: The filename, directory name, or volume label syntax is incorrect

This is a peculiar little bug. When creating a List Definition, you may encounter the following error when you try to deploy:

The filename, directory name or volume label syntax is incorrect.

It took a while to track the cause, seeing as a lot of info out there info out there relates to things to do with file systems, which in this case, obviously wasn’t the cause.

The bug for me was that I had created a List Definition and called it My.List.Definition - notice the multiple periods. I wanted it to match the namespaces that we were using. It turns out that the second period trips it up. When you create a List Definition with multiple periods, the List Definition only gets the first period, e.g., My.List, whereas the Elements.xml file for the List Definition still references My.List.Definition - hence it can’t deploy properly.

Read more

Coverage of a SharePoint 2010 project recently completed

Interesting coverage of a document repository system in SharePoint 2010 I recently implemented for a client based in Ireland.

The field with Id {} defined in feature {} was found in the current site collection or in a subsite

This is a known bug in Visual Studio. It seems to occur most often when using VS to deploy (and redeploy) declarative content types to a SharePoint site. I’ve seen it happen most often when deploying List Definitions and List Instances. There are a variety of steps out there to try to make it go away:

  1. Retract solution, close VS, restart VS, deploy solution.
  2. Deploy project, attempt to activate via UI, deactivate, retract, restart VS, deploy solution.
  3. Deploy, retract, deploy. Open Task Manager, kill VSSHostP4.

Deploying after this should be resolved.

Read more

Quick tip: SPListItem.CopyTo custom method

One use for my custom Ribbon buttons could be to move files (or Document Sets) from one library to another. I was trying to get the SPListItem.CopyTo method working, but for various reasons, it refused to play ball.

I came across a handy piece of code that is essentially a custom method for doing the same thing. Couldn’t understand a word of the article, but got the gist of what the code was doing. It essentially creates an item in the target location, and then copies all the field info over to the new item. This works fine for Lists, and even copies attachments, but what about for document libraries, which are setup a bit differently?

Read more

SharePoint 2010 + Document Sets + Custom Ribbon Buttons with Custom Code

I recently posted a guide on how to add an item to the SharePoint 2010 context menu (“EditControlBlock”) and run some custom code on the click action. SharePoint 2010 uses the love-it-or-hate-it Microsoft Ribbon, which, to the developer, is fully accessible. This guide will show you how to implement a custom button for a Document Set, in the Manage group and also on the Edit form, and run some custom code when it’s clicked, in Visual Studio 2010.

Read more

SharePoint 2010 context menu item with custom code

List items in SharePoint lists and document libraries have a “context menu” on the Filename/FileLeafRef field. When you hover to the right of the field, you see a drop down menu with a bunch of options. You can add your own items to this list, and also run custom code when the item is clicked. This tutorial will show you how, using Visual Studio 2010 and SharePoint 2010.

Edit: 16/02/2012 - there were a few comments about the custom assembly not firing. I’ve revised the post below to include an extra bit in the XML to ensure the control loads (see #13.)

Read more

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