.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

ItemAdding event receiver - properties.ErrorMessage appears to be truncated

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

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

View Complete Post

More Related Resource Links

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

How to show html tags in Properties.Errormessage in Itemadding, Itemupdating?

    properties.Cancel = true;
    properties.ErrorMessage = "You are yet to choose an answer . <a href='" + cUrl + "/lists/hire/Emp.aspx" + "'> <u>Click</u></a> here to define now<br>";

In the above examples (within ItemAdding), the error message is shown but it doesn't show the actual hyperlink itself. It shows everything including the <a> and </a> tags.

Is there anything to set anywhere else to show the html tags.

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

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

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 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.

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.

Keeping Custom properties in GridView Added on OnRowDataBound Event While Sorting

All of my columns are bound in the Gridview. On OnRowDataBound event, I am adding some custom styles like underlines and colors to the text of the columns. Sorting of data is working fine but I am losing my custom styles when I sort. I am using the generic sorting code for the GridView. How I can keep my custom styles on sorting that I added during OnRowDataBound event.   Thanks for your help.

Redirecting to another page from an eventhandler on ItemAdding event

Hi,   I want to redirect to another page from an eventhandler on ItemAdding event. So please help me achieve in achieving this.    Thanks in Advance

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?

DataGrid control properties not updating on resize event


I have a DataGrid control on a form and I'm binding it to an ArrayList that is populated dynamically as the user scrolls.  The array list is pre-populated with blank records equal in number to the number of records in the DB.  As the user scrolls, if they stop in a place where there are blank records I populate that data from the DB.  I'm using the VisibleRowCount and VertScrollBar.Value properties to determine where I am in the DataGrid.  


The problem is that if I scroll to the bottom of the control then maximize the control it's resize event fires, the VertScrollBar is redrawn proportionally to the number of records, but the Value and VisibleRowCount remain unchanged.  If I then grab and scroll the scroll bar up then back down to the bottom, the Value and VisibleRowCount update correctly.  Is there a way for me to get these values some other way or to force the scroll bar to refresh/update manually?

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.

WorkFlow Event Reveiver parameter "properties.ActivationProperties" is null.

I have been trying to write the event receiver on completion of my out of box "Approval - Sharepoint 2010 workflow" set on a Site Page library. I need to update some column on completion of the workflow.

So for this I need is the list and listItem to which the workflow is attached and the column that I need to update. I understand I can get this using "properties.ActivationProperties" but what I get is null value for this. Can someone help me in this regard? I also tried reading the same in workflowStarted event but even there I get the value as null.

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

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