0

Path.GetTempFileName is pretty close to what i want. But i wouldnt want to restart the machine and lose these files (as they would be temp). What i need is a unique filename. Whats the best way to do it? I was thinking inserting a key into a db, commit them pulling it but i dont think its a good idea.

I was thinking of using a random number but i am always worried about using random numbers when on a server. Since two request can occur at the same time getting the same number (assuming i dont lock it which would make it slow). So, what can i do?

I plan to use the filename so i can take file(s) from the users post request and save them to a file. Which i then put into a queue to be processed which may be immediately, a second from now or minutes/hours if something has gone wrong.

2 Answers 2

1

Store filenames using GUID?

If you are expecting a lot of files. I replace guid dashes to make it into a directory structure.

d524532e-8337-422f-925c-14500972c843.jpg

becomes

\d524532e\8337\422f\925c\14500972c843.jpg
Sign up to request clarification or add additional context in comments.

Comments

1

How about a Guid:

var appData = Server.MapPath("~/"App_Data);
var filename = Path.Combine(appData, string.Format("{0}.tmp", Guid.NewGuid()));

or some timestamp or something:

var appData = Server.MapPath("~/"App_Data);
var filename = Path.Combine(appData, string.Format("{0:dd_MM_yyyy_fffff}.tmp", DateTime.Now));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.