[C#]

01/24/2011 06:42 aowi#1
How to save and load external files ?
eg. I will write a series of number on listbox how can i code the button for the load and save to load and save my settings from an ini extension?

and also if i select a number on the listbox and click use number it will display on
textbox1 .
I'm sorry i'm just a beginner on c#
01/24/2011 13:19 pro4never#2
stream reader/stream writer if you want it to be a text file or binary read/writer for binary files (.dat or w/e)

Example code...
Code:
            StreamReader SR = new StreamReader(File.Open("filename.txt", FileMode.Open));
            string AllFile = SR.ReadToEnd();
            string[] FileLines = AllFile.Split('\n');
            foreach (string S in FileLines)
                Console.WriteLine(S);
            SR.Close();
Here's an example of a writer

Code:
            StreamWriter SW = new StreamWriter(File.Open("filename.txt", FileMode.OpenOrCreate));
            SW.WriteLine("Line 1");
            SW.WriteLine("Line 2");
            SW.WriteLine("Line 3");
            SW.Flush();
            SW.Close();
VERY basic applications of both systems but hopefully it gives you some ideas.
01/24/2011 19:41 .Kinshi#3
Code:
string in;
while (!SR.EndOfFile) {
    in = SR.ReadLine();
}
Easier way to read each line of the file.
01/25/2011 01:08 pro4never#4
Quote:
Originally Posted by .Kinshi View Post
Code:
string in;
while (!SR.EndOfFile) {
    in = SR.ReadLine();
}
Easier way to read each line of the file.
Ahh didn't ever use that before :P. Good to know.
01/25/2011 08:52 aowi#5
Quote:
Originally Posted by pro4never View Post
stream reader/stream writer if you want it to be a text file or binary read/writer for binary files (.dat or w/e)

Example code...
Code:
            StreamReader SR = new StreamReader(File.Open("filename.txt", FileMode.Open));
            string AllFile = SR.ReadToEnd();
            string[] FileLines = AllFile.Split('\n');
            foreach (string S in FileLines)
                Console.WriteLine(S);
            SR.Close();
Here's an example of a writer

Code:
            StreamWriter SW = new StreamWriter(File.Open("filename.txt", FileMode.OpenOrCreate));
            SW.WriteLine("Line 1");
            SW.WriteLine("Line 2");
            SW.WriteLine("Line 3");
            SW.Flush();
            SW.Close();
VERY basic applications of both systems but hopefully it gives you some ideas.
thank you! I'm gonna try this, I'm just a beginner on c#.

edit:
This code is for opening a file but my main problem for now is how can i set the selected variable shown on the listbox to my textbox?

I've tried

Code:
textBox1.Text(listBox1.Item.Selected)
but it gives me an error on ".Text" :S

Quote:
Originally Posted by .Kinshi View Post
Code:
string in;
while (!SR.EndOfFile) {
    in = SR.ReadLine();
}

Easier way to read each line of the file.
Nice :) this is for richtextstream right ?
01/25/2011 12:37 messi100#6
Thanks
01/25/2011 18:32 Ian*#7
Just a tip. Google is your best friend if you don't know how to do something.

Search for - [Question] [Language]
Example - Text Files C#

[Only registered and activated users can see links. Click Here To Register...]