C # Implements sample code that determines whether a folder exists or not and creates a folder

Source: Internet
Author: User
This article mainly introduces C # to determine the existence of folders and create a folder method, involving C # for the file and directory of the judgment and creation of operations related skills, the need for friends can refer to the following

The example in this article describes how C # implements determining whether a folder exists or not and creates a folder. Share to everyone for your reference, as follows:

protected void Button1_Click (object sender, EventArgs e) {if (Directory.Exists (Server.MapPath ("~/upimg/hufu")) = = False   )//Create the file folder {directory.createdirectory (Server.MapPath ("~/upimg/hufu") if it does not exist; }//directory.delete (Server.MapPath ("~/upimg/hufu"), true);//delete the folder and subdirectories in the folder, File//Determine the existence of the file if (file.exists (server.ma    Ppath ("~/upimg/data.html")) {Response.Write ("Yes");    There is a file} else {Response.Write ("No"); There is no file File.create (MapPath ("~/upimg/data.html"));//Create the file} string name = getfiles.filename;//Get the name of the uploaded file string s ize = GetFiles.PostedFile.ContentLength.ToString ();//Gets the size of the uploaded file string type = getfiles.postedfile.contenttype;// Gets the MIME string postfix = name of the uploaded file. Substring (name. LastIndexOf (".") + 1);//Gets the suffix of the uploaded file string ipath = Server.MapPath ("upimg") + "\ \" + name;//gets the actual path of the file string fpath = Serve   R.mappath ("upfile") + "\ \" + Name; String Dpath = "upimg\\" + name;//determines the virtual path written to the database showpic.visible = true;//activation showtext.visible = true;//Active//Determine the file format if (name = = "") {Response.Write ("<script>alert (' upload file cannot be empty ') </script>"); } else{if (postfix = = "JPG" | | postfix = = "gif" | | postfix = = "BMP" | | postfix = "png") {Getfiles.saveas (IP     ATH);     Showpic.imageurl = Dpath; Showtext.text = "The name of the image you uploaded is:" + name + "<br>" + "File Size:" + size + "KB" + "<br>" + "file type:" + type + "<br>"    + "The actual path for storage is:" + ipath;  } else {showpic.visible = false;//hides the picture Getfiles.saveas (Fpath);//Because it is not a picture file, so go to upfile this folder Showtext.text  = "The file name you uploaded is:" + name + "<br>" + "File Size:" + size + "KB" + "<br>" + "file type:" + type + "<br>" + "to store the actual path:"    + Fpath; }   }}

The above is the C # implementation to determine the existence of folders and create a folder sample code content, more relevant content please follow topic.alibabacloud.com (www.php.cn)!

  • 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.