Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    190
    Thanks
    1
    Thanked 2 Times in 2 Posts

    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

  • #2
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    190
    Thanks
    1
    Thanked 2 Times in 2 Posts
    interesting. so i need to populate a form and submit it to get the values passed to asp?

  • #4
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Regular Coder
    Join Date
    May 2005
    Posts
    190
    Thanks
    1
    Thanked 2 Times in 2 Posts
    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.

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    There are many ASP INI components available on the net.

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

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #7
    Regular Coder
    Join Date
    May 2005
    Posts
    190
    Thanks
    1
    Thanked 2 Times in 2 Posts
    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

  • #8
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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")


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •