using
System.Linq;
System.Text;
System.Threading.Tasks;
Microsoft.Office.Server.UserProfiles;
Microsoft.SharePoint;
Microsoft.SharePoint.Administration;
namespace
MysiteCreation
{
class
Program
static
void
Main(
string
[] args)
try
Console.WriteLine(
"Please enter the site URL"
);
String url = Console.ReadLine();
SPSite site =
new
SPSite(url);
SPWeb web = site.OpenWeb();
SPServiceContext serviceContext = SPServiceContext.GetContext(site);
"Please enter the group name"
String groupName = Console.ReadLine();
UserProfileManager userProfileManager =
UserProfileManager(serviceContext);
SPGroup group = web.Groups[groupName];
SPUserCollection users = group.Users;
foreach
(SPUser user
in
users)
if
(userProfileManager.UserExists(user.LoginName))
UserProfile uProfile = userProfileManager.GetUserProfile(user.RawSid);
(uProfile.PersonalSite !=
null
)
"Mysite Already exists for the user "
+ uProfile.AccountName);
}
else
uProfile.CreatePersonalSite();
"Mysite successfully created for the user "
"This is completed, please press any key to exit"
Console.ReadLine();
catch
(Exception e)
Console.WriteLine(e.Message);
Naomi N edited Revision 1. Comment: Minor edit