0

Hi, i have a form with data and I am tryin to save and load data using a texfile, any suggestion how I could start this as Im not too sure, thanks

4
Contributors
11
Replies
12
Views
6 Years
Discussion Span
Last Post by zachattack05
Featured Replies
  • Yup [CODE]StreamWriter fileOut = new StreamWriter("file.txt"); fileOut.WriteLine("stuff goes here"); fileOut.Close();[/CODE] then... [CODE] string strData = ""; StreamReader fileIn = new StreamReader("file.txt"); while(!fileIn.EndOfStream) { strData = fileIn.ReadLine(); } fileIn.Close(); [/CODE] Read More

1

Yup

StreamWriter fileOut = new StreamWriter("file.txt");
fileOut.WriteLine("stuff goes here");
fileOut.Close();

then...

string strData = "";
StreamReader fileIn = new StreamReader("file.txt");
while(!fileIn.EndOfStream)
{
   strData = fileIn.ReadLine();
}
fileIn.Close();

Edited by thines01: Added mor ecode

0

thines has a good suggestion.

If you are going to be holding many different pieces of data I would recommend delimiting the data in some fashion or otherwise structuring your file so that there is a "table of contents" so to speak so you can find where certain data is.

Unless it's absolutely necessary to store the data in a text file, you could serialize your data which might be easier.

0

I would recommend delimiting the data in some fashion or otherwise structuring your file so that there is a "table of contents" so to speak.

Zachattach05 has a good point look into using Xml to store data, you can structure your data using tags/ nodes and child tags/ nodes to add more structure to your data.

It's a good idea aswell because you can use this data across different DBMS'

0

XML works, but I avoid it like the plague.

XML files are bloated for the sake of "human readability."

I always use straight up binary serialization. You could always include a "export to XML" feature :)

0

pretty hardcore going all the way down to binary, it would take up a lot less space but would binary be as re-usable and readable by other users as xml ?

0

Yup

StreamWriter fileOut = new StreamWriter("file.txt");
fileOut.WriteLine("stuff goes here");
fileOut.Close();

then...

string strData = "";
StreamReader fileIn = new StreamReader("file.txt");
while(!fileIn.EndOfStream)
{
   strData = fileIn.ReadLine();
}
fileIn.Close();

thank you, I have the data in a textbox, so where in the code would I tell the program the name of this textbox to get the data from, and the path of the file, thanks a lot

0

i figured it out, could someone tell me how I would insert a new line

objWriter.Write(txtName.Text);
objWriter.Write(txtTelephone.Text);
objWriter.Write(txtAddress.Text);

atm it saves but its all squashed together. thanks

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.