Как мне скопировать test.pdf из текущей папки в C:exfolder
Я знаю простой способ копирования на C#, но мне нужен код, который работает для любых папок, в которых находится exe-файл.
Я был сбит с толку, потому что, когда хотел использовать текущий путь к папке, в Visual Studio 2008 были ошибки
потому что я использовал:
string fileName = "test_log.LDF";
string sourcePath = @ + Application.StartupPath;
string targetPath = @"C:\honar2";
// Use Path class to manipulate file and directory paths.
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
// To copy a folder's contents to a new location:
// Create a new target folder, if necessary.
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
}
System.IO.File.Copy(sourceFile, destFile, true);
Подробнее здесь: https://stackoverflow.com/questions/313 ... in-c-sharp