C#讀取檔案成一個string字串

  • 815
  • 0
  • C#
  • 2020-12-23

C# 讀取檔案 cshtml txt html string字串

 

using System.Text;
using System.IO;

//設定檔案路徑
string path = System.AppDomain.CurrentDomain.BaseDirectory + @"XXX\OOO\Index.cshtml";
try
{
  //有資料
  if (File.Exists(path))
  {
    //讀取檔案
    StreamReader streamReader = new StreamReader(path, Encoding.GetEncoding("Big5"));
    //轉字給參數
    string returnData = streamReader.ReadToEnd();
  }
}
catch
{
}

 

我只是一棵樹