Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

App.Config in non executable vb.net 2003 class

Status
Not open for further replies.

acarruth

Programmer
Sep 7, 2003
34
0
0
US
Hi there,

Seems like such a simple problem - just trying to get a dynamic value from app.config file or even a simple text file so client doesn't have to recompile.. but either need to be able to access app.config file, or somehow find out current working path so i can open a text file in the same folder. no executables are generated, its just a vb.net 2003 class.. so just a dll is created. anyone have ideas on how to do this? frustrated to the max! :)

Thanks,

Allan
 
hi,

its a runtime value in a file for later use.. the DLL is a custom function for crystal reports, and needs to locate some text files on the hard drive. the location of these files might change, so instead of having the client recompile if the location changes, i was hoping to store the value in a configuration file that is accessed at runtime. so, when compiling this class, there is no .exe created.. just a .dll.

thanks!
 
I use some code similar to this for setting and retreiving files inbetween runs. A module with the following code:

Code:
public function GetSetting(Key as string) as string
  dim ReturnVal as string = string.emptry
  dim dsSettings as new dataset
  if system.io.file.exists("Settings.ini") then _
    dsSettings.readxml("Settings.ini")

  dim dr() = dssettings.tables(0).select("Key = '" & key & "'")
  if dr.length = 1 then
    returnVal = dr(0)("Value")
  end if
end function

public sub SetSetting(Key as string, Value as string)
  dim dsSettigns as new dataset
  if system.io.file.exists("Settings.ini") then
    dsSettings.readxml("Settings.ini")
  else
    dssettings.tables.add("Settings")
    dssettings.tables(0).columns.add("Key",gettype(string))
    dssettings.tables(0).columns.add("Value",gettype(string))
  end if

  dim dr() = dssettings.tables(0).select("Key = '" & key & "'")
  if dr.length = 1 then
    dr(0)("Value") = value
  else
    dim drSetting as datarow = dssettings.table(0).newrow
    drSetting("Key") = key
    drSetting("Value") = value
    dsSetting.Table(0).rows.add(drsetting)
  end if
  dssetting.writeXML("Settings.ini")
end sub

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
hmm.. that looks promising :)

if you call system.io.file.exists, though, where does it start its search? does it start in the dll's current working folder first? wouldn't want to pick up the wrong config/ini file..

thanks for your help!
 
Yeah, that's why I said 'similar' ;)

You should probrably store the Settings.Ini file in the application data folder. I'm thinking it's environment.specialfolders.applicationdata or something like that.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top