.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Getting elevated site in Event Handler

Posted By:      Posted Date: October 27, 2010    Points: 0   Category :SharePoint


In ItemCheckingIn and ItemCheckedId event handlers, I need elevated site since I'm deleting / adding new documents.





public override void ItemCheckedIn(SPItemEventProperties properties)


using (SPSite site = SecurityHelper.GetElevatedSite(properties.ListItem.Web.Site))
		using (SPWeb web = site.OpenWeb(properties.ListItem.Web.ID))
			// do some strange things			

catch{ }


But according to the best practices, Its a bad idea to instantiate a new SPSite and SPWeb object. (obviously, for performance reasons..)



Since I need elaveted web in both event handlers, I'll have double performance penalty. I was thinking to make us of caching, but SPSite or SPWeb is not thread safe, so cannat be cached..


Is there any better way ?

View Complete Post

More Related Resource Links

Site Pages Library Event Handler not working



I have created an event handler for Site Pages library in SharePoint 2010. In event Handler I have given the list template id (119 - wiki web page library) but the event handler is not working. Do I need to use different list template id for this.?

Event handler firing for one site but not for another



I have an event handler that is working just fine on a list in one site, but when I bind it to the other list in another site, it binds properly, but never fires. Any suggestion? 


Creating Event Handler in Code behind


Hi, so I have a control that is created in the code behind and generates fine but I can't figure out how to create an event handler for it.  I've found plenty of examples for it in C sharp, but none of them seem to apply to VB.  What I want to do is essentially this:

myDropDownList.SelectedIndexChanged = "Event to do here"

but it doesn't seem to work for me.

Any suggestions are appreciated.

want to launch modal Popup from created User Event handler




I have a create user wizard on my page and in the event handler (Created User) I get extra information from the user

via textboxes within the aspx etc.


I then do a response.redirect to another page.

What I want to happen is this


When the CreatedUser Event is fired, I  want a Modal Popup to show up with a message Processing your registration.

once the registration code is processed it will close and the users get redirected.


On my ASPX I have the Modal PopUp and a Panel.

In the code behind in the handler I put ModalPop.show()


but this does not work.


thanks for any suggestions



InfoPath Workflow Task Form "Loading" event handler only being called after App Pool recycled.


I have a Workflow that is using an InfoPath task form.  In the "FormEvents_Loading" method event handler I have some code that needs to run each time the form is opened.   I recycle the App Pool and open the form the code runs perfectly, but if I close and try to re-open the form the code is not run at all.  I can then recycle the App Pool again and on the next load the code executes just fine.   The code that is supposed to be run is a very simple statement to set a field value, so I don't think it is interfering.

Does anyone know what this might be?


Event Handler Credentials


I made EH that checks out document when OOB Approval WF is finished successfully.

I want doc to be checked out by WF Initiator, but by default it is made by System Account.

How can i change Event Handler Account ?

Why feature with event receiver doesn't activate properly after site provisioning?



I have defined feature with event receivers for my document library and for users List .

I try to activate my feature in onet.xml in section <WebFeatures>. After provisioning a new site from onet.xml  all work fine and my feature is shown as activated, but event receivers doesn't fire. It fires only after reactivating my feature (deactivate, then activate it again). But I need my feature works immediately after site provisioning without deactivating and activating it again. Who knows how to solve this problem?

part of ONET.xml



        <Feature ID="00BFEA71-4EA5-48D4-A4AD-7EA5C011ABE5"/>

        <!-- TeamCollab Feature -->

        <Feature ID="F41CC668-37E5-4743-B4A8-74D1DB3FD8A4"/>

        <!-- MobilityRedirect -->

        <!--My EventReceivers Feature-->

        <Feature ID ="41178843-A6A4-47c7-9EF9-B8A432E02B88"></Feature>





Pre_Init event handler problem


Hi all my friends

   I have to masterpages for my home page.

1. The first is for the annonymous users which has the login controls. its name is General_Anonymous.master.

2. The second one is for the logged in users which has a logout button and it hasn't the login controls in it. its name is General_LoggedIn.master.

in my default.aspx page I wrote the following code

protected void Page_PreInit(object sender, EventArgs e)
            if (Session["SupId"] == null && Session["CustomerId"] == null)
                this.MasterPageFile = "~/Masters/General_Anonymous.master";
                this.MasterPageFile = "~/Masters/General_LoggedIn.master";

Event Handler & AD

My event handler is working fine until i add AD part. After this string it stops firing at all: DirectoryEntry dom = new DirectoryEntry(); I mean it compiles, deploys and doesnt react to anything ( Why ? PS VS2010, SP2010  

how to get values of list item being entered in ItemAdding event handler?

Hi,          i am trying to get the values being entered in a listitem in the ItemAdding eventhandler as follows, but it doesnt work. public override void ItemAdding(SPItemEventProperties properties)         {             base.ItemAdding(properties);             SPSite CurrentSite = new SPSite("http://mm-moss/np/");             SPWeb CurrentWeb = properties.OpenWeb();             SPList CurrentList = CurrentWeb.Lists[properties.ListId];             string vehicleNo = CurrentList.Items[CurrentList.Items.Count - 1]["Vehicle No"].ToString();             string  name=CurrentList.Items[CurrentList.Items.Count-1]["Name"].ToString(); } when i debug i cant get hold of the VehicleNo value. canyone help me in getting the values of the list item being entered? Thank you all.

Create a meeting instance with an event handler

Hi, i want to know if its posible to insert a new meeting instance in a meeting workspace automatically when you add a new event in a calendar.   i try to pass automatically the option of the template selection.   its posible with the objetc model or web services?   thanks

ASP.Net event id 1334 SRS Reports site not available yet reportserver is

We have a SQL 2008 SP1 server running on Windows Server 2008R2. It holds the DataWarehouse for our SCOM2007R2 environment. Up until last month http://server/reports worked fine and allowed users access to out pre-configured reports. However it was noticed recently that this site is no longer available. Testing from localhost also failed, no permissions had been changed. However we are getting the following Event ID 1334 for ASP.NET 2.0.50727.0:- Failed to initialize the AppDomain:ReportManager_MSSQLSERVER_0 Exception: System.Configuration.ConfigurationErrorsException Message: Unrecognized element. (C:\Program Files\Microsoft SQL Server\MSRS10.MSSQLSERVER\Reporting Services\ReportManager\web.config line 18) StackTrace: at System.Web.HttpRuntime.HostingInit(HostingEnvironmentFlags hostingFlags) at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters) at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters) at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironment(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters) at System.Web.Hosting.Appl

Event handler that will take an e-mail sent to a doc library and save it as an .MSG file within the

Hi All, I have a requirement to create an event handler that will take an e-mail sent to a doc library and save it as an .MSG file within the library? Any help/inputs on getting this done is much appreciated.  Hanif

Sharepoint Event Handler not firing

I have written an event handler for an ItemAdded eventfor a document library. I am trying to read an excel file being uploaded and extract a value from it which I write to a list column for the item. I have this working properly on my development machine which is a Windows Server 2003 machine.However, on a production Windows Server 2008 machine, the event handler never fires. I am doing a simple write to a log file to test and see if it runs at all even if the Excel parsing does not work but I get no indication that it ran. The event handler is being registered with a feature that I am deploying. I have verified that the event handler is registered to the library by using the u2u Event Handler Explorer tool.Is there any way I can determine if my event handlers are even executing? How can I debug this?

ItemAdded Event Handler not firing

Hi, I have created an ItemAdded Event handler that is linked to a content type. This event handler does certain custom validations and then sends Email to users. I have referenced this event handler in XML file as well but somehow the event handler is not getting fired...Following is the code.   Code Snippet            this.DisableEventFiring();            using (SPSite site = new SPSite(properties.SiteId))            {                 using (SPWeb web = site.OpenWeb())                {                    base.ItemAdding(properties);                     SPList nList = web.Lists["NList"];                    SPList IList = web.Lists["IList"];                     foreach (SPListItem listItem in nList.Items)                    {                        if (listItem["Topic"].ToString() == properties.ListItem["Topic"].ToString())                        {                            SPUser alertUser = (SPUser)(properties.ListItem["SUser"]);                            SPUtility.SendEmail(web, false, true,alertUser.Email,"New item added", "A new item has been added");                         }                    }                    this.EnableEventFiring();                }            }       The XML file is: Code Snippet  <XmlDocuments>      <XmlDocument NamespaceURI="http://schemas.microsoft.com/

Event Handler not picking up error

I have a connection manager which uses a Variable as part of a ConnectionString. I have tried putting an Event handler on the package to capture any errors with the connection string. Unfortunately the event handler does not pick up any errors. I would like to add some screenshot but i am not sure how to do it on this forum.  Mr Shaw

Event handler to delete minor versions in document libraries

Hi Is there a way we can capture the deletion of minor versions in document libraries using any event handler. May not be using the delete all the minor versions but at least when we use the option to delete the selected minor version. I do not see the ItemUpdating and ItemUpdated getting fired in this case. Thanks wpwije  
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend