Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Unique Filename
Message
From
14/10/2005 05:26:52
 
 
To
13/10/2005 18:15:24
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Miscellaneous
Thread ID:
01058916
Message ID:
01059053
Views:
9
Greg,

You could try using the following from the System.IO namespace.
string TempFilename = System.IO.Path.GetTempFileName();
However this will return a unique temporary filename but it also creates an empty file on disk (zero bytes) which is okay if you are prepared to manage deletion or re-use yourself. This method is actually making the following call to managed code.
[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
internal static extern uint GetTempFileName(string tmpPath, string prefix, uint uniqueIdOrZero, StringBuilder tmpFileName);

public static string GetTempFileName()
{
   string text1 = Path.GetTempPath();
   StringBuilder builder1 = new StringBuilder(260);
   uint num1 = Win32Native.GetTempFileName(text1, "tmp", 0, builder1);

   if (num1 == 0)
   {
         __Error.WinIOError();
   }

   return builder1.ToString();
}
However I would not use this if your requirements involve multiple threads and avoiding race conditions then Cetin's idea of using a GUID is a much more reliable solution.

Regards
Neil
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform