Basically, I wonder if there is a best practice when it comes to the next problem of downloading files, not just for temporary use, but ultimately for moving them to the application folder. I came across some options:
//Option 1 - Random file String tempfile = Path.GetTempFileName(); WriteData(tempfile); File.Move(tempfile, Path.Combine(Environment.CurrentDirectory, filename); //Option 2 - Temp Path + Random file name String tempfile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); WriteData(tempfile); File.Move(tempfile, Path.Combine(Environment.CurrentDirectory, filename); //Option 3 - Temp Path + real file name String tempfile = Path.Combine(Path.GetTempPath(), filename); WriteData(tempfile); File.Move(tempfile, Path.Combine(Environment.CurrentDirectory, filename); //Option 4 - Temp Application Path + Random file name String tempfile = Path.Combine(Environment.CurrentDirectory, Settings.Default.DownloadFolder, Path.GetRandomFileName()); WriteData(tempfile); File.Move(tempfile, Path.Combine(Environment.CurrentDirectory, filename); //Optioin 5 - Temp Application Path + file name String tempfile = Path.Combine(Environment.CurrentDirectory, Settings.Default.DownloadFolder, filename); WriteData(tempfile); File.Move(tempfile, Path.Combine(Environment.CurrentDirectory, filename);
Since some files are used at the time, I have no way to write the file directly to where it ends. He must go to the time domain ...
source share