Save text box to file

I am trying to save some information entered into a text box to a file.  This is what i have, but I keep getting the error that follows.  I tried changing it to myStream->Write(tp) but that doesn't work either.  Help Please!!

private: System::Void button3_Click(System::Object *  sender, System::EventArgs *  e)
                   {
                        Stream *myStream;
                        SaveFileDialog* saveFileDialog1 = new SaveFileDialog();
                        saveFileDialog1->Filter = S"txt files (*.txt)|*.txt|All files (*.*)|*.*"  ;
                        saveFileDialog1->FilterIndex = 2 ;
                        saveFileDialog1->RestoreDirectory = true ;
                  
                        if(saveFileDialog1->ShowDialog() == DialogResult::OK)
                        {
                              if((myStream = saveFileDialog1->OpenFile()) != NULL)
                              {
                                    // Code to write the stream goes here.
                                    String *tp = this->OutputBox->ToString();
                                    myStream->WriteText(tp,0,this->OutputBox->ToString()->Length);
                                    myStream->Close();
                              }
                        }
                   }
DPhoenix121Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mahesh1402IT ProfessionalCommented:
what error you are getting ?

MAHESH
amit_gCommented:
Use

        private: System::Void button3_Click(System::Object *  sender, System::EventArgs *  e)
                {
                    SaveFileDialog* saveFileDialog1 = new SaveFileDialog();
                    saveFileDialog1->Filter = S"txt files (*.txt)|*.txt|All files (*.*)|*.*"  ;
                    saveFileDialog1->FilterIndex = 2 ;
                    saveFileDialog1->RestoreDirectory = true ;
               
                    if(saveFileDialog1->ShowDialog() == DialogResult::OK)
                    {
                        String *tp = this->OutputBox->ToString();
                        StreamWriter *sr = File.CreateText(saveFileDialog1->FileName);
                        sr->WriteLine(tp);
                        sr->Close();
                    }
                }

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Knut HunstadCommented:
I think that in C# you need to declare:

Stream myStream;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
 
instead of as pointers, according to the help documentation in VS.

P.S.: You forgot to write what error you get :-)
DPhoenix121Author Commented:
Thanks everyone.  Amit_Q's answer worked perfectly.  Really appreciate it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual C++.NET

From novice to tech pro — start learning today.