Greetings all,
I have this code which works this way:
When user click EXPORT, csv file is created at the Root Folder.
However I want to be able to have the SaveDialog box pop-up, that allows user to enter a name for the file and save to wherever they want in computer.
How can I modify the code to do so?
Code:Private Sub export_btn_Click(sender As Object, e As EventArgs) Handles export_btn.Click Dim exportFileName As String = "EVC_kiosk_DB_" & Date.Now.ToString("dd-MMM-yyyy") & ".csv" Try Dim fs As New IO.StreamWriter(".\" & exportFileName, False) fs.WriteLine("<?xml version=""1.0""?>") fs.WriteLine("<?mso-application progid=""Excel.Sheet""?>") fs.WriteLine("<ss:Workbook xmlns:ss=""urn:schemas-microsoft-com:office:spreadsheet"">") fs.WriteLine(" <ss:Styles>") fs.WriteLine(" <ss:Style ss:ID=""1"">") fs.WriteLine(" <ss:Font ss:Bold=""1""/>") fs.WriteLine(" </ss:Style>") fs.WriteLine(" </ss:Styles>") fs.WriteLine(" <ss:Worksheet ss:Name=""Sheet1"">") fs.WriteLine(" <ss:Table>") For x As Integer = 0 To ProjectsDataGridView.Columns.Count - 1 fs.WriteLine("<ss:Column ss:Width=""{0}""/>", ProjectsDataGridView.Columns.Item(x).Width) Next fs.WriteLine(" <ss:Row ss:StyleID=""1"">") For i As Integer = 0 To ProjectsDataGridView.Columns.Count - 1 fs.WriteLine(" <ss:Cell>") fs.WriteLine(String.Format( " <ss:Data ss:Type=""String"">{0}</ss:Data>", ProjectsDataGridView.Columns.Item(i).HeaderText)) fs.WriteLine(" </ss:Cell>") Next fs.WriteLine(" </ss:Row>") For intRow As Integer = 0 To ProjectsDataGridView.RowCount - 1 fs.WriteLine(String.Format("<ss:Row ss:Height =""{0}"">", ProjectsDataGridView.Rows(intRow).Height)) For intCol As Integer = 0 To ProjectsDataGridView.Columns.Count - 1 fs.WriteLine(" <ss:Cell>") fs.WriteLine(String.Format( " <ss:Data ss:Type=""String"">{0}</ss:Data>", ProjectsDataGridView.Item(intCol, intRow).Value.ToString)) fs.WriteLine(" </ss:Cell>") Next fs.WriteLine(" </ss:Row>") Next fs.WriteLine(" </ss:Table>") fs.WriteLine(" </ss:Worksheet>") fs.WriteLine("</ss:Workbook>") fs.Close() MessageBox.Show(exportFileName & " has been exported to your root folder.") Catch ex As Exception MessageBox.Show("Error exporting data! Please ensure that the excel file is not opened.") End Try End Sub




Reply With Quote
