Skip to main content

SharepointLabs.com Blog on MOSS - WSS 3.0 sharing experience, technology, news, views and more

Go Search
Home
Buy Webparts
SharePoint Training
Contact Us for Consulting Inquiry
  

SharepointLabs.com Blog on MOSS - WSS 3.0 sharing experience, technology, news, views and more > Posts > Not able to get Current Context in Event Handler: Solution is here
Not able to get Current Context in Event Handler: Solution is here

To solve problem you need to create httpcontext constructor explicitly like below code

public class MyEventHandler: SPItemEventReceiver
{
HttpContext current;
public MyEventHandler()
{
current = HttpContext.Current;
}


public override void ItemAdding(SPItemEventProperties properties)
{

//perform validation if required.

// get the list which item to be added
SPSite objsite = new SPSite (properties.SiteId);
SPWeb objweb = objsite.OpenWeb (properties.RelativeWebUrl);
SPList objlist = objweb.Lists[properties.ListId];

//use this method to disable reoccurence of events.

DisableEventFiring();
SPListItem itemToAdd = objlist.Items.Add();

//add item to list

itemToAdd.Update();
EnableEventFiring();

// provision sub site and perform required action

//redirect it to your new destination like newly provisioned sub site or any other page you want.

SPUtility.Redirect(strNewresiractionUrl, SPRedirectFlags.Trusted,current);

}

Posted by Vaibhav Jain (Success is always one step ahead)

Comments

There are no comments yet for this post.
Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


Attachments