USERID_17050 Sharepoint Tips And Tricks: Synchronous Add List event (ItemAdding) will not give access to item properties skip to main | skip to sidebar Sharepoint Tips And Tricks Sharepoint Tips And Tricks is Ishai Sagi's sharepoint information blog. It specializes in Microsoft SharePoint technologies, including web parts, development, configuration, customization, and best practices for the use of Microsoft SharePoint Server and Windows SharePoint Services. It also provides some related Office Information, including VSTO and VSTA and other office application development tips. Wednesday, September 27, 2006 Synchronous Add List event (ItemAdding) will not give access to item properties UPDATE: I have had a chance to look into this again now, and found that indeed it is possible to access and change properties in ItemAdding, if you are doing it through the "AfterProperties" hash table of the event, and not through the list item. Some things to note: During ItemAdding, there is no SPListItem object to refer to. It is null in the event properties, because to get an SPListItem a record for the item should be in the database, and during ItemAdding nothing has been written to the database yet . After ItemAdding, the item is added to the database. When it is added, the values from the AfterProperties are applied to it. If you try to add a property to that hashtable that doesnt exist in the list definition, the user will get an error that the field isn't installed correctly. You may encounter this if you don't use the internal name of the field when you set the AfterProperties. The moral of the story - Use the AfterProperties in ItemAdding , and when you use it to get or set a field, make sure you use the field's internal name . That said, my argument with Sahil (see below in the original post) remains - you cannot use the SPListItem, because one cannot exist. His sample code modifies the item that was added before the current item, and not the current one. Here is a sample code that modifies one of the fields in the ItemAdding event. In this example we have a links list, with a custom column called "Tool Tip" (internal name is "Tool_0x0020_Tip") and we want to set it automatically to the title of the link the user picked: public override void ItemAdding( SPItemEventProperties properties) { string toolTipFieldInternalName = "" ; using ( SPWeb web = properties.OpenWeb()) { toolTipFieldInternalName = web.Lists[properties.ListId].Fields[TOOL_TIP_FIELD_NAME].InternalName; } string urlVal = properties.AfterProperties[ "URL" ].ToString(); SPFieldUrlValue val = new SPFieldUrlValue (urlVal); string desc = val.Description; properties.AfterProperties[toolTipFieldInternalName] = desc; } Original post: (was posted during Beta2) Ok - here is an update to my " Bad news - synchronous list events bug (or missing feature) " post from August: I reported this as a bug to Microsoft, and got a response that they "cant repro this on a newer build - please check on TR". So I waited for TR, and checked again - no change! The properties of the new list item are simply not accessible. I reported this to MS, and this time gave a full code sample so that they will be able to repro exactly what I was trying to do. The answer came back that this is by design! Microsoft has no plans of giving us developers access to list item properties in the itemadding event. All you will know is that an item is being added. You will notice that the SDK was also updated to show a sample code that checks the number of items in the list and shows a user an error if there are 150 items in the list. But checking the new item's properties can only be done in the "itemadded" event. By the way, this means that Sahil's example does have the bug I pointed out - during itemadding, the item is not yet added to the list and is not available through list.Items[list.Items.Count-1] . People- I think this is big enough that we should gang up on Microsoft and clamor for them to give us the ability to check properties of list items. Write comments here if you agree and we will build us a petition! Posted by Ishai Sagi [SharePoint MVP] at 6:13 PM Labels: SharePoint 2007 10 comments: Anonymous said... The same problem applies to using itemupdating. You can not get access to item properties. Very annoying. Asked Microsoft. They gave the same reply (By Design). I find this unacceptable. 1:50 PM Anonymous said... I had the same problem but with the itemupdating event. No way to see the value of the new list properties. Were you able to find any resolution to this? Microsoft got back to me with their "As Designed" reply... Thoughts? Ideas? 1:48 PM Suresh said... I also agree with you. I am using Item ading event to insert data to some of my list item's field which is hidden to user. but the data is not inserted to those fields. Furthermore , i have a workflow on that list item.I want to the workflow to be executed after my code in Item Added event is executed. But it is executed before this event. How can i control the workflow. 2:14 AM Sheetal Jain said... Thanks god I stumbled upon your blog.. I was going insane... Look like whoever design this event certainly didn't have clue on how people are going to use it.. What is the whole point of giving this placeholder if we can't the data???? It is true... MS gets everything right in 3rd attempt... So wait till Office14 6:21 PM Sheetal Jain said... I agreee.... This is useless without data.... 6:22 PM A. Quneibi said... I also agree with you. I would like to use Item adding-event to fill data to some of Item-fields which are hidden to user, but this is not possible. I have to Insert the Item, and then fill the Data to it. I do not know if this Event makes any sense!!!! 10:26 AM Anonymous said... Hi, I'm sure we need access to properties in ItemAdding, if not, why we want that event? just to limit the number of items in the list?... I don't think so 3:57 AM Keith said... Iterating through the properties worked for me, e.g.: foreach (DictionaryEntry de in properties.AfterProperties) { string myValue = de.Value; string myKey = de.Key } 7:14 PM Anonymous said... Dear Readers, Thats for your posts. I have been trying for this since 2 months at last i found this article and came to know that was issue, i find this so stupid why microsft will do allways like this, without exposing the properties in ITemadding and itemupdating what is the point of exposing that event handlers.... any way i was very much needed this can any one has any idea please write a email to me... i have a calendar control and using this control i will book meetings, my problem is i don't the users to book duplicate time slots .. thanks, rao 10:23 PM Anonymous said... Interestingly, ItemAdding() and ItemAdded() do not work/fire for Lists at sitecollection level ("User Information List") in WSS 3.0. A bug in WSS (or perhaps there is a reason why it wouldnt work..) Sriram rsriram22 at hotmail dought com 12:16 PM Post a Comment Links to this post Create a Link Newer Post Older Post Home Subscribe to: Post Comments (Atom) RSS, Email Notifications and Contact details Subscribe to Sharepoint Tips And Tricks by Email Email Ishai Sagi About Me Ishai Sagi [SharePoint MVP] Canberra, Australian Capital Territory, Australia A SharePoint expert since 2001, I have worked for several consulting companies, and developed several SharePoint solutions. I am currently employed as a solution architect in Unique World - an Australian company consulting in SharePoint and other Microsoft technologies. I have been awarded the Microsoft Office SharePoint Server MVP award from Microsoft on the 1st April 2007, and renewed in 2008 View my complete profile Certifications Application Development MCTS in WSS and in MOSS Configuration MCTS in WSS and in MOSS Atheists - Reach Out My Company is Hiring Want to work with me? Live in Australia? Got SharePoint or ASP.NET2 experience? join Unique World! Useful Links My MVP Profile My profile @ Linked-In SharePoint Tips Utility Pack Enchanced Content Query Webpart Project Labels SharePoint 2007 (101) Personal Junk (47) Code Sample (43) General SharePoint (All Versions) (13) SharePoint 2003 (13) Administration (10) Content Query Web Part (8) Event Handlers (8) Features (8) Enhanced Content Query Web Part (7) Free Downloads (7) Free Web Parts (6) Links (6) Tech Ed 2008 (6) Recommended SharePoint Products (5) Best Practices (4) Custom fields (4) Development (4) InfoPath (4) Nested Tasks Project (4) Open Source (4) XSLT (4) BDC (3) CAML (3) MVP Summit 2008 (3) SharePoint Designer (3) Tech Ed 2007 (3) Upgrade (3) XSLT Data Views (3) Accessibility (2) Certification (2) Live SharePoint Sites (2) Office (2) Search Customization (2) User Profiles (2) Windows 2008 Server (2) Workflow (2) web services (2) Begginer Guide (1) Blog Recommendations (1) Canberra User Group (1) Databases (1) Error Messages (1) Excel Services (1) Macro (1) My Sites (1) Service Pack (1) SharePoint Hierarchical Tasks (1) SharePoint How To Book (1) SharePoint Product recommendation of the week (1) SharePoint User Groups (1) Site Columns (1) Video (1) alerts (1) hardware (1) infrastructure update (1) javascript (1) site definitions (1) troubleshooting (1) Looking for SharePoint or .NET Employees? Startup Looking For Level 78 Rails Mage Make online games with us. • Fun atmosphere. • Competitive salary, benefits & equity • Help us create new games from scratch • Akron, OH Fun Team needs a Software Developer! ...for a small fun team making great software • WPF,WCF,C# • Expression Blend, XAML • Sql skills a plus • Phoenix, AZ » post your job » browse more jobs » syndicate jobs Blog Archive ▼ 2009 (7) ▼ March (1) Upgrading SharePoint - SharePoint Tips' point of v... ► February (4) Finally - a solution to having bluetooth in window... Preventing IIS from logging activity on a specific... New MOSS internet site launched - good case study Dispose check tool - to check your best practices ► January (2) Memberships Discounted Microsoft Certification code ► 2008 (70) ► December (1) Changing fields by code - common oversight ► November (5) How to copy attachments from one list item to anot... Custom fields with custom properties - important l... Using the People picker - how to specify what can ... My code for the custom fields presentation Tech.Ed EMEA presentation ► October (4) Throwing myself behind the site definitions Cool new free feature - download all files zipped!... Application pool crash on win2008 New SharePoint book coming up - by me! ► September (7) Developing Custom SharePoint fields - coming soon ... Offtopic - Zune new updates do not work on win2008... Samsung rant Strange win2008 accessibility issue How to use the Microsoft Solution Generator on a 6... Common question - how to change the alert email BDC Column Demo ► August (12) Problems with BDC Definition Editor AMD developer site on SharePoint Ask me a question, win an HP iPAQ Open letter to laptop manufacturers My BDC presentation at Teched Australia Infrastructure update kills view functionality in ... Grouping and sorting settings of custom fields How sharepoint determines if a field is "groupable... Goodbye good friend Why no posts? Do not read from the SharePoint Database (unless y... What accounts does the people picker show ► July (2) Updating web part properties, without the tool pan... CAML sorting by file name ► June (3) Access denied when trying to open a site when on t... Showing "my links" on a web page Things to think about when planning a SharePoint s... ► May (5) A must read blog post -everything about AllowUnsaf... Tweet - writing code that accesses a site in anoth... Access denied when trying to get to shared service... A Lookup to the sub sites My TechEd 2008 Presentations are on video ► April (11) Antarctic pictures Event handlers configuration settings best practic... Checking the current user's permission on a web si... How to find the default SSP with code ► March (10) ► February (9) ► January (1) ► 2007 (122) ► December (3) ► November (5) ► October (12) ► September (5) ► August (11) ► July (5) ► June (14) ► May (7) ► April (25) ► March (14) ► February (5) ► January (16) ► 2006 (89) ► December (6) ► November (10) ► October (6) ► September (10) ► August (12) ► July (14) ► June (19) ► May (2) ► April (1) ► March (5) ► February (3) ► January (1) ► 2005 (1) ► December (1) My Blogroll <dev:Blog> ...Me Unplugged... Adventure Girl Alex's blog <a href="http://www.bloggix.com/blogs/mic Amanda Murphy's Xbox and SharePoint Blog Andrew Connell [MVP MOSS] Andrew May's WebLog Andrew Richter's Professional Blog Arpan Shah's Blog Bart Hanssen's Blog Bill Baer BizTalk 2006 - Windows SharePoint Services adapter Blah Blah Blog [Ryan Rogers] Bob Fox's SharePoint Blog: Posts Brain Dump - Thoughts, musings, outbursts & revelations of Corne Brian Farnhill Capital Design cBlog 0.2 Sample Site Feed Chris Johnson cjwalker's WebLog Closet Genius Technology Blog CodeSegment - Carlos Segura Sanz (blog) Collaborate Cottleston Pie Daniel Larson's Developer Blog Daniel | zevenseas | SharePoint Blog The Dean's Office Development Diaries DocuPoint dwinter's [MSFT] WebLog edhild's WebLog Eric Legault My Eggo FitzBlog Free Fire Zone FrontPoint GAYAN PEIRIS'S SHAREPOINT BLOG [MVP] The Goldfish Bowl greg hughes - dot net - SharePoint Gregory S. MacBeth - <a href="http://www.linkedin.com/in/gregmcb Guru-Web Heather Solomon - MVP, WSS - SharePoint Branding and Design Jack of all that is Microsoft, Master of None James Edelen Jan Tielens' Bloggings Jean-Paul Smit Joel Oleson's SharePoint Land John Holliday, MVP Office SharePoint Server 2007 Johnwe's SharePoint WebLog JOPX on SharePoint 2007 (MOSS and WSS V3 ) Karthick's Blog Keith Richie Kristian Kalsing Lamont Harrington's Blog LauraJ's Weblog Lawrence Liu's Report from the Inside Marcus Hass' [MS] Blog : SharePoint Mark Harrison 2009 Mart Muller's Sharepoint Weblog - Sharepoint Matthew Cosier's Blog Mei Ying's Tech Blog Method ~ of ~ failed by Tim Heuer Michael O'Donovan's SharePoint and Stuff Microsoft Knowledge Network Team Blog Microsoft SharePoint Designer Team Blog Microsoft SharePoint Products and Technologies Team Blog Mike H. - Another Geek In Need... Mike Taghizadeh's Blog Mike Walsh's WSS and more Mike Walsh's WSS, Finland and more The Mit's Blog Mohamed Zaki's Blog [Sharepoint MVP] Nick Porter - SharePoint & More Not Fit For Print - Robert Bogue [MVP] Offline SharePoint Point2Share Rob Nowiks SharePoint Blog Roberdan Robin | zevenseas | SharePoint Blog Scott's musings... Shane Perran's SharePoint Customization Blog Share Points Share-Port SharePoint / ASP.Net Development - SharePoint SharePoint Apps: Alexander Malek's weblog SharePoint Blogs SharePoint Internals - Hristo Pavlov's Blog SharePoint Nick SharePoint Talk Sharepoint Tips And Tricks SharePoint User Group UK SharePoint: State-of-the-Art The SharingPoint SPSFAQ Stacy Draper et al Steen Molberg's Blog Stuart Preston's Blog Tangible Thoughts Tech Talk PT Ted's SharePoint Things that Should be Easy Thom Robbins .NET Weblog : SharePoint Tips and Tricks Tim W's Blog Tobias Zimmergren's thoughts on development Todd Bleeker Todd Klindt's Blog: Posts Tools for Moving to a Microsoft Collaboration Platform Wayne Hall Wayne Larimore - his Bloggin' Weighs Windows Sharepoint Services etc. Powered by Bloglines Fun Team needs a Software Developer! ...for a small fun team making great software • WPF,WCF,C# • Expression Blend, XAML • Sql skills a plus • Phoenix, AZ Startup Looking For Level 78 Rails Mage Make online games with us. • Fun atmosphere. • Competitive salary, benefits & equity • Help us create new games from scratch • Akron, OH post your job • browse more jobs • syndicate jobs