How to ensure System.IO.Path.GetTempFileName() will not give repeated filename?

Hi,

We will be using this method
System.IO.Path.GetTempFileName()
to generate around 200 files inside a function. May I know how can we ensure that the file name are not repeated so that will will not be overwrite?

Please advice.
LVL 1
cybehAsked:
Who is Participating?
 
VeerabhadraiahhvConnect With a Mentor Commented:
hi ,
try this

string fileName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString()

it will give you the unique file names
0
 
CraigLazarCommented:
Hi,
According to Microsoft it manages the file name uniquely for u
http://msdn.microsoft.com/en-us/library/system.io.path.gettempfilename(vs.71).aspx
What u can do to make sure there are no duplications is either test if there is a file already with that name in th folder using file.exists function, or on the return string from function GetTempFileName() - u can then save the file and adjust the file name and add at the end for examle the hour/minute/second/millisecond paramter to make sure the names are different to each file (HH:mm:ss mm )
 hope this helps
0
 
Éric MoreauSenior .Net ConsultantCommented:
you can always check if File.Exist if you have doubts
0
All Courses

From novice to tech pro — start learning today.