C#文件打开问题

求一个代码例子,按下按钮之后打开一个指定路径的文本文档。不胜感激!

string pathFile="你的文件路径";//
private string OpenFileTxt(string path)
{
    string txtContent="";
    using(FileStream fs  = new FileStream(path,FileMode.Open))
    {
        using(StreamReader sr = new StreamReader(fs,Encoding.UTF8))
        {
            while(sr.Peek()>0)//如果下一行还有数据
            {
                txtContent+=sr.ReadLine();
            }
        }
    }
    return txtContent;
}

温馨提示:答案为网友推荐,仅供参考
相似回答