473,320 Members | 1,868 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,320 software developers and data experts.

VB.NET INI or XML file for path locations

Hello, I have a complete project in VB.NET (2003) with all the path to
the folders where the files being used are. For example I have these
variables:

' Setup Directory Paths
ImportDir = "C:\OrdersIn\"
ExportDir = "C:\OrdersOut\"
LogDir = "E:\OrdersLogs\"

This work fine right now. However, if for some reason in the near
future I have to move these folders to another drive, I will have to go
back to the VB.NET code and replace them there. What I would like to
do is create is a INI or XMF file with these paths and then use it in
my project. I'm hoping to also add more variable values such as the
connection string to the SQL database in our server.

Since I am fairly new to VB.NET. I have no idea where to start. How
can I set this paths in the file and how do I open/use the file in the
VB.NET code?

Thanks for your help.

May 19 '06 #1
8 6410
I would recommend XML as it is the newer technology and I think
XMLSerialization is the best thing since sliced bread! :-)

After reading in the XML file with the Deserialization method, the
values for the file paths will be stored in a Class Instance's
Properties.

You could then write a configuration form that allows the user to
change one or more values and write the XML file back out with the
Serialization method.

Check the Help out, search for XMLSerialization.

May 19 '06 #2

IL***@NETZERO.NET wrote:
Hello, I have a complete project in VB.NET (2003) with all the path to
the folders where the files being used are. For example I have these
variables:

' Setup Directory Paths
ImportDir = "C:\OrdersIn\"
ExportDir = "C:\OrdersOut\"
LogDir = "E:\OrdersLogs\"

This work fine right now. However, if for some reason in the near
future I have to move these folders to another drive, I will have to go
back to the VB.NET code and replace them there. What I would like to
do is create is a INI or XMF file with these paths and then use it in
my project. I'm hoping to also add more variable values such as the
connection string to the SQL database in our server.

Since I am fairly new to VB.NET. I have no idea where to start. How
can I set this paths in the file and how do I open/use the file in the
VB.NET code?

Thanks for your help.


You can accomplish this by adding a config file to your application.
Then, you can add these items to it by editing the app.config file:

<configuration>
<add key="ImportDir" value="C:\OrdersIn\" />
</configuration>

Then, in you code:

Imports System.Configuration

....

string importPath = CType (ConfigurationSettings.AppSettings
("ImportDir"), String)

--
Tom Shelton [MVP]

May 19 '06 #3

Tom Shelton wrote:
IL***@NETZERO.NET wrote:
Hello, I have a complete project in VB.NET (2003) with all the path to
the folders where the files being used are. For example I have these
variables:

' Setup Directory Paths
ImportDir = "C:\OrdersIn\"
ExportDir = "C:\OrdersOut\"
LogDir = "E:\OrdersLogs\"

This work fine right now. However, if for some reason in the near
future I have to move these folders to another drive, I will have to go
back to the VB.NET code and replace them there. What I would like to
do is create is a INI or XMF file with these paths and then use it in
my project. I'm hoping to also add more variable values such as the
connection string to the SQL database in our server.

Since I am fairly new to VB.NET. I have no idea where to start. How
can I set this paths in the file and how do I open/use the file in the
VB.NET code?

Thanks for your help.


You can accomplish this by adding a config file to your application.
Then, you can add these items to it by editing the app.config file:

<configuration>
<add key="ImportDir" value="C:\OrdersIn\" />
</configuration>

Then, in you code:

Imports System.Configuration

...

string importPath = CType (ConfigurationSettings.AppSettings
("ImportDir"), String)


Crap! The fact that I almost exclusively use C# now is comming out :)
That above line should be:

Dim importPath As String = CType (ConfigurationSettings.AppSettings
("ImportDir"), String)

--
Tom Shelton [MVP]

May 19 '06 #4
INI files are outdated. XML is the way to go. VS2005 (not sure about 2003) has
a Settings tab for your Application that creates a file named app.config
containing all the settings you wish to store. You can edit this file manually
or programmatically after the fact.

See http://msdn2.microsoft.com/en-us/library/k4s6c3a0.aspx.

<IL***@NETZERO.NET> wrote in message
news:11*********************@u72g2000cwu.googlegro ups.com...
Hello, I have a complete project in VB.NET (2003) with all the path to
the folders where the files being used are. For example I have these
variables:

' Setup Directory Paths
ImportDir = "C:\OrdersIn\"
ExportDir = "C:\OrdersOut\"
LogDir = "E:\OrdersLogs\"

This work fine right now. However, if for some reason in the near
future I have to move these folders to another drive, I will have to go
back to the VB.NET code and replace them there. What I would like to
do is create is a INI or XMF file with these paths and then use it in
my project. I'm hoping to also add more variable values such as the
connection string to the SQL database in our server.

Since I am fairly new to VB.NET. I have no idea where to start. How
can I set this paths in the file and how do I open/use the file in the
VB.NET code?

Thanks for your help.

May 19 '06 #5
Hi guys. Thanks for replying. I'm trying Tom's solution first, but I
am getting an error :
"Unrecognized configuration section add"

I created a new App.config file by going to "Project" > "Add New Item"
"Application Configuration Settings" in the menu bar.


This is what I have in the App.config file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<add key="ImportDir" value="C:\OrdersIn\" />
</configuration>
I added the "Imports System.Configuration " line all the way to the top
of the code next to the other Imports lines.

Then I added this line to my code:
Dim ImportPath As String =
CType(ConfigurationSettings.AppSettings("ImportDir "), String)

I tried to test it by doing a message box pop up.
MsgBox(ImportPath)
I also tried some variations such as changing the add key line in the
app.config to:
<add key="ImportDir" value="C:\OrdersIn\"></add>

and adding a extra .getkey in the import path declaration:
Dim ImportPath As String =
CType(ConfigurationSettings.AppSettings.GetKey("Im portDir"), String)

That did not help either. Do you have any ideas why I am getting this
error?

Thanks again for your help.

May 19 '06 #6

IL***@NETZERO.NET wrote:
Hi guys. Thanks for replying. I'm trying Tom's solution first, but I
am getting an error :
"Unrecognized configuration section add"

I created a new App.config file by going to "Project" > "Add New Item"
"Application Configuration Settings" in the menu bar.


This is what I have in the App.config file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<add key="ImportDir" value="C:\OrdersIn\" />
</configuration>


It's my fault :) It should look like:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ImportDir" value="C:\OrdersIn\" />
</appSettings>
</configuration>

Sorry...

--
Tom Shelton [MVP]

May 20 '06 #7
http://www.kjmsolutions.com/xmlsettings.htm

--
Get a powerful web, database, application, and email hosting with KJM
Solutions
http://www.kjmsolutions.com

<IL***@NETZERO.NET> wrote in message
news:11*********************@u72g2000cwu.googlegro ups.com...
Hello, I have a complete project in VB.NET (2003) with all the path to
the folders where the files being used are. For example I have these
variables:

' Setup Directory Paths
ImportDir = "C:\OrdersIn\"
ExportDir = "C:\OrdersOut\"
LogDir = "E:\OrdersLogs\"

This work fine right now. However, if for some reason in the near
future I have to move these folders to another drive, I will have to go
back to the VB.NET code and replace them there. What I would like to
do is create is a INI or XMF file with these paths and then use it in
my project. I'm hoping to also add more variable values such as the
connection string to the SQL database in our server.

Since I am fairly new to VB.NET. I have no idea where to start. How
can I set this paths in the file and how do I open/use the file in the
VB.NET code?

Thanks for your help.

May 20 '06 #8
Thanks a lot Tom, that did the trick.

JR

May 22 '06 #9

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

Similar topics

11
by: BoonHead, The Lost Philosopher | last post by:
I think the .NET framework is great! It's nice, clean and logical; in contradiction to the old Microsoft. It only saddens me that the new Microsoft still doesn't under stand there own...
2
by: \A_Michigan_User\ | last post by:
Ok, I give up. I need to #include the same 1 file (IncludeThis.asp) into 3 different asp files. 1> C:\MyDir\ThisFile.asp 2> D:\MyDir\AASubSub\ThatFile.asp 3>...
10
by: hendafe | last post by:
I have a problem of importing a text file into Access. The text file will be imported using a delimiter, say ( , ) for example. This should be imported into the database. An example is: John,...
2
by: Susan Baker | last post by:
Hi, I am (trying) to compile some code I downloaded from the internet. The sources contain references to header files - using the form : #include <pathname/file> If I change the form to...
5
by: Al | last post by:
Hi all We have created a xml file that imports a single project using the Import element. This project compiles to a class library, but has references to two other projects that are also class...
3
by: den 2005 | last post by:
Hi everybody, I like to allow user to select and browse to which location to save the pdf file of a crystal report viewed on a web page, how can i do this in ASP.Net? I need to get the path...
18
by: walterbyrd | last post by:
I am trying to develop an app where: the same file, in the same place, will be uploaded, and then processed. Everything I can find about uploading a file, uses a form that requires the user to...
2
by: contractsup | last post by:
Environment: $ uname -a AIX <withheld2 5 000100614C00 $ db2level DB21085I Instance "<withheld>" uses "32" bits and DB2 code release "SQL08024" with level identifier "03050106"....
0
by: eholz1 | last post by:
Hello PHP group, I have a question about file locations, and whether on not (in my case, not) a page will execute depending on the location of the php file. I have a web devel server, with a...
0
by: PFancy | last post by:
Hi, Not sure if anyone can help. I have writen some code that will allow users to edit a txt file (it's actually an xml file) in notepad. I can get notepad to open correctly with the correct file,...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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)...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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.