Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy ListBox items to a text file

Status
Not open for further replies.

hugh999

MIS
Nov 29, 2001
129
IE
Hi
I am new the world of C#(Sharp)and am having problems copying the items in a listbox to a text file.

So far in my code i can youse the browse dialog to add file locations and file names to the listbox. What i am trying to do is click on a command button and copy the list to a text file.

In VB6 this procedure was not a problem, but converting the vb6 code to c#, it is bit of a nightmare.

Any examples of code would be of great help.

Thanks
 
// ListBox m_lbxList;

StreamWriter sw= null;
try
{
sw = new StreamWriter("listBoxLines.txt",false);
foreach (object objItem in m_lbxList.Items)
{
sw.WriteLine(objItem.ToString());

}
}catch (Exception e)
{
string sErr = "... " + e.GetType() + e.Message();
MessageBox.Show(sErr);

}
finally
{
if (sw!=null)
sw.Close();
sw = null;
}

-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top