protected void Button1_Click (object sender, EventArgs e)
{
if (Directory.Exists (Server.MapPath ("~/upimg/hufu")) = = false)//create a file folder if it does not exist
{
Directory.CreateDirectory (Server.MapPath ("~/upimg/hufu"));
}
Directory.delete (Server.MapPath ("~/upimg/hufu"), true);//delete folders and subdirectories in folders, files
Determine the existence of a file
if (File.exists (Server.MapPath ("~/upimg/data.html")))
{
Response.Write ("Yes");
exists file
}
Else
{
Response.Write ("No");
File does not exist
File.create (MapPath ("~/upimg/data.html"));//Create the file
}
String name = getfiles.filename;//Gets the name of the uploaded file
String size = GetFiles.PostedFile.ContentLength.ToString ();//Gets the size of the uploaded file
String type = getfiles.postedfile.contenttype;//Gets the mime of the uploaded file
string postfix = name. Substring (name. LastIndexOf (".") + 1);//Get the suffix of the uploaded file
String ipath = Server.MapPath ("upimg") + "\ \" + name;//get the actual path of the file
String fpath = Server.MapPath ("upfile") + "\ \" + Name;
String Dpath = "upimg\\" + name;//determine the virtual path to write to the database
Showpic.visible = true;//Active
Showtext.visible = true;//Active
Determine 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 (Ipath);
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;//Hidden pictures
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>" + "The actual path for storage is:" + fpath;
}
http://www.cnblogs.com/szytwo/archive/2012/03/22/2411703.html
C # Determines whether files and folders exist and is created (C # determines the folder exists)