Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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.

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

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

share|improve this answer
    
He needs the info in C#, not in the GUI –  Robert Lindgren May 27 at 8:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.