Retrieve query string values iin SHarePoint event receiver
This post will helpful to manipulate SharePoint list item based on query string value in events such us item adding, item deleting and item updating. Also you can learn how to cancel the item adding/deleting/updating to SharePoint list using custom event receiver.
In this post I would like to share quite simple code on SharePoint event receiver but it worth you lot to do List manipulation using Query string.
Scenario:
While adding/deleting/updating list item in SharePoint list depends on query string value you have to do few operations on SharePoint List.
Solution:
The below code will help you to get query string on SharePoint List Events such us List deleting, Updating, Adding etc.
Code:
public class EvtReceiverFromQuery : SPItemEventReceiver
{
///
/// An item is being added.
///
///
HttpContext oContext = null;
public EventReceiver1() : base()
{
oContext = HttpContext.Current; // we will get current httpcontext
}
public override void ItemAdding(SPItemEventProperties properties)
{
base.ItemAdding(properties);
if (hContext != null)
{
string queryString = hContext.Request.QueryString["A"].ToString();
//Check for Query string value.
if(queryString=="Yes")
{
//do opertaion
}
//Cancelling item adding to list
else
{
properties.cancel=true;
}
}
}
That is't.
Reference: http://sharepointpassion.wordpress.com/tag/receive-query-string-in-sharepoint-event-receiver/