protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection con = db.ceratcon();
con.Open();
SqlCommand cmd = new SqlCommand("select * from uploadimage ", con);
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
this.Image2.ImageUrl = sdr["Ppath"].ToString();
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string name = this.FileUpload1.FileName;//获取文件或图片的名字
string size = this.FileUpload1.PostedFile.ContentLength.ToString();//获取文件或图片的大小
string type = this.FileUpload1.PostedFile.ContentType;//获取文件或图片的类型
string type2 = name.Substring(name.LastIndexOf(".") + 1);//获取文件或图片的后缀名
string fpath = Server.MapPath("upfile") + "\\" + name;//获取文件的实际路径
string ipath = Server.MapPath("upimage") + "\\" + name;//获取图片的实际路径
string wpath ="upimage\\" + name;//获得文件的虚拟目录
if (type2 == "jpg" || type2 == "bmp" || type2 == "jif")//判断文件是不是图片类型
{
this.FileUpload1.SaveAs(Server.MapPath("upimage")+"\\"+name);//如果是图片上传到upimage文件夹里
this.Image1.ImageUrl = wpath;
this.Label1.Text = "你上传的文件名是" + name + "图片类型是" + type2 + "文件大小是" + size + "文件的实际路径是" + ipath + "文件的虚拟路径是" + wpath;
this.Label2.Text = wpath;
SqlConnection con = db.ceratcon();
|