C # create a temporary file

Source: Internet
Author: User
1. Only one temporary file can be created in the temporary file and the complete path of the file is returned. // Only one temporary file can be created in the temporary file and the complete path of the file is returned:
// C: \ Documents ents and Settings \ yourname \ Local Settings \ temp \ tmp3e6. tmp
System. Io. Path. gettempfilename ();


2. Return the complete path of the file with the unique name in the Temporary Folder Based on the file name. ///   <Summary>
/// Return the complete path of the file with the unique name in the Temporary Folder Based on the file name.
/// Format: company document (1).doc,company document (2).doc
///   </Summary>
Public   Static   String Gettemppathfilename ( String Filename)
{
// Temporary system folder
String Temppath = Path. gettemppath ();
// File completion path
Filename = Temppath + Path. getfilename (filename );
// File Name
String Filenamewithoutext =  
Path. getfilenamewithoutextension (filename );
// Extension
String Fileext = Path. getextension (filename );
Int I =   0 ;
While (File. exists (filename ))
{
// Generate a file name like this: company document (1).doc,company document (2).doc
Filename = Temppath + Filenamewithoutext +  
String . Format ( " ({0 }) " , ++ I) + Fileext;
}
Return Filename;
}

3. Return the path of the temporary folder of the system.//Return the path of the temporary folder of the system:
//C: \ Documents ents and Settings \ yourname \ Local Settings \ temp \
System. Io. Path. gettemppath ();

4. Return a random file name.//Returns a random file name, 41ceduv1. UWV.
System. Io. Path. getrandomfilename ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.