Import users from CSV??
Has anyone had any luck creating something custom that does this?
Hi Eli,
There is no way to directly import users from an .csv. You will need to add them by creating a custom membership provider and use the users from the other system:Create a custom membership provider or use the API to create the users in Sitefinity:Creating users and Creating user profiles.
Regards,
Ivan D. Dimitrov
Telerik
How to read data from CSV files ?
Hi Roshith,
Very rough example how to read from CSV file and then create users in Sitefinity:
// CSV format username;password;firstName;lastName;mail;secretQuestion;secretAnswer;isApproved
public
static
void
YourFunction()
var users = File.ReadAllLines(
"users.csv"
);
foreach
(var user
in
users)
var data = user.Split(
";"
);
CreateUser(data[0], data[1], data[2], data[3], data[4], data[5], data[6],
bool
.Parse(data[7]));
public
static
MembershipCreateStatus CreateUser(
string
username,
string
password,
string
firstName,
string
lastName,
string
mail,
string
secretQuestion,
string
secretAnswer,
bool
isApproved)
UserManager userManager = UserManager.GetManager();
UserProfileManager profileManager = UserProfileManager.GetManager();
System.Web.Security.MembershipCreateStatus status;
User user = userManager.CreateUser(username, password, mail, secretQuestion, secretAnswer, isApproved,
null
,
out
status);
if
(status == MembershipCreateStatus.Success)
SitefinityProfile sfProfile = profileManager.CreateProfile(user, Guid.NewGuid(),
typeof
(SitefinityProfile))
as
SitefinityProfile;
if
(sfProfile !=
null
)
sfProfile.FirstName = firstName;
sfProfile.LastName = lastName;
userManager.SaveChanges();
profileManager.RecompileItemUrls(sfProfile);
profileManager.SaveChanges();
return
status;