如何通过htmlinputfile控件将文本文件内容读取到Textbox控件里?

解决方案 »

  1.   

    testbox1.Text = htmlinputfile1.PostedFile.FileName;
      

  2.   

    如何通过htmlinputfile控件将文本文件内容读取到Textbox控件里?
      

  3.   

    htmlinputfile不能完成你所说的任务,可以通过该控件得到文件的路径等属性,以下代码摘自msdn,具体可以参看streamreader
    using System;
    using System.IO;class Test 
    {
        public static void Main() 
        {
            try 
            {
                // Create an instance of StreamReader to read from a file.
                // The using statement also closes the StreamReader.
                using (StreamReader sr = new StreamReader("TestFile.txt")) 
                {
                    String line;
                    // Read and display lines from the file until the end of 
                    // the file is reached.
                    while ((line = sr.ReadLine()) != null) 
                    {
                        Console.WriteLine(line);
                    }
                }
            }
            catch (Exception e) 
            {
                // Let the user know what went wrong.
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
        }
    }