This Code(for winform) allow you to create a new .csv or .txt file and save it in any location you want in you Computer. you can change the Filter to add .xls or any other type.
try
{
SaveFileDialog saveDiag = new SaveFileDialog();
saveDiag.Filter = " Excel (*.csv) | *.CSV | Fichier Text (*.txt)| *.txt";
saveDiag.DefaultExt = "*.CSV";
if (saveDiag.ShowDialog() == DialogResult.OK)
{
using (Stream stream = File.Open(saveDiag.FileName, FileMode.Create,
FileAccess.ReadWrite))
{
using (StreamWriter sWriter = new StreamWriter(stream,
Encoding.UTF8))
{
sWriter.WriteLine("Name ; Last Name ; Login; Password ");
foreach(User user in ListUsers)
{
sWriter.WriteLine(user.Name + ";" + user.LastName + ";" +
user.Password);
}
}
}
MessageBox.Show("operation Completed");
}
}
catch (Exception exception)
{
MessageBox.Show(exception.InnerException.ToString());
}
this will generate a organized table in excel. the ";" is the Column separator.
Hope it helps.