Answered AssignedTo and getting the person programatically

  • Wednesday, July 11, 2012 8:33 AM
     
     

    Hi

    I've created a timer job that looks at a Calendar List. The list has a AssignedTo field.

    I want to email the person in the AssignedTo field.

    Using
     string taskassign = Convert.ToString(curItem["AssignedTo"]); gives 8;#Jane Mary

    I could use string manipulation to get the name in the format and email. I was thinking perhaps I could get the email instead or use SPUser class.

    Any ideas on best approach ?

    Thanks

All Replies

  • Wednesday, July 11, 2012 8:51 AM
     
     Answered Has Code

    Hi orange,

    Try this..

    string strUserValue = oList["Assigned To"];
    int intIndex = strUserValue.IndexOf(';');
    int intID = Int32.Parse(strUserValue.Substring(0, intIndex));
    SPUser oUser = oWebsite.SiteUsers.GetByID(intID);
    string stremail = oUser.Email;


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact ravimca@live.com.

  • Wednesday, July 11, 2012 8:55 AM
     
     Answered Has Code

    Hi,

    This code snippet could help you easily gets the User from Person/Group field in SharePoint list.

    SPFieldUserValue userField = (SPFieldUserValue)list.Fields["Assigned To"].GetFieldValue(item["Assigned To"].ToString());
    SPUser user= userField.User;

    After that you will be able to use SPUser.Email Property


    Dmitry

    Lightning Tools LogoLightning Tools Check out our SharePoint tools and web parts | Lightning Tools Blog