There are various groups present over a SharePoint Site. The below code can extract email addresses of all the existing users in all the groups.
Code to get the user names:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string username;
SPSite spsite = new SPSite("site url"); //Ex: http://adfsaccount:2222/
SPWeb web= spsite.RootWeb;
SPUserCollection userlist= web.AllUsers;
foreach (SPUser u in userlist)
{
username=u.Name;
}
}
}
}
Code to get the email addresses:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SPSite spsite = new SPSite("site url"); //Ex: http://adfsaccount:2222/
SPWeb web= spsite.RootWeb;
SPUserCollection userlist= web.AllUsers;
foreach (SPUser u in userlist)
{
string email = u.Email.ToString();
}
}
}
}
No comments:
Post a Comment
Thank you for Commenting Will reply soon ......