Board index » Visual Studio » How do you execute VB code that resides in a Text File...

How do you execute VB code that resides in a Text File...

Visual Studio98
All,







I'm trying to figure out how I would execute code that would be shared over

a number of wwwroot folders.







Basically it would be the equivalent of an .inc file only instead of

residing below the wwwroot it would exist above (FYI - I want to do this so

when information changes on a page like my "Terms of Use" it will be

reflected throughout each site I maintain) as apposed to changing the file

for each domain.







I've tried using StreamReader but have run into a problem. the page loads

(with the .txt file Embedded in the page without any problem) but the VB

code in the file is not executed:







'This is the code that calls the appropriate file.







accountRoot = "\\server\root_Folder\"







Dim footer_file As New IO.FileStream(accountRoot & "_includes\file.txt",

IO.FileMode.Open, IO.FileAccess.Read)



Dim myReader As New IO.StreamReader(footer_file)



Dim footer_txt As String



footer_txt = myReader.ReadToEnd()







response.write(footer_txt) ' I've tried server.execute(footer_txt) but I'm

getting error messages even when the page is empty.







-XXXXXXXXXXXXXX-







'This is what is returned to the browser (note - That the <%

=DatePart("yyyy", Now) %>is returned but is invisible on the page.







.



<p class="footer_header">



Copyright <% =DatePart("yyyy", Now) %>- XYZ, Inc. - All rights reserved.



<br />



.







I've just switched from VBS to VB so I'm sure this is the wrong approach so

any advice or guidance would be appreciated.







CES


-
 

Re:How do you execute VB code that resides in a Text File...

Well, remember that ASP.NET pages are compiled pages and not scripts.



The best thing that I can think of you doing is to create a class with the

code that you want to share. Sign it with a strong name and place it into

the GAC. Any .NET assembly can access the code then.



"CES" <NONE@NOEMAIL.com>wrote in message

Quote
All,







I'm trying to figure out how I would execute code that would be shared

over

a number of wwwroot folders.







Basically it would be the equivalent of an .inc file only instead of

residing below the wwwroot it would exist above (FYI - I want to do this

so

when information changes on a page like my "Terms of Use" it will be

reflected throughout each site I maintain) as apposed to changing the file

for each domain.







I've tried using StreamReader but have run into a problem. the page loads

(with the .txt file Embedded in the page without any problem) but the VB

code in the file is not executed:







'This is the code that calls the appropriate file.







accountRoot = "\\server\root_Folder\"







Dim footer_file As New IO.FileStream(accountRoot & "_includes\file.txt",

IO.FileMode.Open, IO.FileAccess.Read)



Dim myReader As New IO.StreamReader(footer_file)



Dim footer_txt As String



footer_txt = myReader.ReadToEnd()







response.write(footer_txt) ' I've tried server.execute(footer_txt) but I'm

getting error messages even when the page is empty.







-XXXXXXXXXXXXXX-







'This is what is returned to the browser (note - That the <%

=DatePart("yyyy", Now) %>is returned but is invisible on the page.







.



<p class="footer_header">



Copyright <% =DatePart("yyyy", Now) %>- XYZ, Inc. - All rights

reserved.



<br />



.







I've just switched from VBS to VB so I'm sure this is the wrong approach

so

any advice or guidance would be appreciated.







CES









-

Re:How do you execute VB code that resides in a Text File...

What I'm really looking for is the vb.net equivalent to eval() that is in

VBScript... but alas it's not their.

CES



"CES" <NONE@NOEMAIL.com>wrote in message

Quote
All,







I'm trying to figure out how I would execute code that would be shared

over

a number of wwwroot folders.







Basically it would be the equivalent of an .inc file only instead of

residing below the wwwroot it would exist above (FYI - I want to do this

so

when information changes on a page like my "Terms of Use" it will be

reflected throughout each site I maintain) as apposed to changing the file

for each domain.







I've tried using StreamReader but have run into a problem. the page loads

(with the .txt file Embedded in the page without any problem) but the VB

code in the file is not executed:







'This is the code that calls the appropriate file.







accountRoot = "\\server\root_Folder\"







Dim footer_file As New IO.FileStream(accountRoot & "_includes\file.txt",

IO.FileMode.Open, IO.FileAccess.Read)



Dim myReader As New IO.StreamReader(footer_file)



Dim footer_txt As String



footer_txt = myReader.ReadToEnd()







response.write(footer_txt) ' I've tried server.execute(footer_txt) but I'm

getting error messages even when the page is empty.







-XXXXXXXXXXXXXX-







'This is what is returned to the browser (note - That the <%

=DatePart("yyyy", Now) %>is returned but is invisible on the page.







.



<p class="footer_header">



Copyright <% =DatePart("yyyy", Now) %>- XYZ, Inc. - All rights

reserved.



<br />



.







I've just switched from VBS to VB so I'm sure this is the wrong approach

so

any advice or guidance would be appreciated.







CES









-

Re:How do you execute VB code that resides in a Text File...

"CES" <NONE@NOEMAIL.com>scripsit:

Quote
What I'm really looking for is the vb.net equivalent to eval() that is in

VBScript... but alas it's not their.



<www.devx.com/codemag/Article/10352/0/page/1>">www.devx.com/codemag/Article/10352/0/page/1>



Samples:



<www.codeproject.com/useritems/evaluator.asp>">www.codeproject.com/useritems/evaluator.asp>

<www.codeproject.com/csharp/livecodedotnet.asp>">www.codeproject.com/csharp/livecodedotnet.asp>



All untested with ASP.NET projects.



--

Herfried K. Wagner

MVP · VB Classic, VB.NET

<www.mvps.org/dotnet>">www.mvps.org/dotnet>

-

Re:How do you execute VB code that resides in a Text File...

have a look at the system.process namespace

"CES" <NONE@NOEMAIL.com>wrote in message

Quote
What I'm really looking for is the vb.net equivalent to eval() that is in

VBScript... but alas it's not their.

CES



"CES" <NONE@NOEMAIL.com>wrote in message

news:%23d6kwjEiDHA.1272@TK2MSFTNGP09.phx.gbl...

>All,

>

>

>

>I'm trying to figure out how I would execute code that would be shared

over

>a number of wwwroot folders.

>

>

>

>Basically it would be the equivalent of an .inc file only instead of

>residing below the wwwroot it would exist above (FYI - I want to do this

so

>when information changes on a page like my "Terms of Use" it will be

>reflected throughout each site I maintain) as apposed to changing the

file

>for each domain.

>

>

>

>I've tried using StreamReader but have run into a problem. the page

loads

>(with the .txt file Embedded in the page without any problem) but the VB

>code in the file is not executed:

>

>

>

>'This is the code that calls the appropriate file.

>

>

>

>accountRoot = "\\server\root_Folder\"

>

>

>

>Dim footer_file As New IO.FileStream(accountRoot & "_includes\file.txt",

>IO.FileMode.Open, IO.FileAccess.Read)

>

>Dim myReader As New IO.StreamReader(footer_file)

>

>Dim footer_txt As String

>

>footer_txt = myReader.ReadToEnd()

>

>

>

>response.write(footer_txt) ' I've tried server.execute(footer_txt) but

I'm

>getting error messages even when the page is empty.

>

>

>

>-XXXXXXXXXXXXXX-

>

>

>

>'This is what is returned to the browser (note - That the <%

>=DatePart("yyyy", Now) %>is returned but is invisible on the page.

>

>

>

>.

>

><p class="footer_header">

>

>Copyright <% =DatePart("yyyy", Now) %>- XYZ, Inc. - All rights

reserved.

>

><br />

>

>.

>

>

>

>I've just switched from VBS to VB so I'm sure this is the wrong approach

so

>any advice or guidance would be appreciated.

>

>

>

>CES

>

>









-