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)!