private void btnOpen_Click(object sender, EventArgs e) //Event handler for when the open button is clicked { string filePath = listBox.GetItemText(listBox.SelectedItem); //Assigns the currently selected directory to a string variable FtpClient clientFTP = new FtpClient(); clientFTP.Host = "ftp://82.10.84.171"; clientFTP.Port = 54443; clientFTP.Credentials.UserName = "******"; clientFTP.Credentials.Password = "******"; clientFTP.DataConnectionReadTimeout = 2147483645; clientFTP.ConnectTimeout = 2147483645; clientFTP.DataConnectionConnectTimeout = 2147483645; clientFTP.ReadTimeout = 2147483645; clientFTP.Connect(); if (clientFTP.FileExists($@"\{filePath}")) //Checks the quiz exists in the dirctory on the FTP server { string csvPath = Path.GetTempPath() + "tempcsv.csv"; clientFTP.DownloadFile(csvPath, $@"\{filePath}"); //Downloads the selected quiz to a temporary CSV file QuizForm quizForm = new QuizForm(1, Global.CSVToArray(csvPath)); //Initialises a QuizForm form with the passed data that this is View form type and the list of string array data from the CSV path quizForm.Show(); //Shows the QuizFOrm form File.Delete(csvPath); //Deletes the temporary CSV file } else { MessageBox.Show("File Not Found!"); //Informs the user that the file was not found } clientFTP.Disconnect(); }
private void btnOpen_Click(object sender, EventArgs e) //Event handler for when the open button is clicked { FtpClient clientFTP = new FtpClient(); clientFTP.Host = "ftp://82.10.84.171"; clientFTP.Port = 54443; clientFTP.Credentials.UserName = "******"; clientFTP.Credentials.Password = "******"; clientFTP.DataConnectionReadTimeout = 2147483645; clientFTP.ConnectTimeout = 2147483645; clientFTP.DataConnectionConnectTimeout = 2147483645; clientFTP.ReadTimeout = 2147483645; clientFTP.Connect(); string csvPath = Path.GetTempPath() + "tempcsv.csv"; if (clientFTP.FileExists($@"/Students/{Global.currentUser}/{listbox.GetItemText(listbox.SelectedItem)}")) //Ensure that the file selected still exists { clientFTP.DownloadFile(csvPath, $@"/Students/{Global.currentUser}/{listbox.GetItemText(listbox.SelectedItem)}"); //If it does QuizForm studentQuiz = new QuizForm(0, Global.CSVToArray(csvPath)); //Creates a temporary csv, converts that to a list of string arrays, passes into an instantiated QuizForm form this.Close(); //Close this form } else //Otherwise { MessageBox.Show("Error, quiz is no longer in your depository"); //Inform user the file no longer exists in their Depository } }
private void btnCreate_Click(object sender, EventArgs e) //Event handler for when the create button is clicked { QuizForm quizForm = new QuizForm(2, null); //Initialises a QuizForm form with the type Create, and null list of string arrays }