Question: How in the name of the created document, insert the time spent on its creation?
string fileName = "prefix" + "_" + "время создания документа в формате ЧЧММССННН: ЧЧ" + "" + "_" + string.Format("{0:yyyyMMdd}", DateTime.Now) + ".xml"; Question: How in the name of the created document, insert the time spent on its creation?
string fileName = "prefix" + "_" + "время создания документа в формате ЧЧММССННН: ЧЧ" + "" + "_" + string.Format("{0:yyyyMMdd}", DateTime.Now) + ".xml"; // Запускаем таймер Stopwatch makeFile = Stopwatch.StartNew(); // Создаем временный файл string tmpFile = Path.GetTempFileName(); // Что-то с ним делаем using (StreamWriter sw = new StreamWriter(tmpFile)) { for (int i = 0; i < 1000; i++) { sw.WriteLine(i.ToString()); } } // Останавливаем таймер makeFile.Stop(); // Берем полученный интервал времени (время затраченное на создание) TimeSpan ts = makeFile.Elapsed; // Дата создания файла DateTime dt = DateTime.Now; // Имя файла с временем, затраченным на создание string fileName1 = string.Format(@"C:\Users\admin\Documents\NewFile_{0:D2}-{1:D2}-{2:D2}_{3:D2}.txt", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds); // Имя файла с временем создания string fileName2 = string.Format(@"C:\Users\admin\Documents\NewFile_{0:D2}-{1:D2}-{2:D2}_{3:D2}.txt", dt.Hour, dt.Minute, dt.Second, dt.Millisecond); // Перемещаем и переименовываем временный файл File.Move(tmpFile, fileName1); // File.Move(tmpFile, fileName2); Source: https://ru.stackoverflow.com/questions/580527/
All Articles