Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
How To create a unique number everytime
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.csharp.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Bill
I need to create a temporary file on the file system. I have over 5000 users.

What's the best method to ensure uniqueness?

Thanks

Bill
Reply to this message...
Vote that this is a GOOD answer...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
Peter Bromberg [C# MVP] (VIP)
Guid is definitely preferable. If you need a "number" (e.g. 0123456789) you
could
try System.DateTime.Now.Ticks.ToString()
Peter
"Bill" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
gabriel
[Original message clipped]

Depends on the application. You might get away with just starting at #1.
You might get away with having an array of booleans (or a table of booleans
in a database), one starting at #1 and so on. Or you might have to
generate a random number and keep retrying till you hi one that's not in
use.

It all depends on how often you need to do this, what the load is (are your
5k users concurrent?), and so on.

This can be very fast if you plan it right. If you go the random number
route, use a hige range (ie, a number between 1 and 1,000,000) so that
conflicts are very unlikely.

--
gabriel
Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Pete Davis
Guid myGuid = Guid.NewGuid();
myGuid.ToString(N);

You now have a unique 32-character hex string. Have fun.

Pete

--
http://www.petedavis.net

"gabriel" <Click here to reveal e-mail address> wrote in message
news:b86e7$402ab8f1$437be569$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
    
Mike
Many THANKS!
Reply to this message...
Vote that this is a GOOD answer...
 
Email Archiving and Email Filing - what’s the difference?
Web-based task/todo list management
 
    
Martin Maat
"gabriel" <Click here to reveal e-mail address> wrote in message
news:b86e7$402ab8f1$437be569$Click here to reveal e-mail address...
[Original message clipped]

Guid.NewGuid().ToString()

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Mike
Many THANKS!
----- Martin Maat wrote: -----

"gabriel" <Click here to reveal e-mail address> wrote in message
news:b86e7$402ab8f1$437be569$Click here to reveal e-mail address...
[Original message clipped]

Guid.NewGuid().ToString()

Reply to this message...
Vote that this is a GOOD answer...
 
Open source windows
The Law Society’s guidelines on e-mail management
 
    
Doug Erickson [MS] (VIP)
Guid.NewGuid() will produce a random GUID. A GUID is a large, unique
hex-based value suitable for database and registry keys.

For example:

Guid myKey = Guid.NewGuid();
Console.WriteLine("New Key: {0}", myKey.ToString());

Hope this helps!

--
----
Doug Erickson [MSFT], Platform SDK UA
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2003 Microsoft Corporation. All rights
reserved.

"gabriel" <Click here to reveal e-mail address> wrote in message
news:b86e7$402ab8f1$437be569$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Bill Styles
"Bill" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address
[Original message clipped]

How about
string temppath=System.IO.Path.GetTempFileName();

--
C# newbie... posts are probably inaccurate, inelegant or both

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Bill
Dear Mr. Styles:

Many many thanks. I found your approach to be the safest and easiest.

Thanks

Bill

----- Bill Styles wrote: -----

"Bill" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address
[Original message clipped]

How about
string temppath=System.IO.Path.GetTempFileName();

--
C# newbie... posts are probably inaccurate, inelegant or both

Reply to this message...
Vote that this is a GOOD answer...
 
Google Docs… no.
Twitter Elite
 
 
System.Console
System.DateTime
System.Guid
System.IO.Path




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734