public string LeerFicheroDeDisco(string nombreFichero) { Directorios directorio = new Directorios(); _rutaNombreFichero = directorio.ObtenerRuta(nombreFichero); string _datos = ""; if (_rutaNombreFichero != "") { // se ha comentado para no hacer pruebas con el de real if (Properties.Resources.entorno.ToUpper() == "PRODUCCION") { LeerFicheroDeWeb leerFicheroWeb = new LeerFicheroDeWeb(); bool datos = leerFicheroWeb.Bajar(_rutaNombreFichero); } // log.Info("Fichero descargado: " + _rutaNombreFichero); try { using (StreamReader sr = new StreamReader(_rutaNombreFichero)) { // Read the stream to a string, and write the string to the console. _datos = sr.ReadToEnd(); sr.Close(); } } catch (Exception exc) { string tipoExcepcion = exc.InnerException.GetType().ToString(); log.Error("No se ha podido leer el archivo " + _rutaNombreFichero + " " + exc.Message); } } //if (ObtenerCarpeta(nombreFichero)) return(_datos); } // public string LeerFichero(string nombreFichero)
public string GuardarFicheroEnDisco(string nombreFichero, string datos) { Directorios directorio = new Directorios(); string _rutaNombreFichero = directorio.ObtenerRuta(nombreFichero); try { if (directorio.ObtenerRuta(nombreFichero) != "") { //_rutaNombreFichero = string.Format("{0}\\{1}", _directorio, nombreFichero); try { // Delete the file if it exists. if (File.Exists(_rutaNombreFichero)) { File.Copy(_rutaNombreFichero, _rutaNombreFichero + ".bak"); File.Delete(_rutaNombreFichero); } using (FileStream fs = File.Create(_rutaNombreFichero)) { byte[] info = new UTF8Encoding(true).GetBytes(datos); fs.Write(info, 0, info.Length); fs.Close(); log.Info("Fichero guardado en disco: " + _rutaNombreFichero); } } catch (Exception exc) { File.Delete(_rutaNombreFichero); File.Copy(_rutaNombreFichero + ".bak", _rutaNombreFichero); log.Info("Fichero recuperado de version anterior. " + exc.Message); } } } catch (Exception exc) { log.Error("Excepcion al guardar fichero en disco: " + _rutaNombreFichero + ". " + exc.Message); } return("OK"); }