public DocumetoNormativa ShowDocumentFile(int FileID) { string SQL = "SELECT FILE_SIZE, FILE_DATA, CONTENT_TYPE, FILE_NAM FROM DOCUMENTO_NORMATIVA WHERE ID_DOCUMENTO = " + FileID.ToString(); // Create Connection object OleDbConnection dbConn = new OleDbConnection("Provider=SQLOLEDB; Data Source=163.178.173.148;Initial Catalog=ProyectoII_Lenguajes_2017;User ID=lenguajes;Password=lenguajes"); // Create Command Object OleDbCommand dbComm = new OleDbCommand(SQL, dbConn); // Open Connection dbConn.Open(); // Execute command and receive DataReader OleDbDataReader dbRead = dbComm.ExecuteReader(); // Read row dbRead.Read(); DocumetoNormativa document = new DocumetoNormativa(FileID, (string)dbRead["FILE_NAM"], (int)dbRead["FILE_SIZE"], (string)dbRead["CONTENT_TYPE"], (byte[])dbRead["FILE_DATA"]); // Close database connection dbConn.Close(); return(document); }
public DocumetoNormativa documento() { DocumetoNormativa documento = new DocumetoNormativa(); if (fuDocument.PostedFile != null) { HttpPostedFile currentImage = fuDocument.PostedFile; int size = currentImage.ContentLength; documento.Size = size; documento.Nombre = currentImage.FileName; documento.ContentType = currentImage.ContentType; documento.Data = new byte[size]; currentImage.InputStream.Read(documento.Data, 0, size); } return(documento); }
protected void Page_Load(object sender, EventArgs e) { int id = int.Parse(Request.QueryString["id"]); string connectionString = WebConfigurationManager.ConnectionStrings["ProyectoII"].ConnectionString; EvidenciaBusiness evidBussines = new EvidenciaBusiness(connectionString); DocumetoNormativa doc = evidBussines.ShowDocumentNormativa(id); // Clear Response buffer Response.Clear(); // Set ContentType to the ContentType of our file Response.ContentType = doc.ContentType; // Write data out of database into Output Stream Response.OutputStream.Write(doc.Data, 0, doc.Size); // End the page Response.End(); }
private DocumetoNormativa WriteDocumentNoramativaToDB(DocumetoNormativa documento) { SqlCommand cmd = new SqlCommand(); SqlConnection conn = new SqlConnection(this.connectionString); SqlTransaction transaction = null; // Estableciento propiedades cmd.Connection = conn; cmd.CommandText = "insert_document_normativa"; cmd.CommandType = System.Data.CommandType.StoredProcedure; // Creando los parámetros necesarios cmd.Parameters.Add("@name", System.Data.SqlDbType.VarChar); cmd.Parameters.Add("@size", System.Data.SqlDbType.Int); cmd.Parameters.Add("@type", System.Data.SqlDbType.VarChar); cmd.Parameters.Add("@data", System.Data.SqlDbType.VarBinary); // Asignando los valores a los atributos cmd.Parameters["@name"].Value = documento.Nombre; cmd.Parameters["@size"].Value = documento.Data.Length; cmd.Parameters["@type"].Value = documento.ContentType; cmd.Parameters["@data"].Value = documento.Data; //Asignamos el parametro de salida SqlParameter parametroId = new SqlParameter("@id", System.Data.SqlDbType.Int); parametroId.Direction = System.Data.ParameterDirection.Output; cmd.Parameters.Add(parametroId); //Inicia transaccion try { conn.Open(); transaction = conn.BeginTransaction(); cmd.Connection = conn; cmd.Transaction = transaction; //Ejecutamos y obtenemos el id de la imagen guardada cmd.ExecuteNonQuery(); documento.IdDocumento = Int32.Parse(cmd.Parameters["@id"].Value.ToString()); transaction.Commit(); } catch (SqlException ex) { if (transaction != null) { transaction.Rollback(); } throw ex; } finally { if (conn != null) { conn.Close(); } } return(documento); }