private void downLoadFile(string consecutivo, string pro_codi, string tableName, int emp_codi, string adj_nomb) { DAOGnRadju daoRadju = new DAOGnRadju(); DAOGnAdju daoAdju = new DAOGnAdju(); List <Digitalware.Apps.Utilities.TO.TOGnAdjun> adjun = new List <Digitalware.Apps.Utilities.TO.TOGnAdjun>(); string download = HttpContext.Current.Server.MapPath("~/download/"); string ftp = ConfigurationManager.AppSettings["servidorFTP"]; try { List <Digitalware.Apps.Utilities.TO.Gn_Adju.TOGnRadju> radju = daoRadju.GetRadju(emp_codi, pro_codi, consecutivo); if (radju == null || !radju.Any()) { throw new Exception("No hay adjuntos"); } int rad_cont = radju.FirstOrDefault().Rad_Cont; adjun = daoAdju.GetAdjun(emp_codi, rad_cont); if (adjun.Count == 0) { throw new Exception("No hay adjuntos"); } foreach (Digitalware.Apps.Utilities.TO.TOGnAdjun adjunto in adjun) { if (adjunto.Adj_Nomb == adj_nomb) { string directoryDefault = string.Format("ftp://{0}/Seven/docs/{1}/{1}_{2}_{3}_{4}", ftp.ToString(), tableName, emp_codi.ToString(), rad_cont, adjunto.Adj_Cont); List <DirectoryItem> filesExist = FTPManager.GetDirectoryInformation(directoryDefault); if (filesExist != null && filesExist.Count > 0) { DownloadFile(directoryDefault, download + adj_nomb); string data = System.IO.File.ReadAllText(download + adj_nomb); using (FileStream stream = System.IO.File.Create(download + adj_nomb)) { byte[] todecode_byte = Convert.FromBase64String(data); stream.Write(todecode_byte, 0, todecode_byte.Length); } } } } } catch (Exception ex) { ex.ToString(); } }
public TOTransaction <List <Digitalware.Apps.Utilities.TO.TOGnAdjun> > Get(string consecutivo, string pro_codi, string tableName, int emp_codi) { DAOGnRadju daoRadju = new DAOGnRadju(); DAOGnAdju daoAdju = new DAOGnAdju(); DAOGnAdjFi daoAdjF = new DAOGnAdjFi(); List <Digitalware.Apps.Utilities.TO.TOGnAdjun> adjun = new List <Digitalware.Apps.Utilities.TO.TOGnAdjun>(); List <TO.TOGnAdjFi> adjfi = new List <TO.TOGnAdjFi>(); string download = HttpContext.Current.Server.MapPath("~/download/"); string ftp = ConfigurationManager.AppSettings["servidorFTP"]; List <Digitalware.Apps.Utilities.TO.Gn_Adju.TOGnRadju> radju = daoRadju.GetRadju(emp_codi, pro_codi, consecutivo); try { if (radju == null || !radju.Any()) { throw new Exception("No hay adjuntos"); } int rad_cont = radju.FirstOrDefault().Rad_Cont; adjun = daoAdju.GetAdjun(emp_codi, rad_cont); if (adjun.Count == 0) { throw new Exception("No hay adjuntos"); } foreach (Digitalware.Apps.Utilities.TO.TOGnAdjun adjunto in adjun) { string directoryDefault = string.Format("ftp://{0}/Seven/docs/{1}/{1}_{2}_{3}_{4}", ftp.ToString(), tableName, emp_codi.ToString(), rad_cont, adjunto.Adj_Cont); List <DirectoryItem> filesExist = FTPManager.GetDirectoryInformation(directoryDefault); if (filesExist != null && filesExist.Count > 0) { DownloadFile(directoryDefault, download + adjunto.Adj_Nomb); } } return(new TOTransaction <List <Digitalware.Apps.Utilities.TO.TOGnAdjun> >() { objTransaction = adjun, retorno = 0, txtRetorno = "" }); } catch (Exception ex) { try { int rad_cont = radju.FirstOrDefault().Rad_Cont; adjfi = daoAdjF.GetAdjFi(emp_codi, rad_cont); if (adjfi.Count == 0) { throw new Exception("No hay adjuntos"); } foreach (TO.TOGnAdjFi adjuntF in adjfi) { DownloadFileFromDb(adjuntF.adj_nomb, adjuntF.adj_file); } return(new TOTransaction <List <Digitalware.Apps.Utilities.TO.TOGnAdjun> >() { objTransaction = adjun, retorno = 0, txtRetorno = "" }); } catch (Exception exc) { return(new TOTransaction <List <Digitalware.Apps.Utilities.TO.TOGnAdjun> >() { objTransaction = null, retorno = 1, txtRetorno = exc.Message }); } } }