StreamWriter LWriter = File.CreateText(@"w:\source\voproci\bin\data.dat");
try
{
foreach (string LItem in lboxData.Items)
{
LWriter.WriteLine(LItem);
}
}
finally
{
LWriter.Close();
LWriter = null;
}
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
Posted by ELKNews 1.0.4-B
Empower your News Reader! http://www.atozedsoftware.com
I would create an array of strings that is the same length as the number
of items in the textbox. Then, iterate through each item in the listbox and
copy the string to the string array. Once that was done, I would use the
BinaryFormatter class to serialize the string array to a file, something
like this:
// mobjListBox is the listbox.
// Create the array.
string[] pstrStrings = new string[mobjListBox.Items.Count];
// Get the text for each item.
for(int pintIndex = 0; pintIndex < pstrStrings.Length; ++pintIndex)
// Copy the string representation to the listbox.
pstrStrings[pintIndex] =
mobjListBox.GetItemText(mobjListBox[pintIndex]);
// Create the binary formatter
BinaryFormatter pobjFormatter = new BinaryFormatter();
// Create the file stream.
FileStream pobjFileStream = new FileStream(@"c:\temp\contents.lbx");
// Serialize the data.
pobjFormatter.Serialize(pstrStrings, pobjFileStream);
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- casp...@caspershouse.com
"Kudzu" <cp...@hower.org> wrote in message
news:Xns9226A69...@127.0.0.1...
Wow. Thats a lot of work just to save items to a text file. :)
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
IntraWeb & FinalBuilder - http://www.AToZedSoftware.com