|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
VB.NET INI or XML file for path locationsthe 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. 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. IL***@NETZERO.NET wrote:
Show quoteHide quote > Hello, I have a complete project in VB.NET (2003) with all the path to You can accomplish this by adding a config file to your application.> 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. 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] Tom Shelton wrote:
Show quoteHide quote > IL***@NETZERO.NET wrote: Crap! The fact that I almost exclusively use C# now is comming out :)> > 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) That above line should be: Dim importPath As String = CType (ConfigurationSettings.AppSettings ("ImportDir"), String) -- Tom Shelton [MVP] 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("ImportDir"), String) That did not help either. Do you have any ideas why I am getting this error? Thanks again for your help. IL***@NETZERO.NET wrote:
Show quoteHide quote > Hi guys. Thanks for replying. I'm trying Tom's solution first, but I It's my fault :) It should look like:> 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> > > <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="ImportDir" value="C:\OrdersIn\" /> </appSettings> </configuration> Sorry... -- Tom Shelton [MVP] 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 Show quoteHide quote news:1148066571.792077.57050@u72g2000cwu.googlegroups.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. >
http://www.kjmsolutions.com/xmlsettings.htm
--
Show quote
Hide quote
Get a powerful web, database, application, and email hosting with KJM Solutions http://www.kjmsolutions.com <IL***@NETZERO.NET> wrote in message news:1148066571.792077.57050@u72g2000cwu.googlegroups.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. >
catching a specific exception
Q: GIF image on a form Opening a MS Word document through a button click updating control on form2 from form1 Detect if compiling as a console application 2 dimensional array-->1 dimensional array Get calling function in a function? VB.NET: Implementing RasGetErrorString about example code Copying a project into another solution |
|||||||||||||||||||||||