Alex Rivera | Logout

Where to write my temporary files to?

Asked 2011-01-13T17:02:46.013
15

I have numerous byte[] representing pdf's. Each byte array needs to be loaded at the start of the application and shown as a thumbnail on my gui. So far I have managed to write the files to a temp location using:

System.IO.Path.GetTempPath();

Then using this path I get all pdf files, write them using

System.IO.File.WriteAllBytes(fileName, arrayOfPdfs[i]);

and then navigate to that directory, get all pdf files and turn them in to thumbnails in my app.

The thing is I only want the pdfs I have just put in the temp location only, so how else can I store the pdfs, or even where else can I store them so I know when I come to turn them in to thumbnails, the files I am reading are the ones I have just written? This is so I can be sure the user is only looking at the relevant pdfs that relate to their search on my system.

Thanks.

Edit
Report

3 Answers

28

Build a randomly named directory in the base temporary directory:

string directoryName = Path.GetRandomFileName();
Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), directoryName));

Store your files in there.

answered 2011-01-13T17:06:45.063
1

Could you just create a subdirectory in the Temp path?

string dir = System.IO.Path.GetTempPath() + "\\<searchstring>;

answered 2011-01-13T17:06:14.060
0

Use Path.GetTempFileName and keep track of the temporary files that you've allocated during the session. You should clean up when your program exits.

answered 2011-01-13T17:05:53.627

Your Answer