Looping through lines of txt file uploaded via FileUpload control

前端 未结 1 1210
忘了有多久
忘了有多久 2021-02-14 18:41

I want to select a simple .txt file that contains lines of strings using a FileUpload control. But instead of actually saving the file I want to loop through each line of text a

1条回答
  •  遥遥无期
    2021-02-14 19:26

    private void populateListBox() 
    {
        FileUpload fu = FileUpload1; 
        if (fu.HasFile)  
        {
            StreamReader reader = new StreamReader(fu.FileContent);
            do
            {
                string textLine = reader.ReadLine();
    
                // do your coding 
                //Loop trough txt file and add lines to ListBox1  
    
            } while (reader.Peek() != -1);
            reader.Close();
        }
    }
    

    0 讨论(0)
提交回复
热议问题