public SelectDocumento_Path ( |
||
oENTDocumento | Entidad de Documento con los parámetros necesarios para realizar la transacción | |
return |
// Rutinas el programador void DeleteDocumento(Int32 DocumentoId) { ENTDocumento oENTDocumento = new ENTDocumento(); ENTResponse oENTResponse = new ENTResponse(); BPDocumento oBPDocumento = new BPDocumento(); try { // Formulario oENTDocumento.DocumentoId = DocumentoId; // Consultar información del archivo oENTResponse = oBPDocumento.SelectDocumento_Path(oENTDocumento); // Errores y Warnings if (oENTResponse.GeneratesException) { throw (new Exception(oENTResponse.sErrorMessage)); } if (oENTResponse.sMessage != "") { throw (new Exception(oENTResponse.sMessage)); } // Eliminar físicamente el archivo if (File.Exists(oENTResponse.dsResponse.Tables[1].Rows[0]["Ruta"].ToString())) { File.Delete(oENTResponse.dsResponse.Tables[1].Rows[0]["Ruta"].ToString()); } // Eliminar la referencia del archivo en la base de datos oENTResponse = oBPDocumento.DeleteDocumento(oENTDocumento); // Errores y Warnings if (oENTResponse.GeneratesException) { throw (new Exception(oENTResponse.sErrorMessage)); } if (oENTResponse.sMessage != "") { throw (new Exception(oENTResponse.sMessage)); } // Estado inicial del formulario this.ckeDescripcion.Text = ""; // Refrescar el formulario SelectSolicitud(); // Foco ScriptManager.RegisterStartupScript(this.Page, this.GetType(), Convert.ToString(Guid.NewGuid()), "function pageLoad(){ focusControl('" + this.fupArchivo.ClientID + "'); }", true); }catch ( IOException ioEx){ throw (ioEx); }catch (Exception ex){ throw (ex); } }
// Eventos public void ProcessRequest(HttpContext httpContext) { ENTDocumento oENTDocumento = new ENTDocumento(); ENTResponse oENTResponse = new ENTResponse(); BPDocumento oBPDocumento = new BPDocumento(); MemoryStream msFile; FileStream fsFile; Byte[] byteFile; Int32 DocumentoId; try { // Validaciones de llamada if (httpContext.Request.QueryString["key"] == null) { httpContext.Response.Redirect("~/Application/WebApp/Private/SysApp/saNotificacion.aspx", false); return; } // Obtener el id del documento DocumentoId = Int32.Parse(gcEncryption.DecryptString(httpContext.Request.QueryString["key"], true)); // Consultar la ruta del archivo oENTDocumento.DocumentoId = DocumentoId; oENTResponse = oBPDocumento.SelectDocumento_Path(oENTDocumento); // Errores y Warnings if (oENTResponse.GeneratesException) { throw (new Exception(oENTResponse.sErrorMessage)); } if (oENTResponse.sMessage != "") { throw (new Exception(oENTResponse.sMessage)); } // Obtener el archivo fsFile = new System.IO.FileStream(oENTResponse.dsResponse.Tables[1].Rows[0]["Ruta"].ToString(), System.IO.FileMode.Open, System.IO.FileAccess.Read); byteFile = new Byte[fsFile.Length]; fsFile.Read(byteFile, 0, (int)fsFile.Length); fsFile.Close(); // Validación if (byteFile == null) { throw (new Exception("No se encontró el archivo")); } // Cambiar los contet de la página httpContext.Response.ContentType = "application/x-unknown/octet-stream"; httpContext.Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + oENTResponse.dsResponse.Tables[1].Rows[0]["Nombre"].ToString() + "\""); // Descargar el archivo msFile = new MemoryStream(byteFile, true); msFile.Write(byteFile, 0, byteFile.Length); httpContext.Response.BinaryWrite(byteFile); httpContext.Response.Flush(); }catch (IOException ioEx){ httpContext.Response.Write(ioEx.Message); }catch (Exception ex){ httpContext.Response.Write(ex.Message); }finally{ httpContext.Response.End(); } }