protected void enviarButton_Click(object sender, EventArgs e) { try { HttpPostedFile file = figuraFileUpload.PostedFile; if (file == null || string.IsNullOrEmpty(file.FileName) || file.InputStream == null) { throw new Exception("Arquivo invalido para o produto"); } Produto produto = new Produto(); produto.IdCategoria = Convert.ToInt32(categoriaDropDownList.SelectedValue); produto.Descricao = descricaoTextBox.Text; produto.Unidade = unidadeDropDownList.SelectedValue; produto.Preco = Convert.ToDouble(precoTextBox.Text); produto.MimeType = file.ContentType; byte[] bytes = new byte[file.InputStream.Length]; file.InputStream.Read(bytes, 0, bytes.Length); produto.Foto = bytes; ProdutosDao.IncluirProduto(produto); mensagemLabel.CssClass = "alert alert-success"; mensagemLabel.Text = "Produto incluido com sucesso"; } catch (Exception ex) { mensagemLabel.CssClass = "alert alert-danger"; mensagemLabel.Text = ex.Message; } }