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

Posted on 2009-04-05
Last Modified: 2013-11-26

We will be using this method
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.
Question by:cybeh
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 24074523
According to Microsoft it manages the file name uniquely for u
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

Accepted Solution

Veerabhadraiahhv earned 500 total points
ID: 24074527
hi ,
try this

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

it will give you the unique file names
LVL 70

Expert Comment

by:Éric Moreau
ID: 24075590
you can always check if File.Exist if you have doubts

Featured Post

Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor ( Top Charts is a view in which you can set seve…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question