Saturday, April 21, 2007

ItemAdded event handler vs. ItemAdding event handler

I often get asked this question when should i use the ItemAdded / ItemAdding event handler in MOSS 2007. Well the answer is really simple. If you are adding an item to a list and want to perform a set of actions before the item is saved, including preventing the item from being saved or throw an exception, "ItemAdding" is the event handler to override. If you want to perform post add actions then "ItemAdded" in the event handler to override.

Also note that in your event handler code, you would need to use the "AfterProperties" bag to read the list field values that have changed (as opposed to the "Properties" bag). For example:


private void VowelCheck(SPItemEventProperties properties)
{
string vowelErrorMessage = string.Empty;
// Check whether the Title field exists within the List
if (properties.AfterProperties["Title"] != null)
{
// Assumption that you have a class called VowelListManager.cs which has a function CheckVowelExists()
vowelErrorMessage = VowelListManager.CheckVowelExists(properties.AfterProperties["Title"].ToString());
}

// If Error Message is returned then the current words has failed the vowel test- This code also shows how to cancel a SharePoint event (like stop the item from being added or updated)
if (!vowelErrorMessage.Equals(string.Empty))
{
properties.ErrorMessage = vowelErrorMessage;
properties.Cancel = true;
}
}

7 comments:

Kirti Prajapati said...

Hi,
I have problem in MOSS 2007
My problem is :
I have 5 lists which are having same fields.
Now i want to consolidate all 5 lists in one list (with same fields).
And after consolidating them in one list, i want to make group by view on that consolidated list.
Now when i make changes like insert, update, delete records in the original list (from that 5 list) at that time appropriate change should be done in the consolidated list.
So how can i do this.
provide me code if possible

Anonymous said...

Use a lookup field.

lijialefw said...

Why was there no follow on bankruptcy then? The bailout of AIG FP went to (wow power leveling) hedge funds that bound credit swaps on Lehman failing or others betting on rating (wow power leveling) declines. AIG has drained over 100 billion from the government. Which had to go to (wow power leveling) those who bet on failures and downgrades. Many of whom (power leveling)were hedge funds. I-banks that had offsetting swaps needed the money from the AIG bailout or they would have been caught. Its an (wow powerleveling) insiders game and it takes just a little bit too much time for most people to think (wow gold) through where the AIG 100 billion bailout money went to, hedge funds and players, many of whom hire from the top ranks of DOJ, Fed, Treasury, CAOBO

Anonymous said...

Amiable brief and this mail helped me alot in my college assignement. Say thank you you as your information.

qishaya said...

Original christian shoes are first category in alter. They are so much appealing louboutin shoes so, ample of women can not pause to get their hands on them. cheap christian louboutin However, these shoes are not economical. christian louboutin So adequate of women cannot present these shoes. christian louboutin heels Christian Louboutin Replica is presenting the textbook thing for these people. christian louboutin sandals It is present masses of fashionable shoes in an economical rate. christian pumps You know that unique shoes are posh to buy. christian sandals Nevertheless do not think that exchange a shoe with christian louboutin pumps magnificent create of top trait is hard. Now a time model are presented. louboutin pumps But if you hardship attribute cargo look discount christian louboutin for these replicas in a trustworthy position & set an order for your beloved shoes christian louboutin sale

wenwen said...

Original ugg boots uk are first category in alter. They are so much appealing louboutin shoes so,

said...

Arthritis means inflammation of jointsMicrosoft Office 2010csdxumei02 It is one of several Office 2010diseases commonly called rheumatism. Arthritis arises from many causes and it is treated in many various methodsMicrosoft Office 2007Arthritis has been classified as follows: - * Arthritis caused by infection.airOffice 2007Arthritis has been classified as follows: - * Arthritis caused by infection.airMicrosoft OfficeRheumatoid arthritis. * Degenerative arthritis. * Arthritis due to joint injuries.supra shoes Office 2007 keyArthritis originating from the nervous Office 2007 downloadRheumatoid arthritis and arthritis caused by rheumatic Office 2007 Professionalfever are classified as collagen disease. * Rheumatoid arthritis and degenerative nfl jerseysMicrosoft outlooktwo common types. Millions of men and women Microsoft outlook 2010are afflicted with them. But good treatment begun early and continued faithfully can often do much to alleviate the pain