What is base.ItemAdded(properties);? - sharepoint

For event handling code the following code comes up as default:
base.ItemAdded(properties);
Can anybody tell me what it is used for?
Thanks,
Amit

This event handler notifies you of when an item has just been added to a sharepoint list so that you can do some post-processing on the item. Use ItemAdding() if you want need to make changes to the item before it is posted to the list such as incrementing a unique record ID.

Basically it calls it base Class's ItemAdded method which in turn calls another method BaseItemEventReceiver.
What this method does is set properties.Status = SPEventReceiverStatus.Continue;
This just means that the event is allowed to continue (not cancelled).
As for me I always replace the line "base.ItemAdded(properties);" with my code and it works perfectly fine.

Related

sharepoint event receiver events not firing

I added a workflow to my document library (with a custom content type) and now my content types event receiver function itemcheckingin doesnt fire. Double checked my xml files and it's being properly refered to and other events (itemupdating, itemadding) are firing. Any ideas?
Have you tried programmtically pulling down a list of Event Receivers using something like SPList.EventReceivers and seeing if the correct events are bound to your receiver? Sometimes the XML files don't show exactly what the database is holding.
-Shaun
Is your list item definitely of the content type that has the registered event handler? It sounds like you might have created a new item of the workflow-containing content type where that content type does not have a handler for the event of interest. I guess I interpret your post as saying that you now have two content types -- one with the workflow and one with the event handler.
I second #SCMcDonnell's suggestion to go straight to the horse's mouth and see what event receivers are registered for your list item and its content type.
EDIT: Oh, I guess I initially missed your claim that other events are firing successfully. That makes my answer less likely. Still, I recommend that you go specifically retrieve the event receivers for the offending list item.
Does the list have force checkout on it?
If it does, then the checkin fires and ItemUpdated as well. See this KB article
http://support.microsoft.com/default.aspx/kb/939307
if (properties.AfterProperties["vti_sourcecontrolcheckedoutby"] == null && properties.BeforeProperties["vti_sourcecontrolcheckedoutby"] != null)
{
//This is when the update event is triggered by check-in.
}
else
{
//This is triggered by events other than check-in action.
}

How to set up an workflow in SharePoint to only work when a specific field is changed and not everytime the item is edited?

The issue is that everytime an item is edited/changed all the users who are set up to receive updates are notified. I need the workflow to run only when a specific field is changed disregarding the others. For example if my item contains these values (Customer Name; Acc#; Contact Person; Address;) - I need the workflow to work only when the Acc# is changed and only if it is changed, no metter how many times the other fields are changed.
Thanks,
A quick way to do it is to have the workflow store the value each time the it starts, then tell it to wait until the field != the stored value. This may not work in all cases, but it could be enough for your purposes.
You should create an event handler to run on your content type or library. You can then check the before and after properties of the fields you mention. Then use the event handler to initiate the workflow if required.

ItemUpdating not showing changed values in SharePoint event receiver

I'm trying to find how a field's value has changed in an ItemUpdating event receiver. The particular field's display name and internal name is Regions.
As soon as ItemUpdating is hit, the value of the Regions field is identical for the following:
properties.AfterProperties["Regions"]
properties.BeforeProperties["Regions"]
properties.ListItem["Regions"].ToString()
I would expect the latter two to contain the old value but surely AfterProperties should be set correctly.
Does anyone know how I can obtain the changed value?
Update: The event handler is attached to a MOSS 2007 publishing Pages list.
I've had a lot of trouble with event handlers on publishing pages libraries. Think it comes from their being other event handlers on there already for publishing. I had better success with updating, can you change to that or do you need the sync event to block the change ?
Are you trying this in a List or Document Library ?
It will work Only on the Doc Lib Please refer to these
MSDN and another on same subject

ItemAdding never fired

I have a custom content type with two event handler attached : ItemAdded and ItemAdding.
The first one (ItemAdded) is fired without problem.
But the second one is never fire. I've attached the event using API et declarative way. But nothing change.
Do you have already get the same issue ?
Maybe you can use this tool to check wheather your event receivers are assigned correctly to the list where your content type is used:
http://www.entwicklungsgedanken.de/2008/02/29/tool-eventreceiver-installer-for-sharepoint/
Maybe you have a configuration error in your feature definition.
Look in the Event Logs. Mine, most of the time, will place an error entry in the Application event log.

How to fire code upon creation of a SharePoint list?

I'm aware of the event receivers on a list for items added etc. However, I have not found a way to fire code upon the creation of a list.
What I'm trying to do is associate a workflow with a list when the list is created (by the user through the UI).
Anyone any ideas?
thanks.
There are a couple of routes you can take...
You can write your own list definition where you have defined the workflow association - That way all lists created based on your list definition, will contain your workflow on default.
Or... depending on your workflow... write an EventReceiver your attach to all lists of the type you wish to attach your workflow to (can easily be achieved tru a feature) and have your event receiver associate the workflow when the first item is added.
or you can associate the workflow to the contenttype used in the list (your own contenttype you attach to your own list definition or a default SharePoint contenttype)
I don't know the rest of your solution, so it's defficult for me to suggest the best solution for you.
What I (almost) always do, is write my own list definition - That way I can avoid problems like this, now or in the future.
With SharePoint 2010 it is now possible to hook into the list creation event by overriding the ListAdded event in the SPListEventReceiver class.
I usually deploy an extra view page which is set to the default view. When the user creates the list he will be sent to the viewpage which contains the setup in code behind. The view page then calls a method ive created, which changes the default view, removes the setup view and change any navigation node pointing to the setup view.
There is probably no perfect answer to this question because there is no list added event receiver (if memory serves me correct).
I don't know if this is the case, but if you really just needed to register an itemadded (or updated, deleted, etc.) event to any new list, I believe you can register the those events at the site (SPWeb) level and they will fire on any new lists created.

Resources