Does the Ribbon control/framework support dynamic adding of new/additional tabs?

Hi, i developed an ItemAdding Event handler. i want this eventhandler to be generic. i am trying to use this in the code, when debugged i get Object reference not set to an instance. can anyone help me in the right direction?

            string siteUrl = properties.WebUrl;    //throws object reference not set to an instance here
            
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite CurrentSite = new SPSite(siteUrl))
                {

                    using (SPWeb CurrentWeb = CurrentSite.OpenWeb())
                    {
                        SPList CurrentList = CurrentWeb.Lists[properties.ListId];

                    }

}

});

i also tried this, have gotten the same exception

            SPWeb webInUserContext = SPContext.Current.Web;   //throws object reference not set to an instance
            SPSite SiteInUserContext = SPContext.Current.Site;
            Guid webGuid = webInUserContext.ID;
           Guid siteGuid = SiteInUserContext.ID;
                    
           SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite CurrentSite = new SPSite(siteGuid))
                {

                    using (SPWeb CurrentWeb = CurrentSite.OpenWeb())
                    {
                        SPList CurrentList = CurrentWeb.Lists[properties.ListId];
}

}

});

please help.

Use this codepublicoverridevoid ItemAdding(SPItemEventProperties properties)

My first thought is that if you run this code on a subweb, then your site object will not be correct.  I think the answer to your problem is that you need to open the web on the event receiver thread.  I’d do this:  at the beginning put

Dan, thanks for your reply.  i tried the way you said, but i still get the same error. here is what i have triedSPWeb oWeb=properties.OpenWeb();  //this line of code works goodSPSite oSite=oWeb.Site;   //throws object reference not set to an instanceother codelines i triedSPSite oSite=oWeb.ParentWeb.Site; //throws object reference not set to an instanceGuid siteGuid = properties.SiteId; //throws object reference not set to an instancei have also another question, do the synchronous event handlers need to run with ElevatedPrivileges? i mean my requirement is to block two users from entering the same listitem again. for which i would need to query all the listitems. if the user has permision