using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            if (FileUpload1.PostedFile.FileName == "")
            {
                Response.Write("<script>alert('上传文件不能为空！')</script>");
                return;
            }
            else
            {
                string filepath = FileUpload1.PostedFile.FileName;
                string filename = filepath.Substring(filepath.LastIndexOf("\\") + 1);
                string serverpath = Server.MapPath("Files/") + filename;
                FileUpload1.PostedFile.SaveAs(serverpath);
                Response.Write("<script>alert('成功上传了文件！')</script>");
            }
        }
        catch (Exception error)
        {
            Response.Write("<script>alert('上传文件失败！')</script>");
        }
    }
}
