使用FileUpload控件,上传图片到images下的upload文件夹中,代码要添加什么才能上传
stringcat=Server.MapPath(@"images/");if(System.IO.Directory.Exists(cat)==false){Syste...
string cat = Server.MapPath(@"images/");
if (System.IO.Directory.Exists(cat) == false)
{
System.IO.Directory.CreateDirectory(cat);
}
else
{
if (FileUpload1.HasFile == true)
{
FileUpload1.SaveAs(cat + FileUpload1.FileName);
Response.Write("<script> alert('上传成功!')</script>");
Label1.Text = "images/"+FileUpload1.FileName.ToString();
}
} 展开
if (System.IO.Directory.Exists(cat) == false)
{
System.IO.Directory.CreateDirectory(cat);
}
else
{
if (FileUpload1.HasFile == true)
{
FileUpload1.SaveAs(cat + FileUpload1.FileName);
Response.Write("<script> alert('上传成功!')</script>");
Label1.Text = "images/"+FileUpload1.FileName.ToString();
}
} 展开
2个回答
展开全部
protected void Button1_Click(object sender, EventArgs e)
{
string cat = Server.MapPath(@"images/upload/");
if (System.IO.Directory.Exists(cat) == false)
{
System.IO.Directory.CreateDirectory(cat);
}
if (FileUpload1.HasFile == true)
{
FileUpload1.SaveAs(cat + FileUpload1.FileName);
Response.Write("<script> alert('上传成功!')</script>");
Label1.Text = "images/upload/" + FileUpload1.FileName.ToString();
}
}
{
string cat = Server.MapPath(@"images/upload/");
if (System.IO.Directory.Exists(cat) == false)
{
System.IO.Directory.CreateDirectory(cat);
}
if (FileUpload1.HasFile == true)
{
FileUpload1.SaveAs(cat + FileUpload1.FileName);
Response.Write("<script> alert('上传成功!')</script>");
Label1.Text = "images/upload/" + FileUpload1.FileName.ToString();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询