public void ExportData(string budgetType, bool isValidationGrid) { try { switch (budgetType) { case ApplicationConstants.BUDGET_TYPE_REVISED: FillExportDataTableRevised(isValidationGrid); break; case ApplicationConstants.BUDGET_TYPE_TOCOMPLETION: FillExportDataTableReforecast(); break; } //StringBuilder that will hold the contents of the csv file to be exported StringBuilder fileContent = new StringBuilder(); //List holding column names List <string> columnNames = new List <string>(); foreach (DataColumn column in exportDataTable.Columns) { columnNames.Add(column.ColumnName); //Add the header text to the StringBuilder object that holds the contents of the csv file fileContent.Append("\"" + column.ColumnName + "\";"); } //Remove the last semicolon in the header fileContent.Remove(fileContent.Length - 1, 1); //Get the datarows from the grid which obey the filter condition DataRow[] rows = exportDataTable.Select(); if (rows.Length > 0) { //Append the actual grid contents to the StringBuilder fileContent.Append(DSUtils.BuildCSVExport(rows, columnNames, true)); } //Download the file DownloadUtils.DownloadFile(ApplicationConstants.DEFAULT_BUDGET_EXPORT_FILE_NAME, fileContent.ToString()); } catch (IndException ex) { ControlHierarchyManager.ReportError(ex); return; } catch (Exception ex) { ControlHierarchyManager.ReportError(new IndException(ex)); return; } }
public void ExportData() { try { //StringBuilder that will hold the contents of the csv file to be exported StringBuilder fileContent = new StringBuilder(); //List holding visible column names List <string> visibleColumnNames = new List <string>(); //Populate visibleColumnNames with the visible columns in the grid (exclude the ones that are hidden) foreach (GridColumn column in grdExchangeRates.MasterTableView.Columns) { if (column is GridBoundColumn && column.Display) { visibleColumnNames.Add(column.UniqueName); //Add the header text to the StringBuilder object that holds the contents of the csv file fileContent.Append("\"" + column.UniqueName + "\";"); } } //Remove the last semicolon in the header fileContent.Remove(fileContent.Length - 1, 1); //Get the datarows from the grid which obey the filter condition DataRow[] rows = (((DataSet)grdExchangeRates.DataSource).Tables[0]).Select(); if (rows.Length > 0) { //Append the actual grid contents to the StringBuilder fileContent.Append(DSUtils.BuildCSVExport(rows, visibleColumnNames, true)); } //Download the file DownloadUtils.DownloadFile(ApplicationConstants.DEFAULT_FILE_NAME, fileContent.ToString()); } catch (IndException ex) { ShowError(ex); return; } catch (Exception ex) { ShowError(new IndException(ex)); return; } }
private String ExtractMethod(DataSet ds) { //StringBuilder that will hold the contents of the csv file to be exported StringBuilder fileContent = new StringBuilder(); //List holding visible column names List <string> visibleColumnNames = new List <string>(); foreach (DataColumn col in ds.Tables[0].Columns) { visibleColumnNames.Add(col.ColumnName); fileContent.Append("\"" + col.ColumnName + "\";"); } if (fileContent.ToString().EndsWith(";")) { fileContent.Remove(fileContent.Length - 1, 1); } DataRow[] rows = ds.Tables[0].Select(); fileContent.Append(DSUtils.BuildCSVExport(rows, visibleColumnNames, true)); return(fileContent.ToString()); }