Aaron McKelvie
Aaron McKelvie

Reputation: 167

Where to store temporary files using a windows forms application

I have an application that downloads a file from FTP, reads the file, then deletes it (i download a temporary file because the stream gets disposed before i read the end of the data and i get an exception) and I was wondering what is the programming convention for storing temporary files? Basically right now I just download the file to the desktop directory (testing phase still) so it pops up on the desktop for a second while it's read then deleted.

Upvotes: 1

Views: 1168

Answers (1)

The Vermilion Wizard
The Vermilion Wizard

Reputation: 5415

Use System.IO.Path.GetTempFileName() to get a randomly named file in the system's temp directory. Download to there.

Be sure to use System.IO.File.Delete() when you're done with it!

https://msdn.microsoft.com/en-us/library/system.io.path.gettempfilename%28v=vs.110%29.aspx

Upvotes: 5

Related Questions