Import users from CSV??

Posted by Community Admin on 03-Aug-2018 22:29

Import users from CSV??

All Replies

Posted by Community Admin on 24-Apr-2014 00:00

Has anyone had any luck creating something custom that does this?

Posted by Community Admin on 28-Apr-2014 00:00

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

 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 21-Oct-2016 00:00

How to read data from CSV files ?

Posted by Community Admin on 23-Oct-2016 00:00

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;

 

 

This thread is closed