Register for your free account! | Forgot your password?

You last visited: Today at 14:55

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[C#]

Discussion on [C#] within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Jan 2011
Posts: 5
Received Thanks: 0
Question [C#]

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#
aowi is offline  
Old 01/24/2011, 13:19   #2
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,376
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.
pro4never is offline  
Thanks
2 Users
Old 01/24/2011, 19:41   #3
 
.Kinshi's Avatar
 
elite*gold: 0
Join Date: Dec 2010
Posts: 341
Received Thanks: 255
Code:
string in;
while (!SR.EndOfFile) {
    in = SR.ReadLine();
}
Easier way to read each line of the file.
.Kinshi is offline  
Thanks
1 User
Old 01/25/2011, 01:08   #4
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,376
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.
pro4never is offline  
Old 01/25/2011, 08:52   #5
 
elite*gold: 0
Join Date: Jan 2011
Posts: 5
Received Thanks: 0
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 ?
aowi is offline  
Old 01/25/2011, 12:37   #6
 
messi100's Avatar
 
elite*gold: 0
Join Date: Mar 2010
Posts: 261
Received Thanks: 1,167
Thanks
messi100 is offline  
Old 01/25/2011, 18:32   #7
 
Ian*'s Avatar
 
elite*gold: 0
Join Date: Nov 2006
Posts: 805
Received Thanks: 464
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#

Ian* is offline  
Reply




All times are GMT +2. The time now is 14:55.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.