WebHosting

Tuesday, June 28, 2011

Fetching user names and E-mail Addresses from SPGroups

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 ......

Featured Posts

How to Enable and Configure Remote Desktop (RDP) on Ubuntu 24.04.4 LTS

Remote Desktop Protocol (RDP) support in Ubuntu has become considerably easier with the GNOME Remote Desktop stack included in modern Ubuntu...