try
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Title = "Open file as...";
dialog.Filter = "txt files (*.txt)|*.txt";
dialog.RestoreDirectory = true;
if (dialog.ShowDialog() == DialogResult.OK)
{
string csvFileName = dialog.FileName;
//get the user to specify the
TextReader reader = new StreamReader(csvFileName);
string a = reader.ReadToEnd();
char[] array = a.ToCharArray();
reader.Close();
MessageBox.Show("File Converted! Please save");
SaveFileDialog dialogSave = new SaveFileDialog();
dialogSave.Title = "Save file as...";
dialogSave.Filter = "CSV files (*.csv)|*.csv";
dialogSave.RestoreDirectory = true;
if (dialogSave.ShowDialog() == DialogResult.OK)
{
string saveFile = dialogSave.FileName;
//get the user to specify the
FileStream aFile = new FileStream(saveFile, FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(aFile);
for (int i = 0; i < array.Length; i++)
{
if (array[i] == '\n' && array[i] == '\r')
sw.WriteLine();
else
sw.Write(a[i] + ",");
}
sw.Close();
}
}
}
catch (Exception ex)
{
MessageBox.Show("There was an error creating the download report:" + ex.Message);
}
No comments:
Post a Comment