ASP.NET Web Pages – 文件[伺服器檔案存取(讀取)]
ASP.NET Web Pages – 文件[伺服器檔案(server file)存取(讀取)]
資料來源: https://www.runoob.com/aspnet/webpages-files.html
TEXT(Persons.txt)
George,Lucas Steven,Spielberg Alfred,Hitchcock
Code
@{ var dataFile = Server.MapPath("~/App_Data/Persons.txt"); Array userData = File.ReadAllLines(dataFile); } <!DOCTYPE html> <html> <body> <h1>Reading Data from a File</h1> @foreach (string dataLine in userData) { foreach (string dataItem in dataLine.Split(',')) { @dataItem <text> </text> } <br /> } </body> </html>