This article describes the method of C# to determine whether a folder exists or not and create a folder. Share it for your reference, as follows:
protected void Button1_Click(object sender, EventArgs e) { if ((("~/upimg/hufu")) == false)//Create a file folder if it does not exist { (("~/upimg/hufu")); } //(("~/upimg/hufu"), true);//Delete folders and subdirectories in folders, files //Judge the existence of the file if ((("~/upimg/"))) { ("Yes"); //The file exists } else { ("No"); //The file does not exist (MapPath("~/upimg/"));//Create this file } string name = ;//Get the name of the uploaded file string size = ();//Get the size of the uploaded file string type = ;//Get the MIME of the uploaded file string postfix = ((".") + 1);//Get the suffix of the uploaded file string ipath = ("upimg") +"\\"+ name;//Get the actual path to the file string fpath = ("upfile") + "\\" + name; string dpath = "upimg\\" + name;//Judge the virtual path written to the database = true;//activation = true;//activation //Judge file format if (name == "") { ("<script>alert('Uploading files cannot be empty')</script>"); } else{ if (postfix == "jpg" || postfix == "gif" || postfix == "bmp" || postfix == "png") { (ipath); = dpath; = "The image you uploaded is:" + name + "<br>" + "File Size:" + size + "KB" + "<br>" + "File Type:" + type + "<br>" + "The actual path to storage is:" + ipath; } else { = false;//Hide pictures (fpath);//Since it is not a picture file, it is transferred to the upfile folder = "The file name you uploaded is:" + name + "<br>" + "File Size:" + size + "KB" + "<br>" + "File Type:" + type + "<br>" + "The actual path to storage is:" + fpath; } } }
For more information about C# related content, please check out the topic of this site:Summary of common techniques for C# file operation》、《Summary of C# traversal algorithm and skills》、《Summary of thread usage techniques for C# programming》、《Summary of C# operation skills》、《Summary of XML file operation skills in C#》、《Tutorial on the usage of common C# controls》、《Summary of WinForm control usage》、《C# data structure and algorithm tutorial》、《Summary of C# array operation skills"and"Introduction to C# object-oriented programming tutorial》
I hope this article will be helpful to everyone's C# programming.