コード例 #1
0
 /// <summary>
 /// Handle ButtonSubmit click event
 /// Create new Content
 /// </summary>
 /// <remarks></remarks>
 protected void ButtonSubmit_Click(object sender, EventArgs e)
 {
     //Check if all fields are valid
     if (ValidateForm())
     {
         //If all valid, start inserting content
         if ((FileUploadImage.PostedFile != null) && (FileUploadImage.PostedFile.ContentLength > 0))
         {
             var fn           = System.IO.Path.GetFileName(FileUploadImage.PostedFile.FileName);
             var saveLocation = Server.MapPath("../Images/News") + "\\" + fn;
             try
             {
                 // Upload file
                 FileUploadImage.PostedFile.SaveAs(saveLocation);
                 if (content.InsertContent(txtTitle.Text, FileUploadImage.FileName, HttpUtility.HtmlEncode(txtText.Text),
                                           listCategory.SelectedValue))
                 {
                     //If insert successfully, show message and reset all controls
                     Page.ClientScript.RegisterClientScriptBlock(GetType(), "alert",
                                                                 "alert('Content inserted');document.location.href='Contents.aspx';",
                                                                 true);
                 }
                 //Show message if failed insertion
                 else
                 {
                     ShowMessage("Content not inserted");
                 }
             }
             catch (Exception ex)
             {
                 ShowMessage(ex.Message);
             }
         }
         else
         {
             ShowMessage("Please select Image to upload.");
             return;
         }
     }
 }