cancel
Showing results for 
Search instead for 
Did you mean: 

Quick way to add user to a user group

Former Member
0 Kudos

Hi

Is there a quick way to create a large amount of users and add to a user group? preferably from a xls file.

Appreciate any help.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Very Helpful answer. I forgot to mentioned that I am looking for a java program actually. Thank you very much.

Former Member
0 Kudos

Hi Ying,

you can do this with the BOE NET SDK - Read and add from batch file

here is the code :

Good luck

Falk

using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Enterprise;
using CrystalDecisions.Enterprise.Desktop;


public partial class adduser : System.Web.UI.Page
{
    //Enterprise variables
    SessionMgr boSessionmgr = new SessionMgr();
    EnterpriseSession boSession;
    InfoStore boInfoStore;
    EnterpriseService boEnterpriseService;

    string[,] batcharray =  new string[20,8];
    string[]  userarray = new string[8];

    protected void Page_Load(object sender, EventArgs e)
    {

        //variables for logon to the Central Management Server (CMS)
        string userid = Request.QueryString["username"]; 
        string password = Request.QueryString["password"];
        string cms = Request.QueryString["cms"]; 
        string auth = Request.QueryString["authtype"]; 

        

        /* This function logs on to the Enterprise CMS with the parameters provided.
         * It will retrieve the InfoStore object stored in the Session if it exists
         * otherwise it create it and put it in session.
        */

        // Check if infostore is in session to be retrieved.
        if (Session["CEInfoStore"] != null)
        {
            boInfoStore = (InfoStore)Session["CEInfoStore"];
        }
        else
        {
            // Infostore was not in session so let's create it.
            boSession = boSessionmgr.Logon(userid, password, cms, auth);
            boEnterpriseService = boSession.GetService("InfoStore");
            boInfoStore = new InfoStore(boEnterpriseService);

            // Add the InfoStore object to the Session
            Session.Add("CEInfoStore", boInfoStore);
        };
       
    }

    protected void btnAddOne_Click(object sender, EventArgs e)
    {
        int UserNumber = 10;
        CreateBatch("T_Title", "T_Name", "T_Description", "PWD", "true", "false", "false", "N", UserNumber);
        CreateUsers(batcharray, UserNumber); 
    }

    protected void btnAddTwo_Click(object sender, EventArgs e)
    {  
        int UserNumber = ReadBatchfromFile();
        CreateUsers(batcharray, UserNumber);  
    }

    void CreateBatch(String Title, String FullName, String Description, String Password, String PwdExp, String chPwdNL, String AllchPwd, String Connection, int Number)
    {
        for (int i = 0; i < Number; i++)
        {
            batcharray[i,0] = Title;
            batcharray[i,0] += i.ToString();

            batcharray[i, 1] = FullName;
            batcharray[i, 1] += i.ToString();

            batcharray[i, 2] = Description;
            batcharray[i, 2] += i.ToString();

            batcharray[i, 3] = Password;
            batcharray[i, 4] = PwdExp;  // Password expires
            batcharray[i, 5] = chPwdNL; // change Password at next LogOn
            batcharray[i, 6] = AllchPwd; // Allow change Password
            batcharray[i, 7] = Connection; // Connection Type
            
        }
    }

    int ReadBatchfromFile()
    {
        StreamReader sr = new StreamReader(Server.MapPath("") + "\\UserBatch.txt");

        int number = Convert.ToInt32(sr.ReadLine());

        for (int i = 0; i < number; i++)
        {
            sr.ReadLine();
            batcharray[i, 0] = sr.ReadLine(); //Title;
            batcharray[i, 1] = sr.ReadLine(); //FullName;
            batcharray[i, 2] = sr.ReadLine(); //Description;
            batcharray[i, 3] = sr.ReadLine(); //Password;
            batcharray[i, 4] = sr.ReadLine(); //PwdExp;  // Password expires
            batcharray[i, 5] = sr.ReadLine(); //chPwdNL; // change Password at next LogOn
            batcharray[i, 6] = sr.ReadLine(); //AllchPwd; // Allow change Password
            batcharray[i, 7] = sr.ReadLine(); //Connection; // Connection Type
            sr.ReadLine();
        }

        return number;
    }

    void CreateUsers(String[,] Temparray,int Number)
    {
        for (int i = 0; i < Number; i++)
        {
            userarray[0] = Temparray[i, 0];
            userarray[1] = Temparray[i, 1];
            userarray[2] = Temparray[i, 2];
            userarray[3] = Temparray[i, 3];
            userarray[4] = Temparray[i, 4];
            userarray[5] = Temparray[i, 5];
            userarray[6] = Temparray[i, 6];
            userarray[7] = Temparray[i, 7];

            CreateUser(userarray);
        }
    }

    void CreateUser(String[] User)
    {

        // BOE infostore query variables
        InfoObjects boNewUsers;
        InfoObject boNewUser;
        PluginManager boPluginMgr;
        PluginInfo boUserPluginfo;


        boPluginMgr = boInfoStore.PluginManager;
        boUserPluginfo = boPluginMgr.GetPluginInfo("CrystalEnterprise.User");

        // Create a new infoobject collection
        boNewUsers = boInfoStore.NewInfoObjectCollection();

        // Add a new user
        boNewUsers.Add(boUserPluginfo);
        boNewUser = boNewUsers[1];

        User boNewUserInterface = (User)boNewUser.GetPluginInterface("");


        // Set some generic Properties
        boNewUser.Title                                 = User[0];
        boNewUserInterface.FullName                     = User[1];
        boNewUser.Description                           = User[2];
        boNewUserInterface.NewPassword                  = User[3];


        if (User[4] == "true")
            boNewUserInterface.PasswordExpires = false;
        else
            boNewUserInterface.PasswordExpires = true;

        if (User[5] == "true")
            boNewUserInterface.ChangePasswordAtNextLogon = true;
        else
            boNewUserInterface.ChangePasswordAtNextLogon = false;

        if (User[6] == "true")
            boNewUserInterface.AllowChangePassword = true;
        else
            boNewUserInterface.AllowChangePassword = false;

        if (User[7] == "C")
            boNewUserInterface.Connection = CeConnectionType.ceConnectionConcurrent;
        else
            boNewUserInterface.Connection = CeConnectionType.ceConnectionNamed;
        
        try
        {
            boInfoStore.Commit(boNewUsers);
            Label3.Text = "User(s) successfully added "; //with ID" + boNewUser.ID.ToString();
            
        }
        catch (Exception err)
        {
            Label3.Text = err.Message.ToString();
        }
    }
}