The essence of the program is that it downloads a text document from the server, overwrites it and sends it to the server again. It works stably on my computer (Windows 8), another person gets this error on a computer (Windows 7), and there is no answer.txt in the place where the file should be uploaded (this should be the name and extension), instead of it the file appears with the name Task and an extension unknown to me (I forgot to record). There is an Internet connection. Help solve this problem, I will be very grateful
file download method:
private string[] DownloadFileFromServer(string from, string to) { try { using (WebClient client = new WebClient()) { client.DownloadFile(from, to); } string[] file = File.ReadAllLines(to); File.Delete(to); return file; } catch (Exception a) { return null; } } File upload method:
private void UploadFileToServer(string from, string to) // отправка файла { using (WebClient client = new WebClient()) { Uri ftp = new Uri("" + to); client.UploadFile(ftp.ToString(), from); File.Delete(from); } } Print () method;
public void print(int number_question) // вопросы { switch (number_question) { case 1:question_box.Text = "<text>_1"; break; case 2:question_box.Text = "<text>_2"; break; case 3:question_box.Text = "<text>_3"; break; case 4:question_box.Text = "<text>_4"; break; default: timerTask.Enabled = false; panel1.Visible = true; List<string> fail = File.ReadAllLines("backup/Backup.txt").ToList<string>(); fail.Add(date.Day + "." + date.Month + "." + date.Year + " " + date.Hour + ":" + date.Minute); fail.Add(fname + " " + name + " " + class_); fail.Add("Времени ушло: " + time); for (int i = 0; i < answer.Length; i++) { fail.Add(i + 1 + " " + answer[i]); } fail.Add(new string('-', 30)); File.WriteAllLines("backup/Backup.txt", fail); List <string> file = DownloadFileFromServer("http://fschat.ucoz.net/Results.txt", "Task").ToList<string>(); file.Add(date.Day + "." + date.Month + "." + date.Year + " " + date.Hour + ":" + date.Minute); file.Add("Времени ушло: " + time); file.Add(fname + " " + name+" "+class_); for(int i = 0; i < answer.Length; i++) { file.Add(i + 1 + ": " + answer[i]); } file.Add(Environment.NewLine); File.WriteAllLines("Results.txt", file); UploadFileToServer("Results.txt", "fschat.ucoz.net/Results.txt"); MessageBox.Show("Тестирование окончено!"); Application.Exit(); break; } } The print () method is called here.
private void button1_Click_1(object sender, EventArgs e) // вход { timerTask.Interval = 1000; timerTask.Tick += delegate (object sender_, EventArgs a) { time += 1; }; timerTask.Enabled = true; if (String.IsNullOrWhiteSpace(fname_box.Text) || String.IsNullOrWhiteSpace(name_box.Text)||String.IsNullOrWhiteSpace(class_box.Text)) MessageBox.Show("Не все поля заполнены!"); else { panel_test.Visible = true; fname = fname_box.Text; name = name_box.Text; class_ = class_box.Text; print(question); } } 