473,324 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Using an xml file in place of a .ini

In the tool I used to use I would write certain things to a .ini file in a
users private directory from time to time. For example, when the
application was started, a certain section of that .ini file is checked so
that the application will start in a way that is unique to the users
machine. This is a non windows app.

I see that it is not convenient to do the same in VB.net. Tools for writing
and reading from a .ini file are not good. It has occurred to me, however,
that I might just as easily make use of writing that data to an xml file and
get the same result.

Is anyone else doing it this way?

Nov 20 '05 #1
6 1124
From what I've read, the registry is still your best option (though not the
..NET way).

check out this month MSDN magazine's "User Preferences" for some other
ideas:
http://msdn.microsoft.com/msdnmag/is...7/default.aspx

A quick and dirty way is to create a simple class with your user's settings
and serialize it to their profile folder on disk. Here is the code I having
been toying around with:

<Serializable()> _
Public Class UserSettings
Private _username As String

Public Property UserName() As String
Get
If _username = Nothing Then
Return CurrentUser()
Else
Return _username.ToLower
End If
End Get
Set(ByVal Value As String)
_username = Value.ToLower
End Set
End Property
End Class

Imports System.Runtime.Serialization.Formatters.Binary

Public Class UserSettingsDB
Private Sub New()
End Sub

Public Shared Function LoadSettings() As UserSettings

Dim mySettings As New UserSettings

Dim s As String =
Environment.GetFolderPath(System.Environment.Speci alFolder.ApplicationData)

s &= "\myappname\myappname.bin"

If File.Exists(s) Then

Dim streamOut As FileStream
Try
Dim formatter As New BinaryFormatter

streamOut = New FileStream(s, FileMode.Open,
FileAccess.Read)

mySettings = CType(formatter.Deserialize(streamOut),
UserSettings)

Catch

Finally
streamOut.Close()
End Try
End If

Return mySettings

End Function

Public Shared Sub SaveSettings(ByVal mySettings As UserSettings)
Dim s As String =
Environment.GetFolderPath(System.Environment.Speci alFolder.ApplicationData)

s &= "\myappname"

If Not Directory.Exists(s) Then

Directory.CreateDirectory(s)

End If

s &= "\myappname.bin"

Dim formatter As New BinaryFormatter

Dim streamIn As New FileStream(s, FileMode.Create,
FileAccess.Write)

formatter.Serialize(streamIn, mySettings)

streamIn.Close()

End Sub
End Class

HTH,
Greg

"Woody Splawn" <no****@splawns.com> wrote in message
news:ev**************@TK2MSFTNGP12.phx.gbl...
In the tool I used to use I would write certain things to a .ini file in a
users private directory from time to time. For example, when the
application was started, a certain section of that .ini file is checked so
that the application will start in a way that is unique to the users
machine. This is a non windows app.

I see that it is not convenient to do the same in VB.net. Tools for writing and reading from a .ini file are not good. It has occurred to me, however, that I might just as easily make use of writing that data to an xml file and get the same result.

Is anyone else doing it this way?

Nov 20 '05 #2
* "Woody Splawn" <no****@splawns.com> scripsit:
In the tool I used to use I would write certain things to a .ini file in a
users private directory from time to time. For example, when the
application was started, a certain section of that .ini file is checked so
that the application will start in a way that is unique to the users
machine. This is a non windows app.


Configuration Management Application Block
<URL:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/cmab.asp>

<URL:http://www.palmbytes.de/content/dotnet/optionslib.htm>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
One way is to save your stuff to a table inside a dataset, and then simply
use the datasets writeXml & readXml methods. However, this could have
security issues dependent on your congiguration. The registry potentially
allows a more secure method of storage but can be a little slower so Im
informed although Ive never tested that out.

Cheers - OHM
"Woody Splawn" <no****@splawns.com> wrote in message
news:ev**************@TK2MSFTNGP12.phx.gbl...
In the tool I used to use I would write certain things to a .ini file in a
users private directory from time to time. For example, when the
application was started, a certain section of that .ini file is checked so
that the application will start in a way that is unique to the users
machine. This is a non windows app.

I see that it is not convenient to do the same in VB.net. Tools for writing and reading from a .ini file are not good. It has occurred to me, however, that I might just as easily make use of writing that data to an xml file and get the same result.

Is anyone else doing it this way?

Nov 20 '05 #4
Out of the box I don't think CMAB supports different profiles. When I was
testing it, it wanted to save everything to the common app.config.

http://www.gotdotnet.com/Community/M...aspx?id=166329

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2i************@uni-berlin.de...
* "Woody Splawn" <no****@splawns.com> scripsit:
In the tool I used to use I would write certain things to a .ini file in a users private directory from time to time. For example, when the
application was started, a certain section of that .ini file is checked so that the application will start in a way that is unique to the users
machine. This is a non windows app.
Configuration Management Application Block

<URL:http://msdn.microsoft.com/library/de...y/en-us/dnbda/
html/cmab.asp>
<URL:http://www.palmbytes.de/content/dotnet/optionslib.htm>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #5
JLW
Go to my website, and send me an e-mail. I have a library that will do
that, and you can have seperate files for each profile, or contain it all
inside an app.config file. Your preference. It acts just like an INI file
without the hassle

HTH,
JLW

"Woody Splawn" <no****@splawns.com> wrote in message
news:ev**************@TK2MSFTNGP12.phx.gbl...
In the tool I used to use I would write certain things to a .ini file in a
users private directory from time to time. For example, when the
application was started, a certain section of that .ini file is checked so
that the application will start in a way that is unique to the users
machine. This is a non windows app.

I see that it is not convenient to do the same in VB.net. Tools for writing and reading from a .ini file are not good. It has occurred to me, however, that I might just as easily make use of writing that data to an xml file and get the same result.

Is anyone else doing it this way?

Nov 20 '05 #6
Hi Woody,

Yes, I prefer the same way as OHM, except that in my experience the registry
is the fastest.

Registry for things that are typical workstation depended.
- Last place of a form
- Size of the form
- encrypted passwords
Etc.

XML file for installation dependable things
- Not good fitting in the resource files language's issues (I thought you
had some Spanish issues, however maybe I mix you up with someone else)
- Special user settings before configuration etc.
- All things you want to take with you when your workstation is crashed,
however you have a backup.

I hope this helps?

Cor
Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: nbaiju | last post by:
Hi, I am building a asp.net application which has satellite assemblies. When building the satellite assemblies dll's from Visual Studio 2003 GUI the application works fine . i.e. the resource...
7
by: Allan Bruce | last post by:
I have had a look through the FAQ and found that if I am using a class template then I need an argument list. I have tried to add this but it is not quite working - i.e. it doesnt compile. My...
9
by: Fred H | last post by:
I'm currently trying to write a function template that can fill a variable of arbitrary type with 'random' stuff, but I can't seem to get my function template working. In my .h file I've...
5
by: Andrei Pociu | last post by:
I have a major doubt about outputting text in ASP .NET when using code behind. I know most of the output you gain from a code behind file (.aspx.cs) is outputted to the Webform (.aspx) using...
3
by: ABC | last post by:
How to create a web page class for inhert web page using ASP.NET 1.1 and 2.0?
2
by: Phillip Galey | last post by:
I have an object called Place which contains only string properties and has the <Serializable()> flag before the class name declaration. I also have a collection object called Places, which is...
15
by: Joe Fallon | last post by:
I would like to know how you can figure out how much memory a given instance of a class is using. For example, if I load a collection class with 10 items it might use 1KB, and if I load it with...
21
by: kingnothing737 | last post by:
Alright. The text file in question is an online game server's log file (log.log being the file, the game being Halo). It has information in it that I would like to be extracted and put in a table...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
15
by: tshad | last post by:
Do I still need to close an object in a finally statement after a catch if it is part of a using statement? For example: FileStream fs = null; try { using (FileInfo fInfo = new...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.