예제 #1
-1
    protected void UploadButton_Click(object sender, EventArgs e)
    {
        if (FileUploadControl.HasFile)
        {
            try
            {
                string filename = Path.GetFileName(FileUploadControl.FileName);
                string path = Server.MapPath("~/uploaded_images/");
                //if (File.Exists(path + filename))
                //{
                //    StatusLabel.Text = "File name already exists. Please choose another file name";
                //    return;
                //}

                FileUploadControl.SaveAs(path + filename);

                DBManager db = new DBManager();
                db.Connect();
                db.InsertNewPicture(filename, Constants.IMG_FOLDER, "");
                db.Close();

                StatusLabel.Text = "Upload status: File uploaded!";
                Application[Constants.FRONT_PAGE_IMG_API_CACHE] = null;
                Response.Redirect(Request.RawUrl);

            }
            catch (Exception ex)
            {
                StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
            }
        }
    }