This article describes the ASP.net implementation of the method of reading data from TXT file to Data view. Share to everyone for your reference, specific as follows:
#region reading data from TXT file to Data View///reading data from TXT file to Data View///</summary>///<param name= "Strexcelpath" > File path </param >///<returns> Returns a data View </returns> public static DataView Getdatafromtxt (String strtxtpath) {string Strli
NE = "";
DataRow Row;
try {datatable tbl = new DataTable ();
StreamReader sr = new StreamReader (Strtxtpath, encoding.getencoding ("GB2312")); StrLine = Sr. ReadLine (); Read first row and column properties string[] Fields = Strline.split (new char[] {'/t '})//Read each field (Tab separated) for (int k = 0; K < Fields.leng Th k++)//Add column properties to table {tbl.
Columns.Add (Fields[k], typeof (String)); } while (StrLine = Sr. ReadLine ())!= null) {row = tbl.
NewRow (); string[] Words = strline.split (new char[] {'/t '});//Read each field value (tab-separated) for (int j = 0; J < words. Length;
J + +) {Row[j] = words[j]; } tbl.
Rows.Add (row); } Sr.
Dispose (); Sr.
Close ();
DataView dv = new DataView (TBL);
return DV;
catch {return null; }} #eNdregion
I hope this article will help you with ASP.net programming.