Asp.net implements the method of reading data from a Txt file to a data view,

Source: Internet
Author: User

Asp.net implements the method of reading data from a Txt file to a data view,

This document describes how to use asp.net to read data from a Txt file to a data view. We will share this with you for your reference. The details are as follows:

# Region reads data from the Txt file to the data view // read data from the Txt file to the data view /// </summary> /// <param name = "strExcelPath"> File path </param> /// <returns> returns a data view </returns> public static DataView GetDataFromTxt (string strTxtPath) {string strLine = ""; DataRow row; try {DataTable tbl = new DataTable (); StreamReader sr = new StreamReader (strTxtPath, Encoding. getEncoding ("GB2312"); strLine = sr. readLine (); // read the first row attribute string [] Fields = strLin E. split (new char [] {'/t'}); // read each field (separated by TAB) for (int k = 0; k <Fields. length; k ++) // Add the column attribute {tbl to the table. 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 (separated by TAB) 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 design your asp.net program.

Articles you may be interested in:
  • In ASP. NET, MVC transmits data from the background controller to the foreground view.
  • ASP. NET operations on txt files (read, write, and save)
  • Preview ASP. NET files in Word, Excel, and TXT files online
  • Simple implementation code for recording visitor page access IP addresses (asp.net + txt)
  • Asp.net: How to import data from a able to an Excel file and create a table
  • In asp.net, use the Repeater control to drag and drop to sort and synchronize the sort of database fields
  • Asp.net implements Gradview binding database data and exporting Excel
  • Summary of ASP. NET database connection and data retrieval methods
  • Summary of several forms of MVC data transmission in ASP. NET

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.