Stumbles and Travels


Adding value to Multi-choice field with Object Model
June 9, 2007, 3:37 pm
Filed under: MOSS

This is a quick post on how to add another value to a Multi-choice field using the object model.  The code is below and assumes that you already have a reference to your SPWeb object stored in ‘myWeb’.

SPFieldMultiChoice myField = (SPFieldMultiChoice)myWeb.Fields["Field Name"];
myField.Choices.Add(“Value to add”);
myField.PushChangesToLists = true; //Set to false if you don’t want Lists/Content types to update automatically
myField.Upate();



Activating an Event Receiver through the object model
June 9, 2007, 2:28 pm
Filed under: MOSS

What do you do, if you have an event receiver which you want to attach to one and only one document library within a SPWeb?  Using the infastructure provided to you by the feature framework you can attach it to a SPWeb as whole, but not a specific list.  Fortunately pretty much everything can be done using the object model.  The code below shows how to attach an event receive to a specific list.  This code assumes that the assembly containing the event receiver has been deployed to the GAC and that the feature has already been installed through stsadm.

SPSite mySite = new SPSite(http://localhost/);
SPWeb myWeb = mySite.OpenWeb();
SPList myList = myWeb.Lists["Name of List"];

SPEventReceiverDefinitionCollection myReceivers = myList.EventReceivers;
SPEventReceiverDefinition receiver = receivers.Add();
receiver.Name = “My Receiver Name”;
receiver.Assembly = “<namespace>, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxx”;
receiver.Class = “<namespace>.<class>”;
receiver.Type = SPEventReceiverType.ItemAdding;
receiver.Update();



The site is not valid. The ‘Pages’ document library is missing.
June 2, 2007, 8:29 pm
Filed under: MOSS

The title of this post is an error message which confronted me when I first attempted to use the Document Conversion Service available in MOSS; attempting to create such a library on your site does not solve the problem.  The error message appeared after I had activated the Document Conversion Service in Central Administration and then attempted to convert my first document.

The solution around this issue is actually rather basic.  Simply follow these steps:

  1. On your site go to site actions -> site settings
  2. Under Site Administration click on Site features
  3. Activate Office SharePoint Server Publishing

Just don’t forgot to configure the converter settings otherwise you’ll get more error messag when you try to convert a document!