C # Determines if files and folders exist and creates
Using System;
Using System.Data;
Using System.Configuration;
Using System.Collections;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using System.IO;
public partial class Default3:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
Showpic.visible = false;//initialization does not appear
Showtext.visible = false;//initialization does not appear
}
protected void Button1_Click (object sender, EventArgs e)
{
if (Directory.Exists (Server.MapPath ("~/upimg/hufu")) = = false)//if not saved
When you create the file folder
{
Directory.CreateDirectory (Server.MapPath ("~/upimg/hufu"));
}
Directory.delete (Server.MapPath ("~/upimg/hufu"), true);//delete folder to
and the subdirectory files in the folder
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 ();//Get Uploaded
Size of File
String type = getfiles.postedfile.contenttype;//Gets the mime of the uploaded file
string postfix = name. Substring (name. LastIndexOf (".") + 1);//Get Uploaded
Suffix of 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 large
Small: "+ size +" KB "+" <br> "+" file type: "+ type +" <br> "+" to store the actual path is: "+
Ipath
}
Else
{
showpic.visible = false;//Hidden pictures
Getfiles.saveas (Fpath);//Because it is not a picture file, so it exists upfile this
Folder
Showtext.text = "The file name you uploaded is:" + name + "<br>" + "file large
Small: "+ size +" KB "+" <br> "+" file type: "+ type +" <br> "+" to store the actual path is: "+
Fpath;
}
}
}
}
C # Determines if files and folders exist and creates