开发者

Sharepoint - Item added eventhandler properties do not work

I've started programming event handlers. At first I added some items to lists with hard coded values. Everything worked fine, but then I switched to using properties.OpenWeb() and tried to get the URL with web.Url.ToString() - doing this the handlers won't work and do not emit any error.

Do I have to change any configuration? Have you got a way to solve my problem?

By the way if I try to get values, they are all null.

I am using WSS 3.0 and VS 2008, please see my code below, and thanks!

public override void ItemAdded(SPItemEventProperties properties)
    {
        SPSite site = new SPSite("http://air_sim:1431/");
        SPWeb web = site.RootWeb;
        SPList List = web.Lists["Announcements"];

        base.ItemAdded(properties);

        SPWeb web1 = properties.OpenWeb();

        SPListItem newitem = List.Items.Add();

        newitem["Title"] = "test";
        newitem["Body"] = web1.Url.ToString();

        newitem.Update();

    }

By the way i found this code on msdn. It doesn't work. No error..nothing, and of couse the condition is true.

public override void ItemAdding(SPItemEventProperties properties)
    {
        using(SPWeb oWebsite = new SPSite(properties.SiteId).OpenWeb(properties.RelativeWebUrl))
        { 
            SPListItemCollection collItems = oWebsite.Lists[properties.ListTitle].Items;

            if (collItems.Count >1)
            {
                properties.Cancel = true;
                properties.ErrorMessage = "Adding items to this list is not supporte开发者_如何学Cd because it already contains " + 
                    collItems.Count.ToString() + " items.";
            }
        }
    }


please be sure of that the "Type" in "receiver" in the Elements.xml as following :

<Type>ItemAdded</Type>

your "receiver" node should be something like :

<Receiver>
  <Name>ERItemAdded</Name>
  <Type>ItemAdded</Type>
  <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
  <Class>NameSpace.ClassName</Class>
  <SequenceNumber>10000</SequenceNumber>
</Receiver>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜