Answers for "c# save and load listbox to file"

C#
0

c# save and load listbox to file

string temp = AppDomain.CurrentDomain.BaseDirectory;
string sPath = Path.Combine(temp, "test.txt"); 
System.IO.StreamWriter SaveFile = new System.IO.StreamWriter(sPath);
foreach(var item in listBox1.Items)
{
    SaveFile.WriteLine(item.ToString());
}


string line;
var file = new System.IO.StreamReader(sPath);
while ((line = file.ReadLine()) != null)
{
    listBox1.Items.Add(line);
}
Posted by: Guest on September-18-2021

C# Answers by Framework

Browse Popular Code Answers by Language