ASP.NET 2.0 FileUpload.PostedFile 问题
我在ASP.NET 2.0中想用FileUpload.PostedFile 获取路径,可总是显示路径为空,NULL
为什么会这样呢?
string filepath = FileUpload1.PostedFile.FileName;
大家帮忙下
------解决方案--------------------汗
看错
你用的是html标记是么
那加encType="multipart/form-data" 这个了么
------解决方案--------------------这段代码不错,研究下吧.
protected void Button2_Click(object sender, EventArgs e)
{
string fullFileName = this.FileUpload1.PostedFile.FileName;
string filename = fullFileName.Substring(fullFileName.LastIndexOf("\\")+1);
string type = fullFileName.Substring(fullFileName.LastIndexOf(".") + 1);
if (type == "jpg" || type == "gif" || type == "bmp")
{
this.FileUpload1.PostedFile.SaveAs(Server.MapPath("images") + "\\" + filename);
this.Image1.ImageUrl = "images/"+filename;
}
else
{
Response.Write("<script language='javascript'>alert('你选择的图片格式错误!');</script>");
}
}