Beispiel #1
0
        private void MenuFile_SaveLog_Click(object sender, EventArgs e)
        {
            saveFileDialog.FileName = "DinoDoc Import " + String.Format("{0:MM-dd-yyyy}", System.DateTime.Now);

            if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                LogStatus.SaveFile(saveFileDialog.FileName);

                StringBuilder sbItems = new StringBuilder();

                foreach (ColumnHeader lvColumns in lvStatus.Columns)
                {
                    sbItems.Append(lvColumns.Text + ",");
                }

                sbItems.AppendLine();

                foreach (ListViewItem lvItems in lvStatus.Items)
                {
                    foreach (ListViewItem.ListViewSubItem lvStrings in lvItems.SubItems)
                    {
                        if (lvStrings.Text.Trim() == string.Empty)
                        {
                            sbItems.Append(" ,");
                        }
                        else
                        {
                            sbItems.Append(lvStrings.Text + ",");
                        }
                    }
                    sbItems.AppendLine();
                }

                StreamWriter sw = new StreamWriter(System.IO.Path.GetDirectoryName(saveFileDialog.FileName) + "\\" + System.IO.Path.GetFileNameWithoutExtension(saveFileDialog.FileName) + ".csv");
                sw.Write(sbItems.ToString());
                sw.Close();
            }
        }