Execute a form (or create file) only when the program is opened for the first time

1

I want to know if there is a way for me to create a form to be opened only the first time the program is run. Because the form should create a file on the system with the login the first time the program is run only, it can not create the file whenever the user opens the program because if the login has been changed it will be changed back to the default.

Another option would be to create the file at the time of installing the program but I do not know how to do that, I already researched a lot and found nothing.

There is no code because I could not do anything, I just tried to put File.Create("caminho"); on the splash screen, but it always creates a new file and replaces the old one, thus losing the information written to it.     

asked by anonymous 28.06.2015 / 06:59

1 answer

1

Well, I got it here, so it was just under the% splash screen (for it to create before opening the first form)

//Cria variavel com uma nova instância com informações de tal arquivo
FileInfo arq = new FileInfo("caminho-arquivo");

// se o arquivo não existir (por isso == false) ele é criado
if (arq.Exists == false)
{
    File.Create("caminho-arquivo");
}
// se não ele não faz nada, continua sua execução normal
else{}

Remembering to import the IO library (% with%)

    
28.06.2015 / 16:45