Jump to content

saveFileDialog Help

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
edreil143

edreil143

    Newbie

  • Members
  • Pip
  • 2 posts
Hi there guys, can I ask help in fixing this code?

private void simpleButton1_Click(object sender, EventArgs e)

        {

            Stream myStream;

            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter = "Text Files (*.txt)|*.txt|All files (*.*)|*.*";

            saveFileDialog1.FilterIndex = 1;

            saveFileDialog1.RestoreDirectory = true;

           


            if (saveFileDialog1.ShowDialog() == DialogResult.OK)

            {

                if (( myStream = saveFileDialog1.OpenFile()) != null)

                {

                    StreamWriter Text = new StreamWriter(myStream);

                    Text.WriteLine(textBox1.Text);

                    Text.WriteLine(textBox1.Text.ToString());

                    Text.WriteLine(memoEdit1.Text);

                    Text.WriteLine(memoEdit1.Text.ToString());

                    Text.WriteLine(memoEdit1.ToString());

                    myStream.Close();

                }

            }

        }

In this scenario, I tried to have 2 components to contain text namely textBox1 and memoEdit1. What I'm trying to do is that when I click this button, a dialog box appears and ask me where to save the file(Text File) and after which it creates a text file that copies the contents of my textBox1 and memoEdit1 into it. But in my case, yes it successfully created a text file but it's empty, I tried various ways to for this but I always fail. I would really appreciate your help. Thnx in advance.

#2
edreil143

edreil143

    Newbie

  • Members
  • Pip
  • 2 posts
I solved this problem thnx! Closed :D

#3
raissazhou02

raissazhou02

    Newbie

  • Members
  • Pip
  • 1 posts
I think there is something wrong with this code, but i can not find it, so sorry.I want to copy it to my friend, he is a expert, it will be help then.

#4
ArekBulski

ArekBulski

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,376 posts
We would not mind if you would show us what was wrong, sorta as a warning for us. ;)