protected void Button1_Click(object sender, EventArgs e) { //checking if there is a file and action did not triggered by refreshing the page if (FileUpload1.HasFile && IsPageRefresh == false) { string FileExtension = string.Empty; try { FileExtension = System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName).Substring(1); } catch { } OrderezeTask.Image image = new OrderezeTask.Image(); image.Name = NameTxt.Text + "." + FileExtension; image.Description = DescriptionTxt.Text; image.ImagePath = "https://geoklar.blob.core.windows.net/images/" + NameTxt.Text + "." + FileExtension; int id = az.AddNewImage(image); if(id > 0) { az.UploadBlob(FileUpload1, NameTxt.Text + "." + FileExtension); } } GridViewData(); }
public ActionResult AddImage(ImageModel image) { //Checking if there is a file if (image.File.ContentLength > 0) { ImageMethods az = new ImageMethods(); OrderezeTask.Image tmpImage = new OrderezeTask.Image(); HttpPostedFileBase file = image.File; string FileExtension = string.Empty; try { FileExtension = System.IO.Path.GetExtension(file.FileName).Substring(1); } catch { } tmpImage.Name = (string.IsNullOrEmpty(file.FileName) ? file.FileName : image.Name + "." + FileExtension); tmpImage.Description = image.Description; tmpImage.ImagePath = "https://geoklar.blob.core.windows.net/images/" + (string.IsNullOrEmpty(file.FileName) ? file.FileName : image.Name + "." + FileExtension); int id = az.AddNewImage(tmpImage); if (id > 0) { BinaryReader b = new BinaryReader(file.InputStream); byte[] binData = b.ReadBytes(file.ContentLength); az.UploadBlob(binData, (string.IsNullOrEmpty(file.FileName) ? file.FileName : image.Name + "." + FileExtension)); return Content("Success :)"); } } //_images.Add(image); return Content("Fail :("); }
protected void uploadImage(object sender, EventArgs e) { OrderezeTask.Image newimage = new OrderezeTask.Image(); if (!string.IsNullOrWhiteSpace(textboxName.Text)) newimage.Name = textboxName.Text; else newimage.Name = FileUploadControl.PostedFile.FileName; newimage.Description = textboxDescription.Text; newimage.ImagePath = FileUploadControl.PostedFile.FileName; imgsrv.AddNewImage(newimage); textboxName.Text = ""; textboxDescription.Text = ""; UpdateFileList(); }
public List<OrderezeTask.Image> GetImages() { List<OrderezeTask.Image> list = new List<OrderezeTask.Image>(); OrderezeTask.Image image; try { using (SqlConnection connection = new SqlConnection(connectionString)) { try { SqlCommand cmd = new SqlCommand("Select Id, Name, Description, ImagePath From " + databaseImagesTable); //cmd.CommandType = CommandType.Text; cmd.Connection = connection; connection.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { image = new OrderezeTask.Image(); image.Id = reader.GetInt32(0); image.Name = reader.GetString(1); image.Description = reader.GetString(2); image.ImagePath = reader.GetString(3); list.Add(image); } } } catch (Exception ex) { ex.ToString(); } } } catch { } return list; }