62,268
社区成员
发帖
与我相关
我的任务
分享
protected static string PicPath = String.Empty;
protected void btnFileUpload_Click(object sender, EventArgs e)
{
PicPath = Server.MapPath("/images/upload/") + FileUploadIndexPic.FileName;
if (this.FileUploadIndexPic.HasFile)
{
string fileExt = System.IO.Path.GetExtension(this.FileUploadIndexPic.FileName);
if (fileExt == "jpg" || fileExt == "Jpg" || fileExt == "JPEG")
{
try
{
FileUploadIndexPic.SaveAs(PicPath);
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "alert('上传成功!')", true);
}
catch
{
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "alert('上传失败!')", true);
}
}
else
{
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "alert('首页幻灯片必须为jpg格式!')", true);
}
}
else
{
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "alert('请选择要上传的文件!')", true);
}
}