Link to home
Start Free TrialLog in
Avatar of DPhoenix121
DPhoenix121

asked on

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();
                              }
                        }
                   }
Avatar of mahesh1402
mahesh1402
Flag of India image

what error you are getting ?

MAHESH
ASKER CERTIFIED SOLUTION
Avatar of amit_g
amit_g
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 :-)
Avatar of DPhoenix121
DPhoenix121

ASKER

Thanks everyone.  Amit_Q's answer worked perfectly.  Really appreciate it.