reading text file lines into asp.net contentplaceholder
I am new to ASP.Net and am trying to set up some content pages to work with my master page. I currently have the following text hardcoded into an asp:contentplaceholder and it works just fine. I want to read lines in from a text file to produce those headlines and retain the current formatting. I tried using the tag i need each line as a separate
tag. Below is the code in the content place holder. Id like to have this done in the Page_Load or the pre Init.
<p class="text1">--- We recently completed an evaluatio开发者_开发百科n for a large Ocean Tug fleet showing 70% particulate reduction, 11% NOx reduction and an 8% fuel economy improvement.</p>
<p class="text1">--- Our Product was added to the Grainger catalog as its primary emissions and fuel efficiency Catalyst.</p>
<p class="text1">--- Our Product is recommended by Mann-Hummel to promote better performance in Diesel Particulate Filters.</p>
The
IO.File.ReadAllLines()
method will read a text file and return to you an array of strings; one for each line of text.
You can then loop through that, building up the HTML string to place into the ContentPlaceHolder
Try the following:
Dim Lines() As String = IO.File.ReadAllLines(Path)
For Each f As String In Lines
Response.Write("<p class='text1'>" & f & "</p>")
Next
Edit: I noticed you want it inside a ContentPlaceHolder, therefore can't use Response.Write
. If that's the case you can try using a Literal
control and then append the previous code using LiteralName.Text &= f
Hopefully it helps!
Edit: Adding more code, supporting what @Brian M. has said:
Dim Content As String = String.Empty
Dim Lines() As String = IO.File.ReadAllLines(Path)
For Each TxtFromFile As String In Lines
Content &= "<p class='text1'>" & TxtFromFile & "<p>"
Next
Me.ContentPlaceHolder1.Controls.Add(New LiteralControl(Content))
I hope it helps.
精彩评论