• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 737
  • Last Modified:

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.
0
cybeh
Asked:
cybeh
1 Solution
 
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
 
VeerabhadraiahhvCommented:
hi ,
try this

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

it will give you the unique file names
0
 
Éric MoreauSenior .Net ConsultantCommented:
you can always check if File.Exist if you have doubts
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now