In IAlertNotifyHandler implementation I need name of the user who created/add the current item/document to the list (for which this alert is being sent). What is the way to do this?
2 Answers
When you create your OnNotification method you can access the list item with code similar to this.
public bool OnNotification(SPAlertHandlerParams ahp) { SPSite site = new SPSite(ahp.siteUrl+ahp.webUrl); SPWeb web = site.OpenWeb(); SPList list=web.Lists[ahp.a.ListID]; SPListItem item = list.GetItemById(ahp.eventData[0].itemId); String user = item("Author"); } Not sure on your requirements but you may need to add some additional code to then get a domain\username if this is what you require.
Note: This is sub-optimal code to highlight only the code needed to get the list item. I know there are dispose issues here.
- @Charles I'm usint
SPFieldUserValue oUser = item["Created By"] as SPFieldUserValue;. Will this pose a problem?amantur– amantur2010-04-01 21:47:22 +00:00Commented Apr 1, 2010 at 21:47 - Not if it works no. Are you getting an appropriate value back?Charles Lee– Charles Lee2010-04-02 08:46:29 +00:00Commented Apr 2, 2010 at 8:46
- 1Remember to dispose SPSite/SPWeb you create yourselfAnders Rask– Anders Rask2010-04-03 17:17:42 +00:00Commented Apr 3, 2010 at 17:17
- I did mention that in my last note, but I suppose its worth another mention in the comments.Charles Lee– Charles Lee2010-04-03 19:05:13 +00:00Commented Apr 3, 2010 at 19:05
- Definitely @Anders and @Charles i'm opening site and web using
usingconstructsamantur– amantur2010-04-04 18:28:15 +00:00Commented Apr 4, 2010 at 18:28
No Need for Code or anything, Add the Fields Created By and Modified By and you see all.
- 1He needs the info in C#, not in the GUIRobert Lindgren– Robert Lindgren2014-05-27 08:16:30 +00:00Commented May 27, 2014 at 8:16