Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void saveButton_Click(object sender, EventArgs e)
- {
- if (saveFileDialog1.ShowDialog() == DialogResult.OK)
- {
- pathToSave = saveFileDialog1.FileName;
- FileInfo newFile = new FileInfo(pathToSave);
- if (newFile.Exists)
- {
- if (MessageBox.Show("Файл с таким именем уже существует. Хотите перезаписать?", "Сообщение", MessageBoxButtons.YesNo)
- == DialogResult.Yes)
- {
- try
- {
- SaveFile.SaveThisInFile(pathToSave, allWeHave);
- }
- catch (Exception)
- {
- MessageBox.Show("Что-то пошло не так");
- }
- }
- } else
- {
- File.Create(pathToSave);
- try
- {
- SaveFile.SaveThisInFile(pathToSave, allWeHave);
- }
- catch (Exception)
- {
- MessageBox.Show(pathToSave);
- }
- }
- }
- }
- public class SaveFile
- {
- public static void SaveThisInFile(string path, List<Tonnel> listToSave)
- {
- string[] list = new string[listToSave.Count + 1];
- list[0] = $"ROWNUM;Name;Tunnel;AdmArea;District;Longitude_WGS84;Latitude_WGS84;global_id;";
- for (int i = 1; i <= listToSave.Count + 1; ++i)
- {
- list[i] = "";
- list[i] = $"{i};\"{listToSave[i].Name}\";\"{listToSave[i].Tunnel};{listToSave[i].District.AdmArea}\";\"{listToSave[i].District.Distr}\";\"{listToSave[i].Longtitude_WGS84}\";\"{listToSave[i].Latitude_WGS84}\";\"{listToSave[i].Global_id}\";";
- }
- File.WriteAllLines(path, list);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement