public static Result guardar(int id, int opcionMaestroAnexoId, int?registroTablaId, HttpPostedFile anexo, int usuarioId) { Result r = ValidateSession.validarSession(usuarioId, HttpContext.Current.Session["usuarioId"]); if (r.error != "") { return(r); } Anexos a = new Anexos(); a.id = id; a.opcionMaestroAnexoId = opcionMaestroAnexoId; a.registroTablaId = registroTablaId; // a.anexo = anexo; a.usuarioId = usuarioId; try { AnexoController ac = new AnexoController(); return(ac.guardarAnexos(a)); } catch (Exception ex) { return(new Result() { error = ex.Message, id = 0, tipoAlerta = "warning" }); } }
protected void Button1_Click(object sender, EventArgs e) { if ((File1.PostedFile != null) && (File1.PostedFile.ContentLength > 0)) { string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName); string valueTipoAnexo = cmbTipoAnexo.SelectedValue; string val = hRegistro.Value; try { byte[] fileData = null; using (var binaryReader = new BinaryReader(File1.PostedFile.InputStream)) { fileData = binaryReader.ReadBytes(File1.PostedFile.ContentLength); } AnexoController ac = new AnexoController(); Anexos a = new Anexos(); a.anexo = fileData; a.consecutivoTemporal = hConsecutivo.Value; a.id = 0; a.opcionMaestroAnexoId = int.Parse(valueTipoAnexo); a.nombreAnexo = fn; try { a.registroTablaId = int.Parse(hRegistro.Value.ToString()); } catch (Exception) {} a.usuarioId = int.Parse(Session["usuarioId"].ToString()); Result r = ac.guardarAnexos(a); if (r.error != "") { Response.Write("<h1> Error: " + r.error + "</h1>"); } } catch (Exception ex) { Response.Write("Error: " + ex.Message); //Note: Exception.Message returns detailed message that describes the current exception. //For security reasons, we do not recommend you return Exception.Message to end users in //production environments. It would be better just to put a generic error message. } } else { Response.Write("Please select a file to upload."); } }