Today I had a question that perked my inner geek. Turns out it was a terribly easy solution at least for now. I plan to extend this FAQ alot.
This FAQ guides you on how you can show your users the code behind the page that they are viewing. At the moment it displays a simple text version of the code. Sometime in the future(hopefully the near future I plan on extending this to display a nicely formatted page that is similiar to the VS.NET display.
If you happen to move your project off of a development machine please note that in order for this to work the code files must accompany the project. Your code file are the .aspx.vb files. They also must stay in the same directory as the .aspx file itself or you'll see some ugly error messages. I know I know! I should have coded in some error handling but remember this is just version 1. I whipped it up rather quickly so no complaining. Anyway for now simply paste the following code into your .vb file
[color green]
Public Function GrabCode(ByVal path As String) As String
Dim reader As New StreamReader(path)
Dim sb As New StringBuilder()
sb = Nothing
reader = Nothing
End Function
[/color]
Then in the event that you want the code to appear you want the code to appear (page_load, or a button click). Use this code.
[color green]
Dim myRow As TableRow
Dim myCell As TableCell
Make sure that you have declared tblTest somewhere on the designview. It's simply a server-side table object. Of course you can put the string that "GrabCode" returns into any text holding object and it'll work.
Yes and before I forget make sure to include these Imports at the top of your page.
[color green]
Imports System.Text
Imports System.IO
[/color]
Like I said give me a couple days or so and I should have this as a full fledged code viewer control.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.