Hi again to All,
How it would be possible to save some Datas (strings and int) to a *.txt file ?
I have found some informations but the examples are all about saving text in a textbox (multiline) to a txt file.
I will need to write some strings/int which are allready decleared to a file.
thanx again


Sukesh MarlaRank #461 · 5.4K reputationPosted Aug 22, 2012, 9:25 PM EDT
string[] lines = {"First line", "Second line", "Third line"};
System.IO.File.WriteAllLines(@"C:\Users\Public\TestFolder\WriteLines.txt", lines);
// Example #2: Write one string to a text file.
string text = "A class is the most powerful data type in C#. Like structures, " +
"a class defines the data and behavior of the data type. ";
System.IO.File.WriteAllText(@"C:\Users\Public\TestFolder\WriteText.txt", text);
// Example #3: Write only some strings in an array to a file.
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\Public\TestFolder\WriteLines2.txt"))
{
foreach (string line in lines)
{
if (line.Contains("Second") == false)
{
file.WriteLine(line);
}
}
}
// Example #4: Append new text to an existing file
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\Public\TestFolder\WriteLines2.txt", true))
{
file.WriteLine("Fourth line");
}
}
Check this is corerct answer if it helped
Javeed M ShaikhRank #839 · 2.7K reputationPosted Aug 22, 2012, 9:09 AM EDT
#1:
#2:
#3:
Jignesh TrivediRank #16 · 50.3K reputationPosted Aug 22, 2012, 7:32 PM EDT
Please refer...
http://msdn.microsoft.com/en-us/library/8bh11f1k.aspx
http://msdn.microsoft.com/en-us/library/aa287548%28v=vs.71%29.aspx
http://msdn.microsoft.com/en-us/library/system.io.file.appendtext.aspx
hope this will help you.
ilhami caliskan79 reputationPosted Aug 23, 2012, 7:41 AM EDT
Sukesh MarlaRank #461 · 5.4K reputationPosted Aug 23, 2012, 8:54 AM EDT