protected void AddCarButton_Click(object sender, EventArgs e) { Boolean fileOK = false; String path = Server.MapPath("/Catalog/Images/"); if (CarImage.HasFile) { String fileExtension = System.IO.Path.GetExtension(CarImage.FileName).ToLower(); String[] allowedExtentions = { ".gif", ".png", ".jpeg", ".jpg" }; for (int i = 0; i < allowedExtentions.Length; i++) { if (fileExtension == allowedExtentions[i]) { fileOK = true; } } } if (fileOK) { try { //save to images folder CarImage.PostedFile.SaveAs(path + CarImage.FileName); //save to images/thumbs folder CarImage.PostedFile.SaveAs(path + "Thumbs/" + CarImage.FileName); } catch (Exception ex) { LabelAddStatus.Text = ex.Message; } // add car to database AddCars cars = new AddCars(); bool addSuccess = cars.AddCar(AddCarMake.Text, AddCarModel.Text, AddCarFuelType.Text, AddCarDescription.Text, AddCarPrice.Text, DropDownAddCategory.SelectedValue, CarImage.FileName); if (addSuccess) { // reload page string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count()); Response.Redirect(pageUrl + "?CarAction=add"); } else { LabelAddStatus.Text = "Unable to add new car to database."; } } else { LabelAddStatus.Text = "Unable to accept file type."; } }
private void addCars_MouseDoubleClick(object sender, RoutedEventArgs e) { AddCars ac = new AddCars(); ac.Show(); }