protected void SaveButton_Click(object sender, EventArgs e) { try { ImageFileUpload.SaveAs(Server.MapPath("~/Product/Images/") + Path.GetFileName(ImageFileUpload.FileName)); String GetImagePath = "~/Product/Images/" + Path.GetFileName(ImageFileUpload.FileName); Products _Products = new Products(); _Products.Code = txtCode.Text; _Products.Name = txtName.Text; _Products.ReorderLevel = Convert.ToInt32(txtReorder.Text); _Products.Description = txtDescription.Text; _Products.Images = GetImagePath; _Products.CategoriesId = Convert.ToInt32(CategoriesDropDownList.SelectedValue); int Savesuccess = _ProductSetupRepository.Add(_Products); if (Savesuccess > 0) { ShowMessage("Successfully Save Product!!...Continue Working", MessageType.Success); Refresh(); _Products.CategoriesId = Convert.ToInt32(CategoriesDropDownList.SelectedValue); AutoCodeGenerate(); } else { ShowMessage("Failed Product Save!!...Continue Working", MessageType.Warning); } } catch (Exception ex) { ShowMessage(ex.Message, MessageType.Error); } }
/// <summary> /// 上传原图 /// </summary> /// <param name="fileName"></param> void UploadAndCreateThumbnails(string fileName) { string folderPath = ExistFilePath(); //判断路径是否存在 if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } //上传后图片的路径 string fn = Path.Combine(folderPath, fileName); //上传 ImageFileUpload.SaveAs(fn); //文件后缀 string ext = Path.GetExtension(fn); //去掉后缀的文件名 string imgName = string.Format("{0}", Path.GetFileNameWithoutExtension(fn)); string originalFilePath = CheckFileName(imgName, ext, folderPath, ""); //删除原图 Article article = ArticleHelper.GetArticle(ArticleID, null); if (article != null && article.Thumbnail != null && article.Thumbnail != "") { string thumbnail = article.Thumbnail.Replace("_S", ""); File.Delete(Server.MapPath(thumbnail)); } SaveImageToDB(originalFilePath); }
protected void btnUpload_Click(object sender, EventArgs e) { string fileName = ImageFileUpload.FileName; if (fileName != "") { ImageFileUpload.SaveAs(HttpContext.Current.Server.MapPath(".") + @"\pictures\" + fileName); imgUploaded.ImageUrl = "pictures/" + fileName; txtPicture.Text = fileName; } }
/// <summary> /// 上传原图 /// </summary> /// <param name="fileName"></param> void UploadAndCreateThumbnails(string fileName) { string folderPath = ExistFilePath(); //上传后图片的路径 string fn = Path.Combine(folderPath, fileName); //上传 ImageFileUpload.SaveAs(fn); //生成小图片 GenerateThumbImage(fn); }
protected void SaveButton_Click(object sender, EventArgs e) { try { ImageFileUpload.SaveAs(Server.MapPath("~/Party/Images/") + Path.GetFileName(ImageFileUpload.FileName)); String GetImagePath = "~/Party/Images/" + Path.GetFileName(ImageFileUpload.FileName); Customers _Customers = new Customers(); _Customers.Code = txtCode.Text; _Customers.Name = txtName.Text; _Customers.Email = txtEmail.Text; _Customers.Address = txtAddress.Text; _Customers.Contact = txtContact.Text; _Customers.LoyaltyPoint = Convert.ToDecimal(txtLoyaltyPoint.Text); _Customers.Images = GetImagePath; if (IdHiddenField.Value == "") { decimal AlreadyExistCustomer = _CustomerRepository.AlreadyExistCustomer(_Customers); if (AlreadyExistCustomer >= 1) { ShowMessage("This Customer Already Here!!...Enter Another Name", MessageType.Warning); } else { int Savesuccess = _CustomerRepository.Add(_Customers); if (Savesuccess > 0) { ShowMessage("Successfully Save Customer!!...Continue Working", MessageType.Success); IdHiddenField.Value = ""; Refresh(); AutoCodeGenerate(); LoadCustomers(); } else { ShowMessage("Failed Customer Saved!!...Try Again", MessageType.Failed); } } } else { } } catch (Exception ex) { ShowMessage(ex.Message, MessageType.Error); } }
protected void UploadImage_Click(object sender, EventArgs e) { if (ImageFileUpload.HasFile) { string filename = ""; // saving the original image try { filename = Path.GetFileName(ImageFileUpload.FileName); ImageFileUpload.SaveAs(ConfigurationManager.AppSettings["originalImage"].ToString() + filename); Session["Imagefilename"] = null; Session["Imagefilename"] = filename; } catch (Exception ex) { // log exception } // end of saving the original image try { using (ImageResizer resizer = new ImageResizer(ConfigurationManager.AppSettings["originalImage"].ToString() + filename)) { // Make sure any images which are sideways are turned the right way around resizer.RotateIfNeeded(); // Save it to disk as a large JPG, in its own special directory resizer.Mode = ResizeMode.KeepOriginalRatioByCropping; resizer.Resize(650, 650); resizer.SaveToDisk(OutputImageFormat.Jpeg, ConfigurationManager.AppSettings["650by650"] + filename); // Also save a thumbnail version resizer.Mode = ResizeMode.KeepOriginalRatioByCropping; resizer.Resize(80, 80); resizer.SaveToDisk(OutputImageFormat.Jpeg, ConfigurationManager.AppSettings["80by80"] + filename); } SetAddImageDetails(); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "fileUpload", "setImageUpload(true, true)", true); } catch (Exception ex) { //errorLabel.Visible = true; //errorLabel.Text = "Could not upload image: " + ex.Message; } } }
protected void SaveButton_Click(object sender, EventArgs e) { try { ImageFileUpload.SaveAs(Server.MapPath("~/Student/Images/") + Path.GetFileName(ImageFileUpload.FileName)); String GetImagePath = "~/Student/Images/" + Path.GetFileName(ImageFileUpload.FileName); Students _Students = new Students(); _Students.StudentId = txtStudentId.Text; _Students.Name = txtName.Text; _Students.Contact = txtContact.Text; _Students.Gender = GenderDropDownList.SelectedItem.ToString(); _Students.Institute = txtInstitute.Text; _Students.Class = ClassDropDownList.SelectedItem.ToString(); _Students.Groups = GroupDropDownList.SelectedItem.ToString(); _Students.Subjects = txtSubjects.Text; _Students.Address = txtAddress.Text; _Students.Father = txtFather.Text; _Students.Nid = txtNid.Text; _Students.Fees = Convert.ToDecimal(txtFees.Text); _Students.Images = GetImagePath; decimal AlreadyExistStudent = _StudentRepository.AlreadyExistStudent(_Students); if (AlreadyExistStudent >= 1) { ShowMessage("This Student Already Here!!!...", MessageType.Warning); } else { int Savesuccess = _StudentRepository.Add(_Students); if (Savesuccess > 0) { ShowMessage("Successfully Saved Student....", MessageType.Success); Response.Redirect(Request.Url.AbsoluteUri); } else { ShowMessage("Failed Saving Student", MessageType.Warning); } } } catch (Exception ex) { ShowMessage(ex.Message, MessageType.Error); } }
protected void btnSubmit_Click(object sender, EventArgs e) { InventoryItem updateItem = new InventoryItem(); if (hidInventoryId.Value != null && hidInventoryId.Value != "") { updateItem.setInventoryId(Convert.ToInt32(hidInventoryId.Value)); setUpdateItem(updateItem); if (ImageFileUpload.HasFile) { if (ImageFileUpload.PostedFile.ContentType == "image/jpeg" || ImageFileUpload.PostedFile.ContentType == "image/png") { String filename = Path.GetFileName(ImageFileUpload.FileName); ImageFileUpload.SaveAs(Server.MapPath("~/Graphics/" + filename)); updateItem.setImageUrl(ImageFileUpload.FileName); } } else { updateItem.setImageUrl(hidImagePath.Value); } sendItemToDb(updateItem); } else { setUpdateItem(updateItem); if (ImageFileUpload.HasFile) { if (ImageFileUpload.PostedFile.ContentType == "image/jpeg" || ImageFileUpload.PostedFile.ContentType == "image/png") { String filename = Path.GetFileName(ImageFileUpload.FileName); ImageFileUpload.SaveAs(Server.MapPath("~/Graphics/" + filename)); updateItem.setImageUrl(ImageFileUpload.FileName); } else { lblMsg.Text = "There is a problem with your image. It must be .jpg or .png. Please try again."; } sendNewItemToDb(updateItem); } else { lblMsg.Text = "An image file is required, please try again."; } } }
/// <summary> /// 上传原图 /// </summary> /// <param name="fileName"></param> void UploadAndCreateThumbnails(string fileName) { //上传后图片的路径 string fn = Path.Combine(ThumbnailServerFolder, fileName); //上传 ImageFileUpload.SaveAs(fn); OriginalImagePath = ThumbnailFolder.TrimEnd('\\').TrimEnd('/') + "/" + fileName; InitImageInfo(); ////文件后缀 //string ext = Path.GetExtension(fn); ////去掉后缀的文件名 //string imgName = string.Format("{0}", Path.GetFileNameWithoutExtension(fn)); }
protected void profilePicButton_Click(object sender, EventArgs e) { string dbstring = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; SqlConnection con = new SqlConnection(dbstring); con.Open(); string sqlStr = "UPDATE [User] SET [image]=@image WHERE [username]=@username"; SqlCommand sqlCmd = new SqlCommand(sqlStr, con); string imagePath = "~/images/profile_pictures/NoImage.jpg"; //Check if the user has selected an image file that should be used instead of the default if (ImageFileUpload.HasFile) { //Check if the file has a valid extension string extension = System.IO.Path.GetExtension(ImageFileUpload.PostedFile.FileName); if (extension == ".png" || extension == ".gif" || extension == ".jpg" || extension == ".bmp") { //Save the file in the crooms folder on the server. I want the filename to be the name of the room, //but without any dots and dashes. E.g. an image for a room VBI-6.01, should be saved as VBI601.extension. //Remove any . and - from the room name string imageName = this.User.Identity.Name; //Now save the file ImageFileUpload.SaveAs(Server.MapPath("~/images/profile_pictures/" + imageName + extension)); //Now set the imagePath that we will store in the DB to the path of the newly saved file imagePath = "~/images/profile_pictures/" + imageName + extension; } } sqlCmd.Parameters.AddWithValue("@username", this.User.Identity.Name); sqlCmd.Parameters.AddWithValue("@image", imagePath); sqlCmd.ExecuteNonQuery(); con.Close(); Response.Redirect(Request.RawUrl); }
protected void btnSubmit_Click(object sender, EventArgs e) { Boolean success = false; if (IsValid) { InventoryItem inventoryItem = new InventoryItem(); inventoryItem.setProductName(txtProductName.Text); inventoryItem.setProductCount(Convert.ToInt32(txtProductCount.Text)); inventoryItem.setItemsOnHold(Convert.ToInt32(txtItemsOnHold.Text)); inventoryItem.setUnitPrice(Convert.ToDouble(txtUnitPrice.Text)); inventoryItem.setSalePrice(Convert.ToDouble(txtSalePrice.Text)); inventoryItem.setShortDescription(txtShortDescription.Text); inventoryItem.setLongDescription(txtLongDescription.Text); if (ImageFileUpload.PostedFile.ContentType == "image/jpeg" || ImageFileUpload.PostedFile.ContentType == "image/png") { String filename = Path.GetFileName(ImageFileUpload.FileName); ImageFileUpload.SaveAs(Server.MapPath("~/Graphics/" + filename)); inventoryItem.setImageUrl(ImageFileUpload.FileName); success = InventoryManager.insertNewItem(inventoryItem); } else { lblMsg.Text = "There is a problem with your image. It must be .jpg or .png. Please try again."; } if (success) { InventoryPurchaseInfo purchaseInfo = new InventoryPurchaseInfo(); InventoryItem item = InventoryManager.getItemByName(txtProductName.Text); purchaseInfo.inventoryItemId = item.getInventoryId(); purchaseInfo.manufacturerId = Convert.ToInt32(ddlManufacturer.SelectedValue); purchaseInfo.minInventory = Convert.ToInt32(txtMinumInventory.Text); success = PurchaseManager.addNewInventoryPurchaseInfo(purchaseInfo); } if (success) { lblMsg.Text = "Item successfuly added."; } } }
protected void UploadButton_Click(object sender, EventArgs e) { if (ImageFileUpload.HasFile) { try { if (ImageFileUpload.PostedFile.ContentType == "image/jpeg") { if (ImageFileUpload.PostedFile.ContentLength <= 16 * 1000 * 1024) { string username = User.Identity.Name; string id = User.Identity.GetUserId(); string directory = Server.MapPath("~/UploadedFiles/ProfileImages/") + id; string filename = Guid.NewGuid().ToString() + ".jpg"; string path = directory + "/" + filename; string url = "~/UploadedFiles/ProfileImages/" + id + "/" + filename; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } ImageFileUpload.SaveAs(path); UserService.ChangeProfilePhotoUrl(id, url); ErrorSuccessNotifier.AddSuccessMessage("Upload status: File uploaded!"); } else { ErrorSuccessNotifier.AddErrorMessage("Upload status: The file has to be less than 16 mb!"); } } else { ErrorSuccessNotifier.AddErrorMessage("Upload status: Only JPEG files are accepted!"); } } catch (Exception ex) { ErrorSuccessNotifier.AddErrorMessage("Upload status: The file could not be uploaded. The following error occured: " + ex.Message); } } }
protected void UploadButton_Click(object sender, EventArgs e) { if (ImageFileUpload.HasFile) { try { //ViewState["ImageFileUpload"] = ImageFileUpload; SelectedFileName = Path.GetFileName(ImageFileUpload.FileName); ExtractOnlyFileName(SelectedFileName); ServerFilePath = Server.MapPath("~/UploadedImages/") + SelectedFileName; ViewState["ServerFilePath"] = ServerFilePath; ImageFileUpload.SaveAs(ServerFilePath); LoadedImage.ImageUrl = "~/UploadedImages/" + SelectedFileName; } catch (Exception ex) { //StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; } } }
private void UploadPic(ref FileUpload fuObj, ref Label fuLbl, string fuName) { int fileSize = 5096000; string fileExt = ""; string pathAndFile = ""; lblMessage.Text = ""; if (ImageFileUpload.PostedFile.ContentLength < fileSize) { fileExt = System.IO.Path.GetExtension(ImageFileUpload.FileName).ToLower(); string txtID = DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.TimeOfDay.ToString(); string txtLName = "Img"; pathAndFile = "\\\\Server\\Folder\\"; pathAndFile += txtID + "_" + txtLName + "_" + ImageFileUpload.FileName.ToLower(); //FileName = pathAndFile; Session["FileName"] = txtID + "_" + txtLName + "_" + ImageFileUpload.FileName.ToLower();; if (fileExt == ".jpg") { if (System.IO.File.Exists(pathAndFile)) { lblMessage.Text = "Sorry Already Exists !!!"; return; } else { ImageFileUpload.SaveAs(pathAndFile); } } else { lblMessage.Text = "Error Only .jpg Allowed"; return; } } else { lblMessage.Text = "ERROR: The file is needs to be less than 4MB (4096 KB)."; } lblMessage.Text = "Uploaded Successfully !! <br /> File Name :" + ImageFileUpload.FileName + "<br /> Content Type: " + ImageFileUpload.PostedFile.ContentType + "<br /> Length : " + ImageFileUpload.PostedFile.ContentLength; }
protected void AddButton_Click(object sender, EventArgs e) { try { ImageFileUpload.SaveAs(Server.MapPath("~/Librarian/Books/BookImages") + Path.GetFileName(ImageFileUpload.FileName)); String GetImagePath = "~/Librarian/Books/BookImages" + Path.GetFileName(ImageFileUpload.FileName); Book _Book = new Book(); _Book.Name = txtBookName.Text; _Book.AuthorName = txtBookAuthorName.Text; _Book.AvailableQty = Convert.ToDecimal(txtBookQty.Text); _Book.Images = GetImagePath; _Book.CategoriesCode = CategoryDropDownList.SelectedValue.ToString(); decimal AlreadyExistBook = _BooksManager.AlreadyExistBook(_Book); if (AlreadyExistBook >= 1) { ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('This Book Already Exist!!..');", true); } else { int successAdd = _BooksManager.Add(_Book); if (successAdd > 0) { ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Saved Book Successefully!!..');", true); Clear(); } else { ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Failed saved!!..');", true); } } } catch (Exception ex) { ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + ex.Message + "');", true); } }
protected void CreateButton_Click(object sender, EventArgs e) { string dbstring = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; SqlConnection con = new SqlConnection(dbstring); string sqlMy = "SELECT Name FROM Item WHERE Name = @theName"; SqlCommand sqlName = new SqlCommand(sqlMy, con); sqlName.Parameters.AddWithValue("@theName", itemNameTextBox.Text); string sqlStr = "SELECT itemId FROM Item WHERE itemId = @theItemID"; SqlCommand sqlCmd = new SqlCommand(sqlStr, con); sqlCmd.Parameters.AddWithValue("@theItemID", itemIdTextBox.Text); con.Open(); object result = sqlCmd.ExecuteScalar();// first row check in our case it is ID object name = sqlName.ExecuteScalar(); if (result == null && name == null) { string sqlStr2 = "INSERT INTO Item (ItemId,Name,Type,Description,Author,Stock,image,price) VALUES (@theItemId, @theName, @theType, @theDescription ,@theAuthor, @theStock, @theImage, @thePrice)"; SqlCommand sqlCmd2 = new SqlCommand(sqlStr2, con); int itemId = Convert.ToInt32(itemIdTextBox.Text); int stock; string stockStr = StockTextBox.Text; try { stock = Convert.ToInt32(stockStr); } catch (FormatException ex) { stock = 0; } int price; string priceStr = priceTextBox.Text; try { price = Convert.ToInt32(priceStr); } catch (FormatException ex) { price = 0; } string imagePath = "~/Images/brands/NoImage.gif"; if (ImageFileUpload.HasFile) { //Check if the file has a valid extension string extension = System.IO.Path.GetExtension(ImageFileUpload.PostedFile.FileName); if (extension == ".png" || extension == ".gif" || extension == ".jpg" || extension == ".bmp") { //Save the file in the crooms folder on the server. I want the filename to be the name of the room, //but without any dots and dashes. E.g. an image for a room VBI-6.01, should be saved as VBI601.extension. //Remove any . and - from the room name string itemName = itemNameTextBox.Text.Replace(".", ""); itemName = itemName.Replace("-", ""); itemName = itemName.Replace(" ", ""); //Now save the file ImageFileUpload.SaveAs(Server.MapPath("~/images/brands/" + itemName + extension)); //Now set the imagePath that we will store in the DB to the path of the newly saved file imagePath = "~/images/brands/" + itemName + extension; } } sqlCmd2.Parameters.AddWithValue("@theItemId", itemIdTextBox.Text); sqlCmd2.Parameters.AddWithValue("@theName", itemNameTextBox.Text); sqlCmd2.Parameters.AddWithValue("@theType", itemTypeTextBox.Text); sqlCmd2.Parameters.AddWithValue("@thePrice", priceTextBox.Text); sqlCmd2.Parameters.AddWithValue("@theDescription", descriptionTextBox.Text); sqlCmd2.Parameters.AddWithValue("@theAuthor", AuthorTextBox.Text); sqlCmd2.Parameters.AddWithValue("@theStock", StockTextBox.Text); sqlCmd2.Parameters.AddWithValue("@theImage", imagePath); //if (itemNameTextBox == null) //{ // con.Close(); // resultLabel1.ForeColor = System.Drawing.Color.Black; // resultLabel1.Text = "Item name"; //} sqlCmd2.ExecuteNonQuery(); con.Close(); resultLabel1.ForeColor = System.Drawing.Color.Black; resultLabel1.Text = "Item was created"; } else { itemNameTextBox.Visible = false; itemNameLabel.Visible = false; itemTypeLabel.Visible = false; itemTypeTextBox.Visible = false; descriptionLabel.Visible = false; descriptionTextBox.Visible = false; priceLabel.Visible = false; priceTextBox.Visible = false; AuthorLabel.Visible = false; AuthorTextBox.Visible = false; StockLabel.Visible = false; StockTextBox.Visible = false; ImageLabel.Visible = false; ImageFileUpload.Visible = false; CreateButton.Visible = false; con.Close(); if (result != null) { resultLabel.Visible = true; resultLabel.ForeColor = System.Drawing.Color.Red; resultLabel.Text = "Item already exists!"; } else if (name != null) { resultLabel.Visible = true; resultLabel.ForeColor = System.Drawing.Color.Red; resultLabel.Text = "Name already exists!"; } } }