protected void Page_Load(object sender, System.EventArgs e)
        {
            try
            {
                //display nav bar
                Nav1.Feedback.Text = String.Empty;
                Nav1.SideTabId     = AssignmentManager.Common.constants.SIDE_NAV_COURSE_MANAGEMENT;
                Nav1.TopTabId      = AssignmentManager.Common.constants.TOP_NAV_COURSE_USERS;
                Nav1.Title         = SharedSupport.GetLocalizedString("AdminImport_Title");
                Nav1.SubTitle      = SharedSupport.GetLocalizedString("ImportForm_SubTitle");
                Nav1.relativeURL   = @"../";

                GoBack1.GoBack_HelpUrl    = SharedSupport.HelpRedirect("vstskAddingCourseUsers");
                GoBack1.GoBackIncludeBack = true;
                GoBack1.GoBack_left       = "400px";
                GoBack1.GoBack_top        = "-15px";
                GoBack1.GoBack_BackURL    = "ImportForm.aspx?CourseID=" + Request.QueryString.Get("CourseID");

                AssignmentManager.Common.Functions func = new AssignmentManager.Common.Functions();
                courseId = func.ValidateNumericQueryStringParameter(this.Request, "CourseID");
                if (courseId <= 0)
                {
                    throw(new ArgumentException(SharedSupport.GetLocalizedString("Global_MissingParameter")));
                }

                if (!SharedSupport.SecurityIsAllowed(courseId, SecurityAction.USER_ADD))
                {
                    // Note that Redirect ends page execution.
                    Response.Redirect(@"../Error.aspx?ErrorDetail=" + "Global_Unauthorized");
                }

                if (!IsPostBack)
                {
                    //clear combos
                    cboEmailAddress.Items.Clear();
                    cboFirstName.Items.Clear();
                    cboLastName.Items.Clear();
                    cboMiddleName.Items.Clear();
                    cboUniversityID.Items.Clear();
                    cboUserName.Items.Clear();
                }
                //Localize all items
                localizeLabels();

                //grab items off of the querystring - DECODE them
                uploadedFilePath    = SharedSupport.AddBackSlashToDirectory(Server.MapPath(Constants.ASSIGNMENTMANAGER_UPLOAD_DIRECTORY)) + Server.UrlDecode(Request.QueryString.Get("File"));
                delimitingCharacter = Server.UrlDecode(Request.QueryString.Get("Char"));

                //Create an instance of the dataset
                System.Data.DataSet ds = new System.Data.DataSet();

                //populate the combo boxes with items from the delimited file
                if (delimitingCharacter != "" && delimitingCharacter.Length < 2)
                {
                    //Parse first line of file into dataset using delimiting character specified.
                    ds = SharedSupport.ParseDelimitedFile(uploadedFilePath, delimitingCharacter, 1);
                    //throw new System.IO.FileNotFoundException(SharedSupport.GetLocalizedString("User_UploadFileNotFound"));
                }
                else
                {
                    throw(new ArgumentException(SharedSupport.GetLocalizedString("Global_MissingParameter")));
                }

                System.Data.DataSet   dsNew = new System.Data.DataSet();
                System.Data.DataTable dtNew = dsNew.Tables.Add();
                dtNew.Columns.Add();
                for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
                {
                    System.Data.DataRow drNew = dtNew.NewRow();
                    drNew[0] = ds.Tables[0].Rows[0][i].ToString();
                    dtNew.Rows.Add(drNew);
                }

                //populate combos
                if (!Page.IsPostBack)
                {
                    for (int i = 0; i < dsNew.Tables[0].Rows.Count; i++)
                    {
                        int      dropdownIndex = i + 1;
                        ListItem newListItem   = new ListItem(dsNew.Tables[0].Rows[i][0].ToString(), dropdownIndex.ToString());
                        cboEmailAddress.Items.Add(newListItem);
                        cboFirstName.Items.Add(newListItem);
                        cboLastName.Items.Add(newListItem);
                        cboMiddleName.Items.Add(newListItem);
                        cboUniversityID.Items.Add(newListItem);
                        cboUserName.Items.Add(newListItem);
                    }
                }

                txtImportedFileLocation.Text = uploadedFilePath;
            }
            catch (Exception ex)
            {
                Nav1.Feedback.Text = ex.Message.ToString();
            }
        }
        private void btnImportRecords_Click(object sender, System.EventArgs e)
        {
            try
            {
                Nav1.Feedback.Text = String.Empty;
                //Validate delimiting character not blank
                if (delimitingCharacter == String.Empty)
                {
                    Nav1.Feedback.Text = SharedSupport.GetLocalizedString("AdminImport_ChooseDelimitingChar");
                    return;
                }

                System.Data.DataSet dsuser = SharedSupport.ParseDelimitedFile(uploadedFilePath, delimitingCharacter);
                //Grab the column order from the drop downs and put into string array

                int[] columns = new int[6];

                if (!cboLastName.SelectedIndex.Equals(0) && !cboLastName.SelectedIndex.Equals(-1))
                {
                    if (!checkMultipleColumn(columns, cboLastName.SelectedIndex))
                    {
                        columns[0] = cboLastName.SelectedIndex;
                    }
                    else
                    {
                        throw new ApplicationException(SharedSupport.GetLocalizedString("AdminImport_ColumnOnce"));
                    }
                }
                else
                {
                    //throw required field error.
                    throw new ApplicationException(SharedSupport.GetLocalizedString("AdminImport_MissingLastName"));
                }
                if (!cboFirstName.SelectedIndex.Equals(0) && !cboFirstName.SelectedIndex.Equals(-1))
                {
                    if (!checkMultipleColumn(columns, cboFirstName.SelectedIndex))
                    {
                        columns[1] = cboFirstName.SelectedIndex;
                    }
                    else
                    {
                        throw new ApplicationException(SharedSupport.GetLocalizedString("AdminImport_ColumnOnce"));
                    }
                }
                else
                {
                    //throw required field error.
                    throw new ApplicationException(SharedSupport.GetLocalizedString("AdminImport_MissingFirstName"));
                }
                if (!cboMiddleName.SelectedIndex.Equals(0) && !cboMiddleName.SelectedIndex.Equals(-1))
                {
                    if (!checkMultipleColumn(columns, cboMiddleName.SelectedIndex))
                    {
                        columns[2] = cboMiddleName.SelectedIndex;
                    }
                    else
                    {
                        throw new ApplicationException(SharedSupport.GetLocalizedString("AdminImport_ColumnOnce"));
                    }
                }
                else
                {
                    columns[2] = -1;
                }
                if (!cboEmailAddress.SelectedIndex.Equals(0) && !cboEmailAddress.SelectedIndex.Equals(-1))
                {
                    if (!checkMultipleColumn(columns, cboEmailAddress.SelectedIndex))
                    {
                        columns[3] = cboEmailAddress.SelectedIndex;
                    }
                    else
                    {
                        throw new ApplicationException(SharedSupport.GetLocalizedString("AdminImport_ColumnOnce"));
                    }
                }
                else
                {
                    //throw required field error.
                    throw new ApplicationException(SharedSupport.GetLocalizedString("AdminImport_MissingEmail"));
                }
                if (!cboUniversityID.SelectedIndex.Equals(0) && !cboUniversityID.SelectedIndex.Equals(-1))
                {
                    if (!checkMultipleColumn(columns, cboUniversityID.SelectedIndex))
                    {
                        columns[4] = cboUniversityID.SelectedIndex;
                    }
                    else
                    {
                        throw new ApplicationException(SharedSupport.GetLocalizedString("AdminImport_ColumnOnce"));
                    }
                }
                else
                {
                    //throw required field error.
                    throw new ApplicationException(SharedSupport.GetLocalizedString("AdminImport_MissingID"));
                }
                if (!cboUserName.SelectedIndex.Equals(0) && !cboUserName.SelectedIndex.Equals(-1))
                {
                    if (!checkMultipleColumn(columns, cboUserName.SelectedIndex))
                    {
                        columns[5] = cboUserName.SelectedIndex;
                    }
                    else
                    {
                        throw new ApplicationException(SharedSupport.GetLocalizedString("AdminImport_ColumnOnce"));
                    }
                }
                else
                {
                    //throw required field error.
                    throw new ApplicationException(SharedSupport.GetLocalizedString("AdminImport_MissingUserName"));
                }

                //Make sure that each column is only choosen once.
                //Grab the userId from the cookie
                int    UserID        = SharedSupport.GetUserIdentity();
                int    importErrors  = 0;
                int    importSuccess = 0;
                string importID      = System.Guid.NewGuid().ToString();
                for (int i = 0; i < dsuser.Tables[0].Rows.Count; i++)
                {
                    try
                    {
                        string userName = dsuser.Tables[0].Rows[i][columns[5] - 1].ToString();
                        // Does the user already exist?
                        UserM userByName = UserM.LoadByUserName(userName);
                        if (userByName.IsValid)
                        {
                            throw new Exception(SharedSupport.GetLocalizedString("User_UserNameMustBeUnique"));
                        }
                        UserM user = new UserM();
                        user.LastName  = dsuser.Tables[0].Rows[i][columns[0] - 1].ToString();
                        user.FirstName = dsuser.Tables[0].Rows[i][columns[1] - 1].ToString();
                        if (!columns[2].Equals(-1))
                        {
                            user.MiddleName = dsuser.Tables[0].Rows[i][columns[2] - 1].ToString();
                        }
                        user.EmailAddress      = dsuser.Tables[0].Rows[i][columns[3] - 1].ToString();
                        user.UniversityID      = dsuser.Tables[0].Rows[i][columns[4] - 1].ToString();
                        user.UserName          = userName;
                        user.LastUpdatedUserID = UserID;
                        user.LastUpdatedDate   = DateTime.Now;
                        user.ChangedPassword   = false;
                        // create but do not mail out password.
                        user.Create(false);
                        if (!user.IsInCourse(courseId))
                        {
                            user.ImportToCourse(courseId, importID);
                        }
                        importSuccess++;
                    }
                    catch
                    {
                        importErrors++;
                    }
                }

                //Delete imported file
                System.IO.File.Delete(uploadedFilePath);
                //Redirect to Results page.
                Response.Redirect("Results.aspx?CourseID=" + courseId.ToString() + "&ImportID=" + importID + "&Success=" + importSuccess + "&Errors=" + importErrors + "&Expected=" + dsuser.Tables[0].Rows.Count, false);
            }
            catch (Exception ex)
            {
                Nav1.Feedback.Text = SharedSupport.GetLocalizedString("AdminImport_GenericError");
            }
        }