Đọc file .txt được chọn từ FileUpload trong asp.net

Thảo luận trong 'Lập trình web Asp.net' bắt đầu bởi admin, 19/6/17.

  1. admin
    Tham gia ngày:
    22/5/13
    Bài viết:
    4,895
    Đã được thích:
    1,198
    Điểm thành tích:
    113
    Giới tính:
    Nam
    Các đọc toàn bộ dữ liệu trong file text (.txt) đã được chọn từ FileUpload trong lập trình web asp.net (C#) như sau:

    Trong file xxx.ASPX chèn code html sau:
    Mã:
    <asp:FileUpload ID="txtFile" runat="server" Style="width: 100%" />
    <asp:Button ID="btnRedFile" runat="server" Text="UpLoad" OnClick="btnRedFile_Click" />
    
    Trong code xxx.ASPX.CS chèn code sau:
    Mã:
    protected void btnRedFile_Click(object sender, EventArgs e) //upload
    {
        try
        {
            List<string> ListRecords = new List<string>();
    
            if (!txtFile.HasFile)
            {
                return;
            }
            using (StreamReader tempReader = new StreamReader(txtFile.FileContent))
            {
                string tempLine = string.Empty;
                while ((tempLine = tempReader.ReadLine()) != null)
                {
                    ListRecords.Add(tempLine);
                }
            }
        }
        catch (Exception ex)
        {
    
        }
    }
    
    • Tất cả dữ liệu đều được chuyển vào Mảng ListRecords bạn chỉ cần lấy ra sử dụng thôi.
     
    Cảm ơn đã xem bài:

    Đọc file .txt được chọn từ FileUpload trong asp.net

  2. học seo
    Tham gia ngày:
    30/6/17
    Bài viết:
    4
    Đã được thích:
    0
    Điểm thành tích:
    1
    Giới tính:
    Nữ
    cái what the heo????
     


Chủ để tương tự : Đọc file
Diễn đàn Tiêu đề Date
Lập trình web Asp.net Đọc ghi nối file text .txt trong c# như thế nào? 23/6/23
Lập trình web Asp.net Ignore SSL Certificate DownloadString WebClient read file .txt c# MVC 23/6/23
Lập trình web Asp.net Read text .txt file on other websites in c# MVC 23/6/23
Lập trình web Asp.net Download File cài đặt và Key Visual Studio 2019 Professional + Enterprise full bản quyền 10/10/21
Lập trình web Asp.net Lấy chiều cao và rộng của HttpPostedFileBase, get width Height HttpPostedFileBase 25/11/20