C # creates a temporary file (reprint)

1. can only create a temporary file in a temporary file and returns the full path of the file

// can only create a temporary file in a temporary file and returns the full path to the file:
 // C: \ Documents and Settings \ YourName \ Local Settings \ the Temp \ tmp3E6.tmp 
System.IO.Path.GetTempFileName ();
View Code

 2. The full path to the file name returned in the temporary folder uniquely named file

///  <Summary> 
/// The return to the full path name of the file in the temporary folder uniquely named file
 /// form: Corporation document (1) .doc, corporate documents (2) .doc
 ///  </ Summary> 
publicstaticstringGetTempPathFileName (stringfileName) 
{ 
 // the system temporary folder 
 stringtempPath = Path.GetTempPath ();
  // complete file path 
 fileName = temppath + Path.GetFileName (fileName);
  // file name 
 stringfileNameWithoutExt = 
 Path.GetFileNameWithoutExtension (fileName) ; 
 // extension 
 stringfileExt = Path.GetExtension (fileName); 
 Inti = 0 ;
  the while (the File.Exists (fileName)) 
 {
 // generates a file name like this: corporate documents (1) .doc, corporate documents (2) .doc 
 fileName = temppath fileNameWithoutExt + + String .Format ( " ({0}) " , ++ I) + FileExt; 
 } 
 returnfileName; 
}
 
View Code

3. Return to the path system temporary folder

// path back to the system temporary folder:
 // C: \ Documents and Settings \ YourName \ Local Settings \ the Temp \ 
System.IO.Path.GetTempPath ();
View Code

4. returns a random file name

// returns a random file name: 41ceduv1.uwv 
System.IO.Path.GetRandomFileName ();
View Code

 

 

Guess you like

Origin www.cnblogs.com/blogpro/p/11463279.html