...

View Full Version : how do i read a config.ini file with asp



emehrkay
03-08-2006, 01:27 PM
and set some global variables.

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

how do i do this with asp?

thanks

degsy
03-08-2006, 02:05 PM
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


<%
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



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

objFile.Writeline Chr(37)&Chr(62)&vbCRLF

http://www.w3schools.com/asp/asp_ref_textstream.asp

emehrkay
03-08-2006, 02:11 PM
interesting. so i need to populate a form and submit it to get the values passed to asp?

degsy
03-08-2006, 03:23 PM
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.

emehrkay
03-08-2006, 03:28 PM
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.

glenngv
03-09-2006, 03:55 AM
There are many ASP INI components available on the net.

http://www.google.com/search?hl=en&q=ASP+INI+component

emehrkay
03-09-2006, 03:45 PM
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?



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

degsy
03-10-2006, 01:37 PM
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")



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum