.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

WebAdding Event Receiver Issues

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :C#

I am trying to add a WebAdding Event that cancels subsite creation and points user to a page in the layouts.  I used this post as reference: http://www.zimmergren.net/archive/2010/01/05/sp-2010-how-to-event-receivers-and-custom-error-pages.aspx.  Problem is that I cannot get the Redirect to work properly.  I've searched every post on the issue, verified the page exists in the 14/template/layouts and tried for a few days to get this to work, but keep getting an error.  I also found that this ONLY works when a web is created on the top level site collection and not in a subsite.  Am I missing someting?


public override void WebAdding(SPWebEventProperties properties)

           properties.Status = SPEventReceiverStatus.CancelWithError;
      properties.ErrorMessage = "Please fill out the following form\n" +
        "http://oursite/forms/fpages/newsite.aspx \n\n\n\n\n\n\n\n";
      properties.Cancel = true;

 Doesn't work:

public override void WebAdding(SPWebEventProperties properties)

      properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;

View Complete Post

More Related Resource Links

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>





How to rename the document using event receiver during upload

Hi all, I am going to programmaticlly rename the document when it is being uploaded to the document library. In Visual Studio 2010, I used the event receiver and choosed the documment libray type, for the event I selected 'ItemAdding". However I am not able to update the file name using the codes inside this thread: http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/5c3dcc5d-3113-463d-8835-2a050b2471a6/ Can anyone help me with this problem? Thanks!

event receiver to update created field of uploaded document

Hi,   I need to update the created column with the document creation time . 1) First should i use ItemAdding event or Item Added event 2) how do i get the file created properties and assign it to the cdocument library created column.

Running code after site definition site creation in a event receiver or feature receiver

Hi guys I've got a site definition which is pretty much based on STS.This is it's own sharepoint project. Let's call this project SiteDefProj. Next in another SharePoint project (same solution though). Let's call this CustomListProject. In this project I've got a feature which provisions a bunch of lists based on custom content types - this feature is a site scoped. Let's call this feature: CustomListInstances. I have added a feature receiver to this feature to execute some custom code on the lists themselves (under feature activated) In my ONET.XML (part of the SiteDefProj) I have CustomListInstances feature ID as part of my <sitefeatures>. When I do a create site I can actually step through the code and see it actually being executed but after the site is created the list instances are created but it's like the code never run or did anything. The weird part is that stepping through the code while creating a site collection using my SiteDefProj the code runs great with no errors. All lists are there and the code runs smooth. If I manually create a STS site and activate my feature everything works and the code does actually run and the effects are visible after the feature is created. Again I can actually step through it in debug. My suspicion is that there's some sort of a race condition in the CREATE SITE functionality where maybe the web or site collection hol

Event receiver validation client message


Is thera a way to display a client message if validation sets. (java script or inline validation error message)

properties.Status = SPEventReceiverStatus.CancelWithError;

properties.Cancel =



properties.ErrorMessage =


Event receiver deployment on remote server


I have created an EventReceiver using visual studio 2010. Tested on test server and it works ok.

Now I have tried to deploy to production server. Created package.wsp and deployed on the site.

I might add that I can see in the Central Administration / Solution Management that solution is deployed.

After that I have activated feature. All went OK. But the custom validation in the receiver does not work. It looks like its not deployed well.

Is there enything that should be done to activate EventReceiver on remote server?


Event Receiver - for Content type gallery


I wanted to attach a code whenever a new content type is added to the site content type gallery.so that when ever a new content type is created it will copy to all the site collection.

Is it possible to attach an event receiver to Site colomun and site content type library?

Unable to cancel WebAdding event



I want to cancel the WebAdding event and have the user redirected to an error page. Seems simple enough. But I cant get it to work. Heres my code:

 public override void WebAdding(SPWebEventProperties properties)
properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
properties.RedirectUrl = "/_layouts/Custom/error.aspx";

The code executes fine but I get a "File not found" error in the browser afterwards. The ULS logs tells me that someone is trying to use a closed SPWeb (Detected use of SPRequest for previously closed SPWeb object...).

The event handler should prevent my users from creating subsites, but they should be able to create Meeting Workspaces. So it wont be enough to remove the CreateSubweb permission from the permission mask.


Thanks in advance,
Martin Bäckström

Bind Event Receiver to List Dynamically


Hey all, I've been working on a little application page that will give users the option to say whether a list should allow duplicate title entries.

I am able to pass the current list GUID to the application page using this:

<UrlAction Url="~site/_layouts/preventduplicates.aspx?List={ListId}"/>

within a custom action which I've added to the list settings. I'm kind of stuck now....


I'm not sure how to grab this GUID out of the url, and use it so I can bind the current list with my event receiver. Every example I've seen of binding has used a hard coded list name which is fine as an example, but isn't the best for real applications. Or is there a way to use the GUID to get the lists name which I can then pass to the spweb.Lists[var] ? Since I won't know the list name beforehand.

Hope all of that makes sense, any suggestions are appreciated.

ItemAdding event receiver - properties.ErrorMessage appears to be truncated


Hi there,

I have a MOSS Enterprise server with sp1 applied. I have a simple enough custom list with an event receiver. I have written some validation code in the ItemAdding event and I have code similar to the following:

if (!fieldsAreValid)
 properties.Cancel = true;
 properties.Status = SPEventReceiverStatus.CancelWithError;
 properties.ErrorMessage = errorMessage;    

I have a web part that adds items to the custom list, in the web part I have some code which catches the SPException thrown afer calling SPListItem.Update(), within the catch block for the SPException I then retrieve the SPException.Message property and display to the user.

My problem is that I was assuming that the properties.ErrorMessage from the event receiver would be what is used to populate the SPException.Message property - in my case I am getting am SPException.Message property with only the first random amount of characters from the properties.ErrorMessage property.

Looking at reflector and the call stack in Visual Studio there appears to be an unmanaged/managed transition to the Microsoft.SharePoint.Library.SPRequestInternal class in the Microsoft.SharePoint.Library in the OWSSvrLib.dll file so I cannot find the point at which the string is truncated but I would at least li

List Event Receiver in Visual Studio 2010 Received "Save Conflict"


Here is the code. ItemUpdated was looped multiple times that caused the error shown below the code.  I Google the error and one suggestion was adding "if (properties.AfterProperties["vti_sourcecontrolcheckedoutby"] == null && properties.BeforeProperties["vti_sourcecontrolcheckedoutby"] != null)" will prevent the loop. The problem was both properties.AfterProperties["vti_sourcecontrolcheckedoutby"] and properties.BeforeProperties["vti_sourcecontrolcheckedoutby"] were always null. Any ideas?

ItemAdding event receiver has missing lookup information in afterproperties



I am working on a little event receiver for a custom list. I noticed that afterproperties for lookup fields only contain the index but NOT the value of the lookup field. This is only the case for single selection fields. Multiple selection lookup fields will carry all index and value information for all selected fields. This means for multi-selection fields you can use SPFieldLookupValueCollection to iterate and SPFieldLookupValue to access index and value separately. If you try using SPFieldLookupValue on single-select lookup fields, - because the afterproperty is incomplete -  you will receive an error message: Unknown Status Module: 33 Message: 134

The question is: Can this behavior be confirmed and is it limited to the "ItemAdding" event? Thank you very much... 


public override

Event Receiver Deployment mystery

Developing a list event receiver, I frequently deploy updated versions. For debug purposes, I set the Feature Activation Option to "No Activation". This seems to work the first time, and you have to activate the feature manually, but thereafter, in subsequent deployments, it seems that the feature is randomly activated or not. Has anybody else noticed this?    

Is it possible to update a list item in the ItemUpdating event receiver?


i need to add a property (SPListItem.Properties) to the SPListItem being updated in my ItemUpdating event receiver. is there any way to do that?

SPListItem.Update() doesnt seem to be an option, so the obvious answer is probably trying to use the SPItemEventProperties object called properties by calling properties.AfterProperties.ChangedProperties.Add(key, value) and letting sharepoint do the rest, but it turns out it actually deals with fields and not properties. it's a little misleading. so is there another way? some kind of painful work around maybe?

Event Receiver für WorkflowCompleted event - How to get list item?



I'm using an event receiver, which reacts on the WorkflowCompleted event (which is new in SharePoint 2010). In general the event is fired, when an associated workflow has been completed. The question is: how to get the list item the workflow is running against? The WorkflowCompleted event handler has a parameter of type SPWorkflowEventProperties, but via those properties I can't access the specific list item.

Any Idea how to achieve this?




Error loading and running event receiver Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventRecei


Hi all, i found the below error in event log. How can i fix this issue.

Event ID: 6875            Source: Windows SharePoint Services 3

Error loading and running event receiver Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver in Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c. Additional information is below.

: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

Please help me out in this issue. Thanks in advance.


K2Blackpearl, Sharepoint, .Net

Event receiver while item adding in a document library in SharePoint2010



In my SP site i have various document sets.while i adding a new doc in the document set,i have to find the document belongs to which document set.I want to do it an event receiver..Please help me.

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