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

Expert Comment

Comment Utility
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
Comment Utility
hi ,
try this

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

it will give you the unique file names
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
you can always check if File.Exist if you have doubts

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now