Answered by:
Update Item in Sharepoint List

Question
-
I have created a custom list in Sharepoint (using MOSS2007) to create a document log which is automatically populated when documents are added to or updated in the document libraries within the site. I need to be able to automatically delete an entry when the associated docuemt is deleted. Can anyone tell me how I would do this?Friday, July 8, 2011 4:22 PM
Answers
-
You could use the SharePoint ItemDeleted Event Receiver and when a document is deleted delete the corresponding entry from the list.
However, please note that SPListItem in this event will be null, you will need to get the metadata information from the properties hashtable
public override void ItemDeleted(SPItemEventProperties properties) { using(SPSite oSite = new SPSite(properties.WebUrl)) { using(SPWeb oWeb = oSite.OpenWeb()) { //do something } } }
Refer http://www.codefornuts.com/2009/09/dear-sharepoint-team-itemdeleted.html
My SharePoint Blog
http://dhireny.blogspot.com- Proposed as answer by Pieter_Veenstra, MVPMVP Wednesday, July 20, 2011 8:32 AM
- Marked as answer by Xue-Mei Chang-MSFTModerator Thursday, July 21, 2011 1:51 AM
Friday, July 8, 2011 7:40 PM -
Hi Kimwol,
If your question is not still answered, you might find some help in a blog I wrote a while on this that describes how to use the Properties, BeforeProperties and AfterProperties. http://www.synergyonline.com/blog/blog-moss/Lists/Posts/Post.aspx?ID=25.
Only other thing I'll add is that you should be cautious about creating a new SPSite and web object. This can add a sizeable performance hit if you expect your handler to run regularly. Instead, you can also access the current web through the properties.web and the site collection through the properties.site member property as described here (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spitemeventproperties_members.aspx).
Hope this helps.
Randy - SharePoint MVP- Marked as answer by Xue-Mei Chang-MSFTModerator Thursday, July 21, 2011 1:51 AM
Tuesday, July 19, 2011 5:44 AM
All replies
-
You could use the SharePoint ItemDeleted Event Receiver and when a document is deleted delete the corresponding entry from the list.
However, please note that SPListItem in this event will be null, you will need to get the metadata information from the properties hashtable
public override void ItemDeleted(SPItemEventProperties properties) { using(SPSite oSite = new SPSite(properties.WebUrl)) { using(SPWeb oWeb = oSite.OpenWeb()) { //do something } } }
Refer http://www.codefornuts.com/2009/09/dear-sharepoint-team-itemdeleted.html
My SharePoint Blog
http://dhireny.blogspot.com- Proposed as answer by Pieter_Veenstra, MVPMVP Wednesday, July 20, 2011 8:32 AM
- Marked as answer by Xue-Mei Chang-MSFTModerator Thursday, July 21, 2011 1:51 AM
Friday, July 8, 2011 7:40 PM -
Hi Kimwol,
If your question is not still answered, you might find some help in a blog I wrote a while on this that describes how to use the Properties, BeforeProperties and AfterProperties. http://www.synergyonline.com/blog/blog-moss/Lists/Posts/Post.aspx?ID=25.
Only other thing I'll add is that you should be cautious about creating a new SPSite and web object. This can add a sizeable performance hit if you expect your handler to run regularly. Instead, you can also access the current web through the properties.web and the site collection through the properties.site member property as described here (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spitemeventproperties_members.aspx).
Hope this helps.
Randy - SharePoint MVP- Marked as answer by Xue-Mei Chang-MSFTModerator Thursday, July 21, 2011 1:51 AM
Tuesday, July 19, 2011 5:44 AM