VideoHelp Forum
+ Reply to Thread
Results 1 to 3 of 3
Thread
  1. Man of Steel freebird73717's Avatar
    Join Date
    Dec 2003
    Location
    Smallville, USA
    Search PM
    Hello.

    I am in the process of writing a gui and am stuck on one piece of code. I have a listbox that contains text. I would like to click my save button and be able to save the contents of the listbox to a text file. So far I can click "save" and give the file I'm "saving" a name and that goes okay...but nothing really happens. I know I need to use a function like streamreader and or streamwriter I'm just at a loss how. Any body have any clues?

    Here is the code I have now

    Code:
    void Button3Click(object sender, EventArgs e)
    		{
    			if (saveFileDialog2.ShowDialog() == DialogResult.OK);
    		}
    Any help would be appreciated.
    Donadagohvi (Cherokee for "Until we meet again")
    Quote Quote  
  2. Member tekkieman's Avatar
    Join Date
    Mar 2004
    Location
    Over the hill
    Search Comp PM
    Here's some code from an app that writes to a file:

    Code:
    StreamWriter log = new StreamWriter(logfile.FullName, true);
    log.WriteLine(DateTime.Now + "\t Could not find the ini file - " + aName + Environment.NewLine);
    The streamwriter constructor take a path to your file, and the true/false parameter is for appending/overwriting. In my code, the logfile is a FileInfo object, and the fullname property contains the fully qualified path/filename. The writeline sends the line of text to the file. Remember to close the file when finished writing.


    Hope this helps. Let me know if you need more...
    Quote Quote  
  3. Man of Steel freebird73717's Avatar
    Join Date
    Dec 2003
    Location
    Smallville, USA
    Search PM
    Thanks for the reply tekkieman. I tried your code but got errors. However I did come up with some code that works.

    Code:
    void Button3Click(object sender, EventArgs e)
    		{
    		if (saveFileDialog2.ShowDialog() == DialogResult.OK)	
      {
        System.IO.StreamWriter sw = new System.IO.StreamWriter(saveFileDialog2.FileName);
     
        foreach (object item in listBox1.Items)
        
        	sw.WriteLine(item.ToString());
     
          sw.Close();
    		};}
    I do appreciate the help though.

    My gui is finished now. It is a batch processing gui for HCenc. I started a new thread on it Here. If you get the chance you might check it out and give me some feedback. It is my first attempt at writing a gui.
    Donadagohvi (Cherokee for "Until we meet again")
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!