ASP.NET Write out contents of HTML file?

流过昼夜 提交于 2019-12-25 16:56:59

问题


I don't know if this is a stupid question but..

Is it possible in either ASP.NET (either C# or VB#) to Response.Write() the contents of another HTML file? If so, how?


回答1:


Read the HTML file line by line and write it using Response.Write()

 StreamReader sr = new StreamReader(@"C:\abc.html");
        while(sr.Peek() >= 0)
        {
           line=sr.ReadLine();
           Response.Write(line);

        }



回答2:


You can get all the lines into a string array and send them out directly.

string[] lines = File.ReadAllLines("path/to/my/file.html");
foreach(string line in lines)
{
    Response.Write(line);
}

Just don't forget to set your headers up correctly because this will just inject HTML. It won't set up any special headers that might be expected (if any).




回答3:


I know this is an old question, but I have another solution for future researching. How about just use TrasmitFile? i.e.:

Response.WriteFile(@"folder/filename.html");


来源:https://stackoverflow.com/questions/4509417/asp-net-write-out-contents-of-html-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!