.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

Guidelines for where/if base.Item*(properties) should be placed in an Item Event Receiver? (WSS3)

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :C#
Are there any guidelines or reasons as to where (or if) you should place base.Item*(properties) (e.g. base.ItemAdding, base.ItemUpdated, etc.) in Item Event Receivers?
There seems to be a good chunk of people that always make it the first thing, another chunk that just leave it out altogether, and then some that put it last.  This (at bottom) says that .Cancel won't work unless base.ItemAdding/Updating is placed at the top.  This MSDN How-To suggests that AfterProperties[]= won't work unless base.ItemAdding/Updating is placed afterwards.  Then this recommends placing base.Item*(properties) at the end, but inside of a DisableEventFiring block.  The comments in Brian Wilson's Starter Kit say to replace the base.Item* in the template with custom code altogether.

I understand the point that since you've overridden the built-in event handler, you (somestimes?) need to make sure it gets to do whateve

View Complete Post

More Related Resource Links

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

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?




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.

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.

Personal view reverts back to default after updating properties of item


I am working with a company that has 1 site collection with several sub sites.  I have built 3 document libraries with workflow in 3 different sub sites and all behave as expected.  I have one site where ALL libraries do something perplexing;

If you are in a custom personal view and you go into the properties of a document and then exit (update or not, does not matter) it reverts back to the default view of that library. 

Has anyone seen this?  is there an option when creating an album that could cause this?

thanks in advance for any input on this odd issue.

listview with button in item template - how do I handle the click event?

Hello,Using a listview control for the first time... I need a button for each item, and of course I need to handle the click event for the buttons... upon clicking a particular button I of course need to know which item the button is associated with so the appropriate action can be taken...In VS, I can't select the button and see my list of available events in the properties window like is normally done for controls outside of templates like this... what do I need to do?

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.

New item insertion validation through event handler

My requirement is.... I have a list in SharePoint 2007. When I will add a new item into that list it will check the with the previous list item in the list (only title column). If the  same is available it should not allow to insert in the list and cutom error should through. If the same title name is not in the list it should insert in the list. As far my knowledge it will be done by event receiver. But I am unable to do it. Plaese help me....... Thanks in advance Rajesh.

FormView Command Button not firing Item Command Event

Hi, In my content page, I have a formview for Insert & Edit. In insertitemtempalteI have a command button (btnInsert) to trigger  Item_Command event to insert a new record. The button event never gets triggered. But If I set CausesValidation = "false"it fires. But I want the validation to take place. I tried btnInsert_command and btnInsert_Click events. None of them is fired. Ideally I would like to havethe item_command event fired. I would appreciate any inpyt on how to handle this problem. <FormView>     <InsertItemTemplate>            .....           <div>               <asp:Button id="btnInsert" CommandName="Insert" Text="Insert" runat="server" UseSubmitBehavior="true" />              <asp:Button id="btnCancel" CommandName="Cancel" Text="Insert" runat="server" />           </div>     </InsertItemTemplate></FormView>   Thanks Suresh

disable a single intem in dropdownlist or stop the ddl change event for a single item


hello guys,

I am trying something apart of my boundries, is there any way to disable a single intem in dropdownlist or stop the ddl change event for a single item.

any feadback would be appriciable.

Thanks and Regards

Inderjeet Singh Khalsa

event handler - item adding and updating..example



I am a beginner to event handlers..I need to create something like..items created in List A should appear in List B, and when it is updated, it should appear in List B as well..are there like free samples that I can work on..I am not really good at programming

event handler - how to add item from listA in SiteA to listB in SiteB


hi..is there a way to add items from one list to another..


SharePoint - Item - Edit Properties - Access Denied Error

I have a SharePoint 2007 EE Site  (with patches up to version running on Windows Server 2008 & SQL Server 2008.
I ported an existing site from a different domain to this server by backing up/restoring the content database. The site is running fine.

I added a new sub-site and here is where I have the issue. If I create a document library, add a document, and then use the drop-down on the item to pick "edit properties" I bounce to the SP Error: Access Denied screen. My account is a site admin and has full access to the sub-site.
I can view the properties fine.

When I try to upload a document I get the access denied error message if some of the meta data properties are marked "required". The document is still uploaded. I also get the same error when I try to edit an item in a list.

I can view/edit the properties in Data sheet view fine. The libraries on the existing sites work fine. It only seems to be an issue on new sub-sites.

It almost seems like a permission problem generating the property edit forms. There is nothing in the SP log files.

List Properties Supporting Files Display item form won't stay set


In Sharepoint designer I am trying to set a custom display form for a list, following the instructions in the Sharepoint designer help.


I've got a functional display form, called DispForm3.aspx. I know it works since I tested it by replacing the form name in the normal URL where a display form is opened.


However I can not get the list to accept this new form as the display item form.


In Sharepoint Designer, in the List Properties Supporting Files tab I set the Display item form to be DispForm3.aspx and press OK. When I look again I see that the Display item for is DispForm.aspx.


This happens on any list that I try to customise the display form for, even new ones.


Sharepoint designer is allowing me to set the display item form to DispForm3.aspx but is not saving it, or is failing silently when it tries to save it.


Any assistance appreciated.


ItemUpdating event handler causes SPRequest object was not disposed error if properties.ListItem is


I have a very simple ItemUpdating event handler that is causing an SPRequest object was not disposed error when it is fired. The event handler is linked to the document library. I have cleaned out all of my code and narrowed it down to this:

    public override void ItemUpdating(SPItemEventProperties properties)
      SPListItem item = properties.ListItem;

When I change the name of a file or folder in my document list the following line is logged in the SP log:

An SPRequest object was not disposed before the end of this thread.  To avoid wasting system resources, dispose of this object or its parent (such as an SPSite or SPWeb) as soon as you are done using it.  This object will now be disposed.  Allocation Id: {D7AA6805-4CA1-458B-9252-E83D32DBD0D3}  To determine where this object was allocated, set Microsoft.SharePoint.Administration.SPWebService.ContentService.CollectSPRequestAllocationCallStacks = true.


As an extra note I have actually set the CollectSPRequestAllocationCallStacks to true, this is all the information that it gives me. If I comment out the pr

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

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