You see, I need to do the following.
My level of programming in this is minimal since we have only followed a small guide provided by the teacher and it does not cover most of the things written here. Just the save.
Save data in a txt for example. Done and functional.
Open the Txt. (I do not know)
Load Txt data to different TextBox (I do not know)
Save Name: {0} (what you have written in the program) And save it with the file search where I indicated.
Now I need to know how to open that txt. Using the file browser. '
SaveFileDialog saveDialog = new SaveFileDialog();
saveDialog.DefaultExt = "txt";
saveDialog.AddExtension = true;
saveDialog.FileName = textboxApellidos.Text;
saveDialog.InitialDirectory = @"C:\Users\Javier\Documents\";
saveDialog.OverwritePrompt = true;
saveDialog.Title = "Citas";
saveDialog.ValidateNames = true;
if (saveDialog.ShowDialog().Value)
{
using (StreamWriter writer = new StreamWriter(saveDialog.FileName))
{
writer.WriteLine("Nombre: {0}", textboxNombre.Text);
writer.WriteLine("Apellido: {0}", textboxApellidos.Text);
if (hombreCB.IsChecked == true)
{
writer.WriteLine("Sexo: {0}", hombreCB.Content.ToString());
}
else
{
writer.WriteLine("Sexo: {0}", mujerCB.Content.ToString());
}
writer.WriteLine("Próxima cita: {0}", proximaCita.Text);
writer.WriteLine("Sintomas:{0} ", textboxSintomas.Text);
writer.WriteLine("Diagnóstico:{0} ", textboxDiagnostico.Text);
writer.WriteLine("Doctor: {0}", doctorsCB.Text);
MessageBox.Show("Cita guardada.");
}
}
}'
This is the code to save it, but I am unable to figure out how to open it, much less load the data I have saved in a textbox. Any help would be great.
This is the new code that I created with the help of a response. 'private void AccessCita_Click (object sender, RoutedEventArgs e) {
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\" ;
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;
StreamReader fp; char[] buffer = new char[160]; int i = 0; string texto; string[] split = null; bool bok = true;
if (openFileDialog1.ShowDialog() == true)
{
string line;
string filename = openFileDialog1.FileName;
fp = new StreamReader(filename);
if (fp != null)
{
Paciente concita = new Paciente();
concita.ShowDialog();
i = 0;
do
{
texto = fp.ReadLine();
i++;
if (texto != null)
{
if (texto.Length > 2)
{
split = texto.Split(';');
concita.textboxNombre.Text = split[0];
concita.textboxApellidos.Text = split[1];
// concita.textboxSexo.Text = split[2];
concita.textboxSintomas.Text = split[3];
concita.textboxDiagnostico.Text = split[4];
}
}
} while (!fp.EndOfStream);
}
fp.Close();
if (i > 1)
MessageBox.Show("Carga de archivo terminada..." + i.ToString());
}
}'
The file search engine opens, I select the appointment and a new window opens, but the data is not filled in. In addition, closing the appointment window gives an error.