FileUpdate--上传控件
protected void Button1_Click(object sender, EventArgs e)
{
string name = FileUpload1.FileName; //上传文件名
string size = FileUpload1.PostedFile.ContentLength.ToString(); //文件大小(字节)
string type = FileUpload1.PostedFile.ContentType; //获取上传文件的MIME内容类型
string type1 = name.Substring(name.LastIndexOf(".") + 1); //name.LastIndexOf(".")索引name中"."的位置+1,就是后缀名的index
string ipath = Server.MapPath("upimg") + "\\" + name;
string fpath = Server.MapPath("upfile") + "\\" + name;
string wpath = "upimg" + "\\" + name;
if (type1 == "jpg" || type1 == "gif" || type1 == "bmp" || type1 == "png")
{
FileUpload1.SaveAs(ipath);
Image1.ImageUrl = wpath;
Label1.Text = "文件名" + name + "<br>" + "文件大小为" + size + "<br>文件类型是" + type + "<br>后缀名" + type1 + "<br>实际路径" + ipath + "<br>虚拟路径" + wpath;
}
else
{
FileUpload1.SaveAs(fpath);
Image1.ImageUrl = wpath;
Label1.Text = "文件名" + name + "<br>" + "文件大小为" + size + "<br>文件类型是" + type + "<br>后缀名" + type1 + "<br>实际路径" + ipath + "<br>虚拟路径" + wpath;
}
}
运行结果: {
string name = FileUpload1.FileName; //上传文件名
string size = FileUpload1.PostedFile.ContentLength.ToString(); //文件大小(字节)
string type = FileUpload1.PostedFile.ContentType; //获取上传文件的MIME内容类型
string type1 = name.Substring(name.LastIndexOf(".") + 1); //name.LastIndexOf(".")索引name中"."的位置+1,就是后缀名的index
string ipath = Server.MapPath("upimg") + "\\" + name;
string fpath = Server.MapPath("upfile") + "\\" + name;
string wpath = "upimg" + "\\" + name;
if (type1 == "jpg" || type1 == "gif" || type1 == "bmp" || type1 == "png")
{
FileUpload1.SaveAs(ipath);
Image1.ImageUrl = wpath;
Label1.Text = "文件名" + name + "<br>" + "文件大小为" + size + "<br>文件类型是" + type + "<br>后缀名" + type1 + "<br>实际路径" + ipath + "<br>虚拟路径" + wpath;
}
else
{
FileUpload1.SaveAs(fpath);
Image1.ImageUrl = wpath;
Label1.Text = "文件名" + name + "<br>" + "文件大小为" + size + "<br>文件类型是" + type + "<br>后缀名" + type1 + "<br>实际路径" + ipath + "<br>虚拟路径" + wpath;
}
}