5

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 2

3

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.

7
  • @Charles I'm usint SPFieldUserValue oUser = item["Created By"] as SPFieldUserValue;. Will this pose a problem? Commented Apr 1, 2010 at 21:47
  • Not if it works no. Are you getting an appropriate value back? Commented Apr 2, 2010 at 8:46
  • 1
    Remember to dispose SPSite/SPWeb you create yourself Commented Apr 3, 2010 at 17:17
  • I did mention that in my last note, but I suppose its worth another mention in the comments. Commented Apr 3, 2010 at 19:05
  • Definitely @Anders and @Charles i'm opening site and web using using constructs Commented Apr 4, 2010 at 18:28
0

No Need for Code or anything, Add the Fields Created By and Modified By and you see all.

1
  • 1
    He needs the info in C#, not in the GUI Commented May 27, 2014 at 8:16

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.