INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS
Come Join Us!
Are you a
Computer / IT professional?
Join Tek-Tips now!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts
- Keyword Search
- One-Click Access To Your
- Automated Signatures
On Your Posts
- Best Of All, It's Free!
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.
Partner With Us!
"Best Of Breed" Forums Add Stickiness To Your Site
(Download This Button Today!)
"...I have tons of books, have book marked tons of tutorials, which have helped, but this forum has answered those "impossible to find" solutions. I am thrilled with this site..."
Where in the world do Tek-Tips members come from?
Showing Code to Users
Posted: 10 Apr 03
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
Public Function GrabCode(ByVal path As String) As String
Dim reader As New StreamReader(path)
Dim sb As New StringBuilder()
GrabCode = sb.ToString
sb = Nothing
reader = Nothing
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.
Dim myRow As TableRow
Dim myCell As TableCell
myRow = New TableRow()
myCell = New TableCell()
myCell.Text = GrabCode(Request.PhysicalPath & ".vb")
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.
Like I said give me a couple days or so and I should have this as a full fledged code viewer control.
Back to Microsoft: ASP.NET FAQ Index
Back to Microsoft: ASP.NET Forum
Join Tek-Tips® Today!
Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.
Here's Why Members Love Tek-Tips Forums:
- Talk To Other Members
- Notification Of Responses To Questions
- Favorite Forums One Click Access
- Keyword Search Of All Posts, And More...
Register now while it's still free!
Already a member? Close this window and log in.
Join Us Close