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

I have a Custom SPList that has a field "Assigned To", now I can add as many items as I want, and they can have same title and same User they are assigned to, but what I want is a script so that I only get the Distinct number of user's email address, e.g. if a user is assigned to more then 1 item, I will get there email address just once, here is the code I wrote down but i dont think if its good enough.

using (SPSite site = new SPSite("www.local.com"))
        using (SPWeb web = site.OpenWeb())
        {
            SPList mySourceList = web.Lists["ListName"];

            SPQuery mySourceListQuery = new SPQuery();

            mySourceListQuery.Query =

                "<OrderBy><FieldRef Name='AssignedTo' />" +
                         "<FieldRef Name='Title' />" +
                "</OrderBy>";



            SPListItemCollection mySourceItemColl = mySourceList.GetItems(mySourceListQuery);


                foreach (SPUser user in web.Users)
            {
                foreach (SPListItem mySourceListItem in mySourceItemColl)
                {
                    name = mySourceListItem["AssignedTo"].ToString();

                    name = name.Substring(name.IndexOf("#") + 1);

                    if (user.Name == name)
                    {
                        Console.WriteLine(user.Email);
                    }
                }
            }

I dont think if it even works properly as it's not going through all of them, any suggestions please

CHeers

share|improve this question

1 Answer 1

up vote 0 down vote accepted

I Used SPUserField property instead so I didn't required to compare users with list items anymore.

share|improve this answer

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.