2
Can someone tell me the C# method for saving a document to a default folder in Code? In this case wanted the program to automatically save itself to the Desktop.
This is the code I currently have on the button, but I intend to do it right on Load.
private void button1_Click(object sender, EventArgs e)
{
SaveFileDialog salvar = new SaveFileDialog();
salvar.Filter = "Ficheiro de Configuração|*.cnf";
salvar.DefaultExt = "txt";
DialogResult salvou = salvar.ShowDialog();
if (salvou == DialogResult.OK)
{
StreamWriter sw = null;
try
{
sw = new StreamWriter(salvar.FileName);
sw.WriteLine(txtConfig.Text);
MessageBox.Show("Gravado com Sucesso!", "Sucesso",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
catch (IOException ex)
{
MessageBox.Show("IOException:\r\n\r\n" + ex.Message);
}
catch (Exception ex)
{
MessageBox.Show("Exception : \r\n\r\n" + ex.Message);
}
finally
{
if (sw != null)
sw.Close();
}
this.Close();
}
}
Cumps
What kind of document? What do you mean 'automatically'?
– William Pereira
@williamhk2 I have a textbox with written values. I currently have a button that when clicking, opens the Savedialog, now I wanted it to be automatically in Load, that is, when opening the Form, whatever is inside the textbox will save the file . txt on Desktop. Cumps.
– Don Vito
Could you post the code snippet? and describe what you commented, in the question?
– William Pereira
Already a friend @williamhk2.
– Don Vito
Beauty ;) @Godfathersantana
– William Pereira