private void SubirArchivo(Label label, FileUpload fileUpload, string nombreArchivo, int idBeneficiario)
        {
            string fileName     = nombreArchivo + proyecto.ID_PROYECTO + "_" + idBeneficiario + "_" + fileUpload.PostedFile.FileName;
            string folderPath   = Server.MapPath("~/Data/");
            string saveLocation = folderPath + "\\" + fileName;

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }

            try
            {
                fileUpload.PostedFile.SaveAs(saveLocation);

                A_DOCUMENTO.GuardarDocumento(idBeneficiario, saveLocation, nombreArchivo);

                label.Text      = "Se almaceno correctamente el archivo en el servidor";
                label.ForeColor = System.Drawing.Color.Green;
            }
            catch (Exception ex)
            {
                label.Text      = "Ocurrio un error al intentar subir el archivo al servidor " + ex.Message;
                label.ForeColor = System.Drawing.Color.Red;
                H_LogErrorEXC.GuardarRegistroLogError(ex);
            }
        }
コード例 #2
0
        public void DescargarArchivo(string fileName)
        {
            var documentos = A_DOCUMENTO.ObtenerXIdBeneficiario((int)problema.ID_BENEFICIARIO, fileName);

            foreach (var doc in documentos)
            {
                var file = new FileInfo(doc.DIRECCION);
                var ext  = Path.GetExtension(doc.DIRECCION).ToLower();

                if (!file.Exists)
                {
                    return;
                }

                Response.Clear();

                if (ext == ".jpg" || ext == ".jpeg")
                {
                    Response.ContentType = "image/jpeg";
                }
                else if (ext == ".png")
                {
                    Response.ContentType = "image/png";
                }
                else
                {
                    Response.ContentType = "application/pdf";
                }

                Response.AppendHeader("Content-Disposition",
                                      "attachment; filename=" + file.Name);
                Response.TransmitFile(doc.DIRECCION);
                Response.End();
            }
        }
コード例 #3
0
        //Sube el archivo al servidor
        private void SubirArchivo(Page page, FileUpload fileUpload, string nombreArchivo, int idBeneficiario)
        {
            string fileName     = nombreArchivo + "_" + idBeneficiario + "_" + fileUpload.FileName;
            string folderPath   = Server.MapPath("~/Data/");
            string saveLocation = folderPath + "\\" + fileName;

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }

            try
            {
                fileUpload.PostedFile.SaveAs(saveLocation);

                A_DOCUMENTO.GuardarDocumento(idBeneficiario, saveLocation, nombreArchivo);

                ScriptManager.RegisterStartupScript(page, page.GetType(), "Pop",
                                                    "alert('Se almaceno correctamente el archivo en el servidor');", true);
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(page, page.GetType(), "Pop",
                                                    "alert('Ocurrio un error al intentar subir el archivo al servidor " + ex.Message + " ');", true);

                H_LogErrorEXC.GuardarRegistroLogError(ex);
            }
        }
コード例 #4
0
        //Sube el archivo al servidor
        private void SubirArchivo(FileUpload fileUpload, string nombreArchivo, int idBeneficiario)
        {
            string fileName     = nombreArchivo + "_" + idBeneficiario + "_" + fileUpload.PostedFile.FileName;
            string folderPath   = Server.MapPath("~/Data/");
            string saveLocation = folderPath + "\\" + fileName;

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }

            if (fileUpload.AllowMultiple)
            {
                int i = 1;
                foreach (var uploadedFile in fileUpload.PostedFiles)
                {
                    saveLocation = folderPath + "\\" + i + "_" + fileName;
                    A_DOCUMENTO.GuardarDocumento(idBeneficiario, saveLocation, nombreArchivo);
                    uploadedFile.SaveAs(saveLocation);
                    i++;
                }
            }
            else
            {
                A_DOCUMENTO.GuardarDocumento(idBeneficiario, saveLocation, nombreArchivo);
                fileUpload.PostedFile.SaveAs(saveLocation);
            }
        }
コード例 #5
0
        public void DescargarArchivo(string fileName)
        {
            var idPropuesta = Convert.ToInt32(Page.RouteData.Values["idProblema"].ToString());
            var propuesta   = A_PROPUESTA.BuscarPropuestaXId(idPropuesta);
            var problema    = A_PROBLEMA.getByIdProblema(propuesta.ID_PROBLEMA);
            var documentos  = A_DOCUMENTO.ObtenerXIdBeneficiario((int)problema.ID_BENEFICIARIO, fileName);

            foreach (var doc in documentos)
            {
                var file = new FileInfo(doc.DIRECCION);
                var ext  = Path.GetExtension(doc.DIRECCION).ToLower();

                if (!file.Exists)
                {
                    return;
                }

                Response.Clear();

                if (ext == ".jpg" || ext == ".jpeg")
                {
                    Response.ContentType = "image/jpeg";
                }
                else if (ext == ".png")
                {
                    Response.ContentType = "image/png";
                }
                else
                {
                    Response.ContentType = "application/pdf";
                }

                Response.AppendHeader("Content-Disposition",
                                      "attachment; filename=" + file.Name);
                Response.TransmitFile(doc.DIRECCION);
                Response.End();
            }
        }