Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Unique Filename
Message
From
14/10/2005 11:12:46
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Miscellaneous
Thread ID:
01058916
Message ID:
01059169
Views:
12
Thanks, that is what I needed. Sometimes it is difficult to locate the correct method in the .NET framework. I would have beleived it would have been in the System.IO.File namespace, not the .Path.

>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
Greg Reichert
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform