Link to home
Start Free TrialLog in
Avatar of cybeh
cybeh

asked on

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.
Avatar of CraigLazar
CraigLazar

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
ASKER CERTIFIED SOLUTION
Avatar of Veerabhadraiahhv
Veerabhadraiahhv
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Éric Moreau
you can always check if File.Exist if you have doubts