Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-08-2006, 01:27 PM   PM User | #1
emehrkay
Regular Coder

 
Join Date: May 2005
Posts: 190
Thanks: 1
Thanked 2 Times in 2 Posts
emehrkay is an unknown quantity at this point
how do i read a config.ini file with asp

and set some global variables.

in php its a simple parse_ini_file() function then @define.

how do i do this with asp?

thanks
emehrkay is offline   Reply With Quote
Old 03-08-2006, 02:05 PM   PM User | #2
degsy
Senior Coder

 
Join Date: Nov 2002
Location: North-East, UK
Posts: 1,265
Thanks: 0
Thanked 0 Times in 0 Posts
degsy is on a distinguished road
The way i've worked with constant/config is to read the variables into a form. make the changes you want and then submit the form back to the .asp file (use .asp for security instead of .ini or .inc etc)

e.g. The resulting config.asp file would be
Code:
<%
company_name = "mycompany"
company_domain = "mycomany.com"
company_email = "admin@mycompany.com
%>
When this file in included then all those variables are available.

Also remember to write the <% and %> for the ASP file

Code:
objFile.Writeline vbCRLF&Chr(60)&Chr(37)&vbCRLF

objFile.Writeline Chr(37)&Chr(62)&vbCRLF
http://www.w3schools.com/asp/asp_ref_textstream.asp
degsy is offline   Reply With Quote
Old 03-08-2006, 02:11 PM   PM User | #3
emehrkay
Regular Coder

 
Join Date: May 2005
Posts: 190
Thanks: 1
Thanked 2 Times in 2 Posts
emehrkay is an unknown quantity at this point
interesting. so i need to populate a form and submit it to get the values passed to asp?
emehrkay is offline   Reply With Quote
Old 03-08-2006, 03:23 PM   PM User | #4
degsy
Senior Coder

 
Join Date: Nov 2002
Location: North-East, UK
Posts: 1,265
Thanks: 0
Thanked 0 Times in 0 Posts
degsy is on a distinguished road
The form part is just if you wanted to change the variables from a webpage.

You would read in the variables to the page and into a form. When you submit the form it will write them back to the ASP file.

You could manually edit the file if you wished.

You then just need to include that ASP file in your other files to use the variables.
degsy is offline   Reply With Quote
Old 03-08-2006, 03:28 PM   PM User | #5
emehrkay
Regular Coder

 
Join Date: May 2005
Posts: 190
Thanks: 1
Thanked 2 Times in 2 Posts
emehrkay is an unknown quantity at this point
i have a config.ini file with the basic config stuff being read through php. now i need to add a few asp pages and i want to define some varialbes in the config file and just read them into the asp pages.

maybe i can try a different approach - is there anyway for me to echo the web address that the file is being used on? like if i drop the file on a different server it will tell me the web address, not the path to the file, just the address.
emehrkay is offline   Reply With Quote
Old 03-09-2006, 03:55 AM   PM User | #6
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
There are many ASP INI components available on the net.

http://www.google.com/search?hl=en&q=ASP+INI+component
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 03-09-2006, 03:45 PM   PM User | #7
emehrkay
Regular Coder

 
Join Date: May 2005
Posts: 190
Thanks: 1
Thanked 2 Times in 2 Posts
emehrkay is an unknown quantity at this point
thanks guys i found the answer, someone wrote a function that takes care of it


i have a question about that function though. i need to pass the path to the ini file into the function, it has to be a virtual path because it uses the Server.MapPath() call. my probelm is that the ini exists outside of the website, how do i write the path to the file to satsify the function?

Code:
Function GetINIStringVirtual(Section, KeyName, Default, FileName)
  GetINIStringVirtual = GetINIString(Section, KeyName, Default, _
    Server.MapPath(FileName))
End Function 

siteUrl =  GetINIStringVirtual("paths", "app_url", "-", "c:/Inetpub/config/lms.ini")
i tried taking out the Server.MapPath because, from what i understand, all it does is convert the virtual path the the one that im passing, but it doesnt work. what am in overlooking?

thanks
emehrkay is offline   Reply With Quote
Old 03-10-2006, 01:37 PM   PM User | #8
degsy
Senior Coder

 
Join Date: Nov 2002
Location: North-East, UK
Posts: 1,265
Thanks: 0
Thanked 0 Times in 0 Posts
degsy is on a distinguished road
Server.MapPath will reference from the web root.

Why not just remove the Server.MapPath function and just use the filename?

Another option would be to go up a level
siteUrl = GetINIStringVirtual("paths", "app_url", "-", "../config/lms.ini")
degsy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:52 PM.


Advertisement
Log in to turn off these ads.