tags:

views:

146

answers:

4

HI, I need to create unique folder name to be created in the user local App data path, I cannot generate folder names using MD5 and other algorithms as the result has in valid characters for folder name. Is there a way from which I can generate folder names from a given file path or name ?

A: 

Why not just remove, replace or encode those invalid characters as valid ones?

David
+7  A: 

Can't you just use a Guid?

String folderName = Guid.NewGuid().ToString();
Simon P Stevens
Even better, use `ToString("D")` to get rid of the hyphens.
LukeH
+3  A: 

Why is an MD5 like

A4-B7-81-7F...

invalid? Have a look at the BitConverter-class

tanascius
A: 

How fast are you willing to get those folders created ? I'm saying this because you could use the system time, in milliseconds, to name those unique folders. If you want to avoid the possibility of having two or more folders on the very same time, concatenate some string at the end.

nairdaen
this isn't unique per string, it's unique per time
Ron Warholic