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 is not displayed
ShowText. Visible = false; // Initialization is not displayed
}
Protected void button#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, subdirectories, and files in folders.
// Determine the existence of the file
If (File. Exists (Server. MapPath ("~ /Upimg/Data.html ")))
{
Response. Write ("Yes ");
// File exists
}
Else
{
Response. Write ("No ");
// The file does not exist.
File. Create (MapPath ("~ /Upimg/Data.html "); // create the file
}
String name = GetFiles. FileName; // get the name of the uploaded file
String size = GetFiles. PostedFile. ContentLength. ToString (); // obtain the size of the uploaded file.
String type = GetFiles. PostedFile. ContentType; // obtain the MIME of the uploaded file
String postfix = name. Substring (name. LastIndexOf (".") + 1); // obtain the suffix of the uploaded file
String ipath = Server. MapPath ("upimg") + "\" + name; // obtain the actual file path
String fpath = Server. MapPath ("upfile") + "\" + name;
String dpath = "upimg \" + name; // determines the virtual path written to the database
ShowPic. Visible = true; // Activation
ShowText. Visible = true; // Activation
// Determine the file format
If (name = ""){
Response. Write ("<script> alert ('file cannot be blank ') </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> "+" actual storage path: "+ ipath;
}
Else
{
ShowPic. Visible = false; // hide the image
GetFiles. SaveAs (fpath); // The folder upfile is stored because it is not an image file.
ShowText. text = "the name of the file you uploaded is:" + name + "<br>" + "file size: "+ size +" KB "+" <br> "+" file type: "+ type +" <br> "+" actual storage path: "+ fpath;
}
}
}