Check the existence of a file

0

This is my problem, in c #, the code generates txt files, I am creating a control panel that verifies the creation of these txt, with 1 if it exists and 0 that does not exist, the problem that arises is that once it finishes verifying the creation of the txt, in each update duplicates that verification

That is why I thought that this could be controlled, if I verify the existence of that file (code) in the StatusProcess table that I have. How can I capture that record and then compare it with the records that already exist in the table (StatusProcess), and if there is an update that would otherwise add it, that should be done in c # ?, please I need your help, thanks.

// HERE IS WHERE THE TXT GENERATES

string IDRepEstadoProceso = lcFactura.RucEmisor + "-" + lcFactura.TipoDocumento + "-" + lcFactura.SerieFactura + "-" + lcFactura.NumeroFactura;
                        estadoProceso = new ENT_EstadoProceso
                        {
                            ID = IDRepEstadoProceso,
                            Fecha = DateTime.Parse(lcFactura.FechaFactura),
                            Sucursal = lcFactura.CodSucursal
                        };
                        //crea base de dtos
                        //insertantdo el primer registro
                        repEstado.SaveEstadoProceso(estadoProceso);
                        // 12 .- GENERAR TXT DE CABECERA
                        String lcNombre = ConfigurationManager.AppSettings["cfSalidaTXT"]
                                                + "CAB-"
                                                 + lcFactura.TipoDocumento
                                                 + "-" + lcFactura.SerieFactura /// jjj
                                        + "-" + lcFactura.NumeroFactura
                                                + lcAnio
                                                + lcFactura.CodEmpresa
                                                + lcFactura.CodSucursal
                                                + ".txt";

                        System.IO.File.Delete(@lcNombre);
                        using (System.IO.StreamWriter file = new System.IO.StreamWriter(@lcNombre, true))
                        {

                            String lcLineaCab =
                                // DATOS FACTURA
                                lcFactura.TipoDocumento + "\t" +
                                lcFactura.SerieFactura + "\t" +
                                lcFactura.NumeroFactura + "\t" +
                                lcFactura.FechaFactura + "\t" +


                            file.WriteLine(lcLineaCab);
                            file.Close();
                        }
                        //VERIFICADOR DE CREACION GENTXT 1
                        estadoProceso.ID = IDRepEstadoProceso;
                        estadoProceso.GenCABTXT = 1;
                        repEstado.CabeceraOK(estadoProceso);

// // MY TABLE StateProcess Create it in this class

   private static void CreateDatabase()
    {
        using (var cnn = SimpleDbConnection())
        {
            cnn.Open();
            cnn.Execute(
                @"create table Seguimiento
                  (
                     ID                                  integer primary key AUTOINCREMENT,
                     RUC                                 varchar(15),
                     cpTipo                              varchar(2),
                     cpComprobante                       varchar(100) not null,
                     cpDescripcion                       varchar(100) not null,
                     cpEstado                            varchar(100) not null,
                     cpFecha                             datetime
                  )");
            cnn.Execute(
                @"create table EstadoProceso
                  (
                        ID               varchar(28) NOT NULL,
                        Fecha            datetime,
                        Sucursal         varchar(10),
                        GenCABTXT        int,
                        GenDETTXT        int,
                        GenXML           int,
                        GenFirmado       int,
                        GenZIP           int,
                        GenSUNAT         int,
                        GenEnviadoMail   int,
                        GenFTP           int,
                        RutaRespuesta    varchar(250)
                  )");
        }
    }

// Here create the StateProcess object

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Gem.DataAccess.Entity
 {
    public class ENT_EstadoProceso
    {
       //ID integer primary key AUTOINCREMENT,
       public string ID { get; set; }
       public DateTime Fecha { get; set; }
       public string Sucursal { get; set; }
       public int GenCABTXT { get; set; }
       public int GenDETTXT { get; set; }
       public int GenXML { get; set; }
       public int GenFirmado { get; set; }
       public int GenZIP { get; set; }
       public int GenSUNAT { get; set; }
       public int GenEnviadoMail { get; set; }
       public int GenFTP { get; set; }
       public string RutaRespuesta { get; set;}
   }
}
    
asked by Karen 22.06.2017 в 19:25
source

1 answer

2

Use the File.Exists (String) method

string curFile = @"c:\temp\test.txt";
Console.WriteLine(File.Exists(curFile) ? "File exists." : "File does not exist.");

You should use better stored products instead of c # code in the application.

    
answered by 22.06.2017 в 20:17