protected void UploadExcelFileButton_Click(object sender, EventArgs e) { Util util = new Util(); Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID]; if (util.CheckSessionTimeout(State, Response, "../../Default.aspx")) return; if (this.FileUpload1.PostedFile != null) { // get the file HttpPostedFile file = this.FileUpload1.PostedFile; // check the length of the file if (file.ContentLength > 0) { string app_name = ((Hashtable)HttpRuntime.Cache[Session.SessionID])["SelectedApp"].ToString(); string application_id = util.GetAppID((Hashtable)HttpRuntime.Cache[Session.SessionID]); // get the Excel tables ExcelUtil excel_util = new ExcelUtil(); DataTable[] excel_tables = excel_util.GetDataTablesFromExcelStream(file.InputStream); if (excel_tables == null || excel_tables.Length == 0) { ErrorMessage.Text = "The file: '" + file.FileName + "' could not be processed as an Excel file."; return; } DataTable excel_table = excel_tables[0]; //string update_type = UploadType.SelectedIndex == 0 ? "add" : "replace"; string update_type = "replace"; //check on user limit long max_users = util.GetMaxUsers((Hashtable)HttpRuntime.Cache[Session.SessionID]); if (max_users == 0 || max_users > 1000L) { ErrorMessage.Text = "No paid ViziApps service allows any production credentials"; return; } if (excel_table.Rows.Count - 1 > max_users) { ErrorMessage.Text = "The number of credentials in your Credentials File exceed the limit of the paid ViziApps service"; return; } StringBuilder errors = new StringBuilder("The file was successfully uploaded. Close this window."); util.UpdateUserCredentials((Hashtable)HttpRuntime.Cache[Session.SessionID], application_id, excel_table.Rows, update_type); ErrorMessage.Text = errors.ToString(); } else { ErrorMessage.Text = "The file: '" + file.FileName + "' is empty."; } } }