0% found this document useful (0 votes)
86 views2 pages

CSV Export and File Copy Guide

The document contains code for exporting the contents of a DataGridView control to a CSV file. It includes a method that loops through the columns and rows, concatenates the cell values with tabs, and writes the output to a file stream. There is also code to open a SaveFileDialog for the user to select the export file name and location. A recursive Copy method is defined to duplicate the contents of a source folder to a target folder.

Uploaded by

Evan Abie Eza
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views2 pages

CSV Export and File Copy Guide

The document contains code for exporting the contents of a DataGridView control to a CSV file. It includes a method that loops through the columns and rows, concatenates the cell values with tabs, and writes the output to a file stream. There is also code to open a SaveFileDialog for the user to select the export file name and location. A recursive Copy method is defined to duplicate the contents of a source folder to a target folder.

Uploaded by

Evan Abie Eza
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

using using using using using using using using using using using

System; [Link]; [Link]; [Link]; [Link]; [Link]; [Link]; [Link]; [Link]; [Link]; [Link];

private void ToCsV(DataGridView dGV, string filename) { string stOutput = ""; // Export titles: string sHeaders = ""; for (int j = 0; j < [Link]; j++) sHeaders = [Link]() + [Link]([Link][j] .HeaderText) + "\t"; stOutput += sHeaders + "\r\n"; // Export data. for (int i = 0; i < [Link] - 1; i++) { string stLine = ""; for (int j = 0; j < [Link][i].[Link]; j++) stLine = [Link]() + [Link]([Link][i].Ce lls[j].Value) + "\t"; stOutput += stLine + "\r\n"; } Encoding utf16 = [Link](1254); byte[] output = [Link](stOutput); FileStream fs = new FileStream(filename, [Link]); BinaryWriter bw = new BinaryWriter(fs); [Link](output, 0, [Link]); //write the encoded file [Link](); [Link](); [Link](); } //button SaveFileDialog sfd = new SaveFileDialog(); [Link] = "Excel Documents (*.xls)|*.xls"; [Link] = "[Link]"; if ([Link]() == [Link]) { //ToCsV(dataGridView1, @"c:\[Link]"); ToCsV(dataGridView1, [Link]); // Here dataGridview1 is you r grid view name } //upload // Recursive function to copy a folder's content into another folder void Copy(string sourceDir, string targetDir) { [Link](targetDir); foreach(var file in [Link](sourceDir)) [Link](file, [Link](targetDir, [Link](file)));

foreach(var directory in [Link](sourceDir)) Copy(directory, [Link](targetDir, [Link](directory))); }

You might also like