tags:

views:

155

answers:

4

I thought this would be pretty simple, but guess not. I have the following code, it deploys and activates just fine, but when I add a new document to the document library, nothing happens. No errors either. And this is taken directly from another example from someone online who said it works.

Here's the code for my feature:

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;

namespace DocNumGenerator
{
    class DocNumGenerator : SPItemEventReceiver
    {
        public override void ItemAdded(SPItemEventProperties properties)
        {
            base.ItemAdded(properties);
        }

        public override void ItemAdding(SPItemEventProperties properties)
        {
            properties.AfterProperties["DocNum"] = "4321";
            base.ItemAdding(properties);
        }

        public override void ItemUpdated(SPItemEventProperties properties)
        {
            base.ItemUpdated(properties);
        }

        public override void ItemUpdating(SPItemEventProperties properties)
        {
            base.ItemUpdating(properties);
        }

    }
}

Simple right! Why doesn't this work? Do I need to somehow specify the name of the document library in addition to the name of the custom column that I am specifying? I'm lost on this one and desperate for a solution. This is a SharePoint 2007 environment, publishing site.

Thanks for any help!

A: 

could you try first calling base, base.ItemAdding(properties);, then just set properties.ListItem["DocNum"] and the call properties.ListItem.SystemUpdate(false);

Colin
A: 

Is DocNum the display name or the internal name? Try change between those.

JMD
A: 

Try this in the ItemAdded event handler:

DisableEventFiring();
SPListItem item = properties.ListItem;
item["DocNum"] = "4321";
item.Update();
EnableEventFiring();
Rob Windsor
A: 

I got it to work..and I swear I'd tried this before. I also did a reboot, so maybe that was it???

Here's what is working for me now:

public override void ItemAdding(SPItemEventProperties properties)
        {
            this.DisableEventFiring();
            properties.AfterProperties["Document Number"] = "whatever";
            this.EnableEventFiring();
        }
PushCode
The need for a reboot indicates that even though your file had been deployed to the GAC, a process was locking it. Next time, try running IISRESET and see if it works then.
Alex Angas