Witam, mam problem z kawałkiem kodu, a mianowicie przy wykorzystaniu saveFileDialog chcę zapisać plik .txt i tu pojawia się problem, a mianowicie dodałem button, który okodowałem i pomimo podanej treści plik zapisuje się pusty. Co robię źle? Czego w kodzie za dużo / za mało?
Jestem laikiem w C# i to w sumie mój pierwszy program ( dodam, że przy użyciu System.IO.File.WriteAllText plik zapisuje się z podaną treścią ). Poniżej przedstawiam kod.
private void button3_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "Txt File|*.txt";
saveFileDialog1.Title = "Save an Text File";
saveFileDialog1.ShowDialog();
if (saveFileDialog1.FileName != "")
{
System.IO.FileStream fs =
(System.IO.FileStream)saveFileDialog1.OpenFile();
string text = " ________________________________________________________ \r\n" +
"| | | | \r\n" +
"| Dimension | Angle | Bend Lenght | \r\n" +
"| | | | \r\n" +
"|---------------|---------------------|------------------| \r\n" +
"| " + textBox_Dim1.Text + " " + textBox_Angle1.Text + " " + textBox_bendl1.Text + " \r\n" +
"|---------------|---------------------|------------------| \r\n" +
"| " + textBox_Dim2.Text + " " + textBox_Angle2.Text + " " + textBox_bendl2.Text + " \r\n" +
"|---------------|---------------------|------------------| \r\n" +
"| " + textBox_Dim3.Text + " \r\n" +
"|---------------|---------------------|------------------| \r\n" +
"\r\n" +
"L= " + textBox_L.Text;
fs.Close();
}
}
Z góry dziękuję za wszelkie podpowiedzi i proszę o wyrozumiałość, gdyż to mój pierwszy post na tym forum :)