Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-04-05
3
Medium Priority
?
717 Views
Last Modified: 2013-11-26
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
Comment
Question by:cybeh
[X]
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
3 Comments
 
LVL 4

Expert Comment

by:CraigLazar
ID: 24074523
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
 
LVL 4

Accepted Solution

by:
Veerabhadraiahhv earned 2000 total points
ID: 24074527
hi ,
try this

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

it will give you the unique file names
0
 
LVL 70

Expert Comment

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

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

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 (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). 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 …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

719 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