Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Unique Filename
Message
De
14/10/2005 05:26:52
 
 
À
13/10/2005 18:15:24
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Divers
Thread ID:
01058916
Message ID:
01059053
Vues:
14
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform