I have a feature receiver which batch updates a particular field / column in my list. Code is provided below.

NB: This is very simple list item batch processing code which I got from http://msdn.microsoft.com/en-us/library/cc404818(v=office.12).aspx. I do this instead of looping through the entire list because it has 1000s of rows.

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
        using (SPWeb web = properties.Feature.Parent as SPWeb)
            SPList list = web.Lists["MyList"];
            SPQuery query = new SPQuery();
            query.RowLimit = 100;

                // Get the next batch of 100 uninitialised items.
                SPListItemCollection uninitialisedItems = list.GetItems(query);

                // Batch update the list items.
                StringBuilder methodBuilder = new StringBuilder();
                string batchFormat = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                    "<ows:Batch OnError=\"Continue\">{0}</ows:Batch>";
                string methodFormat = "<Method ID=\"{0}\">" +
                        "<SetList>{1}</SetList>" +
                        "<SetVar Name=\"Cmd\">Save</SetVar>" +
                        "<SetVar Name=\"ID\">{2}</SetVar>" +
                        "<SetVar Name=\"urn:schemas-microsoft-com:office:office#MyField\">{4}</SetVar>" +

                for (int i = 0; i < uninitialisedItems.Count; i++)
                    int itemID = uninitialisedItems[i].ID;
                    methodBuilder.AppendFormat(methodFormat, itemID, list.ID.ToString(), itemID, 1);

                list.ParentWeb.ProcessBatchData(string.Format(batchFormat, methodBuilder.ToString()));

                query.ListItemCollectionPosition = uninitialisedItems.ListItemCollectionPosition;
            } while (query.ListItemCollectionPosition != null);

The problem here is that an email alert is being sent for every one of my list items saying that it has changed. I want to prevent this alert from being sent as I am merely setting a field that is not made visible to the user. Any idea how to do this?

FYI: I am using MOSS 2007


You could use SystemUpdate instead of ProcessBatchData. False should mean modified date doesn't change:

SPListItem item = ???;
item["myField"] = "my value";

Of course, this means you have to update each item one at a time instead of the batch process which may lead to performance issues.

See also, how to temporarily disable email notification while updating items in code?.

| improve this answer | |
  • Works like a charm. – Nick Larter Dec 16 '11 at 7:54

If ProcessBatchData is required due to performance/load constraints, you can programmatically disable alerts by iterating through SPWeb.Alerts and finding those associated with your list.

This answer gives a good code example for this: Deactivate email-notifications for SPLists only temporally (and programmatically)

This is applicable in SP2007 (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.alerts(v=office.12).aspx)

| improve this answer | |
  • I had actually considered this @Russell, however the list I am updating is a large tracking list which gets used almost constantly by other employees. So whilst your solution would work from a technical standpoint, we didn't want to disable the alerts that users should be getting (during regular day-to-day list activities) and therefore affect the business. NB: our list has thousands of rows and so takes roughly twenty minutes to update, so the system would then be "down" for this time. We wanted the change/upgrade to be completely transparent to the end user and not affect their work. – Nick Larter Dec 22 '11 at 5:13
  • Thanks for the clarification. It appears in your case, as you say, the approach from Kit was the best. Hopefully this answer will help in other scenarios too. :) – Russell Dec 22 '11 at 5:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.