Tuesday, April 23, 2013

Read text file from file system.



public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string sourcePath = @"E:\Users\Public\TestFolder\";
            if (System.IO.Directory.Exists(sourcePath))
            {
                string[] files = System.IO.Directory.GetFiles(sourcePath);

                // Copy the files and overwrite destination files if they already exist. 
                foreach (string s in files)
                {
                    using (StreamReader sr = new StreamReader(s))
                    {
                        String line = sr.ReadToEnd();
                        Response.Write(line);
                    }
                }
            }
        }
    }
}

No comments:

Post a Comment