+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Import users from CSV??

Import users from CSV??

4 posts, 0 answered
  1. Eli
    Eli avatar
    2 posts
    Registered:
    06 May 2013
    24 Apr 2014
    Link to this post
    Has anyone had any luck creating something custom that does this?
  2. Ivan D. Dimitrov
    Ivan D. Dimitrov avatar
    310 posts
    Registered:
    26 Mar 2015
    28 Apr 2014
    Link to this post
    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
     
  3. Roshith
    Roshith avatar
    0 posts
    Registered:
    05 Oct 2016
    21 Oct
    Link to this post
    How to read data from CSV files ?
  4. Victor Leontyev
    Victor Leontyev avatar
    65 posts
    Registered:
    01 Jul 2014
    23 Oct in reply to Roshith
    Link to this post

    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;
    }

     

     

4 posts, 0 answered