What I try to do is create 2 files in the system, one where the user can choose where he wants to save his database file where all the records of his products will be stored. The other file txt
would be created without the user's permission and will already be located on the disk C
, the point is that this file will have stored the path of the txt file of the database.
The only problem that I present is that the file that I create without the user's permission is that it does not store the file path of the database.
private void btnRuta_Click(object sender, EventArgs e)
{
//Aquí creo 2 variables que serian archivos .txt, creo una para la base de datos en un grid y otra que me almacene la ruta de esta base de dato.
string dataBase;
string rutaDataBase = @"Bibliotecas\Documentos\rutaDataBase.txt";
SaveFileDialog salvarArchivo = new SaveFileDialog();
salvarArchivo.Filter = "archivo de texto|*.txt";
if (salvarArchivo.ShowDialog() == DialogResult.OK) {
dataBase = new FileInfo(salvarArchivo.FileName).DirectoryName;
StreamWriter escritor = new StreamWriter(salvarArchivo.FileName);
escritor.Write(dataBase);//Aqui si funciona, pero el punto es que salga en el otro archivo txt.
escritor.Close();
System.IO.File.CreateText(rutaDataBase).Write(dataBase); //AQUÍ ES DONDE NO ME ESCRIBE LA RUTA DE MI DATABASE EN MI ARCHIVO DE TEXTO
}
}