Thursday, 16 February 2012

List item added


public override void ItemAdded(SPItemEventProperties properties)
        {
            base.ItemAdded(properties);
            try
            {
                if (properties.ListTitle == "anand")
                {
                    SPListItem oitem = properties.ListItem;
                    using (SPSite osite = new SPSite(oitem.Web.Url))
                    {
                        SPWebCollection owebcol = osite.AllWebs;
                        SPWeb oweb = owebcol["subsite"];
                        SPSecurity.RunWithElevatedPrivileges(delegate()
                        {
                            SPList olist = oweb.Lists.TryGetList("listnew");
                            SPListItem oitemnew = olist.Items.Add();
                            oitemnew["Title"] = "anandnew";
                            oweb.AllowUnsafeUpdates = true;
                            this.EventFiringEnabled = false;
                            oitemnew.Update();
                            oweb.AllowUnsafeUpdates = false;
                            this.EventFiringEnabled = true;
                        });


                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

No comments:

Post a Comment