Tuesday, April 5, 2011

C#/asp.net; open a file write contents to a div, span, label, some kind of container.

I’d like to be able to open a text/html file and write its contents to a container, either an HTML div or an asp label would be fine. How do I go about doing this in the C# codefile for the page in question?

From stackoverflow
  • You just want to stream in the file and place the text into the Label.text field:

    lable1.text= System.IO.File.ReadAllText( path );
    
    IainMH : Great answer +1, but with a label, it's InnerText or InnerHtml.
    Joel Coehoorn : Yes: the .Text property will escape things like < for you. You could also use a literal control- that may be more what you really want.

0 comments:

Post a Comment