Exemple #1
0
        private void SaveProductImage()
        {
            if (UploadProductImage.PostedFile != null)
            {
                string filename = UploadProductImage.PostedFile.FileName.ToString();
                string fileext  = System.IO.Path.GetExtension(UploadProductImage.FileName);

                if (fileext != ".jpeg" && fileext != ".jpg" && fileext != ".png" && fileext != ".bmp")
                {
                    Response.Write("<script>alert('invalid format');</script>");
                }
                else if (filename.Length > 96)
                {
                    Response.Write("<script>alert('large size');</script>");
                }
                else if (UploadProductImage.PostedFile.ContentLength > 4000000)
                {
                    Response.Write("<script>alert('size should not be more than 4MB');</script>");
                }
                else
                {
                    UploadProductImage.SaveAs(Server.MapPath("~/ProductImages/") + filename);
                }
            }
        }
        public async Task <IActionResult> UploadProductImageAsync(IFormFile file)
        {
            var fileName = System.Web.HttpUtility.UrlEncode(file.FileName);
            var stream   = new MemoryStream();
            await file.CopyToAsync(stream);

            var command = new UploadProductImage(fileName, stream.ToArray(), file.ContentType);
            var result  = await _mediator.Send(command);

            return(Ok(result));
        }
 protected void ButtonUpdate_Click(object sender, EventArgs e)
 {
     if (UploadProductImage.HasFile)
     {
         string imagePath = "~/images/" + UploadProductImage.FileName;
         UploadProductImage.SaveAs(Server.MapPath(imagePath).ToString());
         SqlCommand cmd = new SqlCommand("UPDATE menuItems  SET itemName = '" + TextBoxName.Text + "', itemPrice ='" + TextBoxPrice.Text + "', itemImage = '" + imagePath + "', itemDescription = '" + TextBoxBio.Text + "' WHERE itemID = " + Request.QueryString["ID"], con);
         con.Open();
         cmd.ExecuteNonQuery();
         con.Close();
         BindData();
     }
 }