asp.net上传控件使用

asp.net上传控件使用
 protected void Button1_Click(object sender, EventArgs e)
{
string str = "";
if (FileUpload1.HasFile)
{
try
{
if (FileUpload1.PostedFile.ContentLength < 10240)
{ FileUpload1.SaveAs("e:\\" + FileUpload1.FileName);
str += "上传的文件名字为" + FileUpload1.FileName + "<br/>";
str += "文件来自" + FileUpload1.PostedFile.FileName + "<br/>";
str += "文件大小" + FileUpload1.PostedFile.ContentLength + "<br/>";
str += "文件的类型为" + FileUpload1.PostedFile.ContentType + "<br/>";
Label1.Text = "文件上传成功,相应信息如下:" + str;
}
else
{
Response.Write("<script>alert('文件大小超出范围!')</script>");
} }
catch (Exception ex)
{
Label1.Text = ex.Message;
}
} }
protected void Button2_Click(object sender, EventArgs e)
{
string name = FileUpload2.FileName;
string size = FileUpload2.PostedFile.ContentLength.ToString();
string type = FileUpload2.PostedFile.ContentType;
string path = Server.MapPath("images\\") + name;
string tp = name.Substring(name.LastIndexOf("."));
if (type.Substring(0, 5) == "image")
{
FileUpload2.SaveAs(path);
Label2.Text = "文件名:" + name + "<br/>" + "大小:" + size + "<br/>" + "文件类型:" + type + "<br/>" + "后缀:" + tp + "<br/>" + "保存路径:" + path + "<br/>";
}
}
上一篇:WCF: 没有终结点在侦听可以接受消息的 这通常是由于不正确的地址或者 SOAP 操作导致的。


下一篇:基于 CentOS 8 搭建 openLDAP 服务器