properties file

  • Thread starter Thread starter rjl444
  • Start date Start date
R

rjl444

My app has a lot of properties, instead of placing the values in
webconfig file (because I have tons), I would like to place these in
it's own file. What is the best way of using an independant file?
Should I consider resource file?
thanks.
 
you can use a Class called website for example and in anypart of your
website you call a property like

dim intTotalLines as Integer = website.numberOfLinesInAGrid
 
Here is how we to this.

I have an XML file:
<settings>
<setting text="Account.RequireValidation" value"false">
<setting text="Account.DefaultRole" value"28">
</settings>

I have a settings DLL that:
1. As function that reads the XML document and caches it with a file
dependency to the XML. Prevent IO overhead.
2. A generic find function that will find by text and return the value.
3. Readonly Properties for easy access and clarity for each setting. The
property uses a find function for less repeat code.

I don't have a function that writes the XML because it is a setup file and
rarely if ever changes after deployment.

That's how I do it, it's flexible with minimal code and easily updated or
added to.

Hope that helps.

-Wayne
 
Wayne,
Exactly what I am looking for, I did not know if asp.net had helpers
for reading alternative config files. I am not quite sure what you mean
by "... caches it with a file
dependency to the XML."
I understand you don't want to phyusically read the file, but are you
saying you store the file in cache? and parse it from their when you
need? instead of the physical file? If I did something like this I
would store it in application setting, this data would not change per
user, but by website.
thanks for helping.
 
Sorry for the delay, busy, busy, busy.

What a cache dependancy is... you can store objects using into cache and can set it to a dependency to for expiration. That dependency can be time, a file, or other things, I use time and files mostly.

The cache store the object, not just the path. You can store the path to the file in the application setting but not the object.

Here is example of how to use it. With a file dependance, if the file gets changed the cache (stored in memory) will expire itself and (using the example below) force a new read of the file.

If HttpContext.Current.Cache("FeaturedPropertyXMLItems") Is Nothing Then

Dim dst As New DataSet
dst.ReadXmlSchema(HttpContext.Current.Server.MapPath("~/resources/featuredproperties/listings.xsd"))
dst.ReadXml(HttpContext.Current.Server.MapPath("~/resources/featuredproperties/listings.xml"))

HttpContext.Current.Cache.Insert("FeaturedPropertyXMLItems", dst, New CacheDependency(HttpContext.Current.Server.MapPath("~/resources/featuredproperties/listings.xml")))

dst = Nothing

Else

Dim dst As DataSet = CType(HttpContext.Current.Cache("FeaturedPropertyXMLItems"), DataSet))

End If



I hope this helps.

-Wayne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top