asp.net文件上传代码?
代码怎么写?
代码怎么写?
答案:添加一个FileUpLoad控件:if (FileUpload1.PostedFile.ContentLength <= 0)
{
Response.Write("<script>alert('请上传文件');</script>");
}else
{
string fpath = FileUpload1.FileName;
string pos = System.IO.Path.GetExtension(fpath).ToLower();
if (pos != ".jpg" && pos != ".gif") // 文件格式验证, 根据需要自己选择
{
Response.Write("<script>alert('格式不符合要求');</script>");
}
else
{
FileUpload1.SaveAs(Server.MapPath("Images/") + System.IO.Path.GetFileName(fpath));
}}
上一个:ASP.NET登陆代码出错
下一个:asp.net & js 的疑问