C #: File/Registry/thread operations

Source: Internet
Author: User

File Operations: (file and fileinfo, the former is a static method, perform security checks, suitable for an operation) 1.1.create: 1 using System; 2 using System. collections. generic; 3 using System. componentModel; 4 using System. data; 5 using System. drawing; 6 using System. linq; 7 using System. text; 8 using System. threading. tasks; 9 using System. windows. forms; 10 using System. IO; // This namespace contains class 11 12 namespace WindowsFormsApplication2 13 {14 public partial class Fo Rm1: Form 15 {16 public Form1 () 17 {18 InitializeComponent (); 19} 20 21 private void Form1_Load (object sender, EventArgs e) 22 {23 24} 25 26 private void button#click (object sender, EventArgs e) 27 {28 // determine whether the input file address is 29 if (textBox1.Text = string. empty) 30 {31 this. toolStripStatusLabel1.Text = "Enter the file to be created next to the red dot. "; 32 errorProvider1.SetError (textBox1," Enter the File to be created "); 33} 34 else 35 {36 if (File. exists (textBox1.Text. trim () // determine whether the file 37 {toolStripStatusLabel1.Text = "already exists. ";}38 else 39 {40 File. Create (textBox1.Text); // The static method creates the File 41 toolStripStatusLabel1.Text =" the File is created successfully! "+ TextBox1.Text +" "; 42} 43 44} 45} 46 47 private void button2_Click (object sender, EventArgs e) 48 {49 if (textBox2.Text = string. empty) 50 {51 // the following two sentences are prompted: 52 this. toolStripStatusLabel1.Text = "Enter the file to be created next to the red dot. "; 53 errorProvider1.SetError (textBox1," Enter the file to be created "); 54} 55 else 56 {57 FileInfo fi = new FileInfo (textBox2.Text. trim (); // instantiate 58 if (fi. exists) // the same as above also determines that 59 {60 toolStripStatusLabel1.Text = "already Exists. "; 61} 62 else 63 {fi. Create () ;}// Create this file 64} 65} 66} 67} 

 

Related Article

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.