.NET

Reply
Active Contributor
xpeter88
Posts: 42
Registered: ‎11-14-2013
Message 1 of 8 (205 Views)

Read path from external file // app.cofig

205 Views, 7 Replies
02-21-2014 01:28 AM

Hi,

I have project (*.dll) that should read paths as string from external file.

Only requiriment is that it have to be in external file that can be modified by user before he runs this application.

 

I dont't know where to start.

I tried to use app.confing from project settings that writes desired values to xml file but no success yet (probably need to study this more).

 

Is this the right approach for what I am trying to do? Or is there any other way?

 

Many thanks,

Peter

Mentor
mzakiralam
Posts: 230
Registered: ‎11-09-2012
Message 2 of 8 (195 Views)

Re: Read path from external file // app.cofig

02-21-2014 01:55 AM in reply to: xpeter88
HI,
I am Little bit confused about your question. If you have a file and it text file then you can easily read any of line without any Problem. if you have a XML file you can also read that. But why do you want to use app.config? Please clarify your Problem more explicitly.
Active Contributor
xpeter88
Posts: 42
Registered: ‎11-14-2013
Message 3 of 8 (187 Views)

Re: Read path from external file // app.cofig

02-21-2014 02:33 AM in reply to: mzakiralam

In general, I have a form with listbox that lists all the *.dwg files in particular folder. But the path may be different depending on PC where application (*.dll) is installed just something like "C:\mylistboxfiles" or D:\mylistboxfiles" etc.. I just would need allow the user to change this path whenewer he needs and make my application more flexible.

 

So I was looking on the internet what options do I have and found that XML app.config may be a solution to store this information and read it by applicaton.

 

E.g. this does not work and seems returns nothing form xml.

 

this is in my class in project;

Dim dbPath As String = ConfigurationSettings.AppSettings("mypath")

 and this is in xml;

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <appSettings>
   <add key="mypath" value="c:\mylistboxfiles" />
 </appSettings>
</configuration>

 

I was expecting that I can read the settings and allow to user change the path from here .

 

I can create e.g. text (*.txt) file and read the values from there but I was looking for some more suitable solution and newer method for this so that's why I asked what are the options for how to read settings from external file like this.

 

I did not explain all the details for the first time, I know, sorry for that.

 

Regards,
Peter

 

 

Mentor
mzakiralam
Posts: 230
Registered: ‎11-09-2012
Message 4 of 8 (165 Views)
Distinguished Contributor
HJohn1
Posts: 169
Registered: ‎09-26-2008
Message 5 of 8 (159 Views)

Re: Read path from external file // app.cofig

02-21-2014 06:55 AM in reply to: xpeter88

I am going to put here my two pennies worth.  To solve your issue I would just create a setting variable for storing the path, this will be stored on the app.config file. You can access it calling My.Settings.(Variable Name) and save it by calling My.Settings.Save() method.  I will set a default value of say None.  On the application before using the path I would check that the value is set to a valid system folder, if the value is not set then I would prompt the user to set it.  Hope it helps

Valued Mentor
fieldguy
Posts: 367
Registered: ‎03-31-2005
Message 6 of 8 (154 Views)

Re: Read path from external file // app.cofig

02-21-2014 07:13 AM in reply to: xpeter88

My $0.02 CAN,

 

App.config for class libraries (.dll) is not the same as for .exe.  I found that the settings I was creating and trying to use ended up in acad.exe.config (the host).  When I found this out I started using txt files instead.

*Expert Elite*
dgorsman
Posts: 5,112
Registered: ‎10-12-2006
Message 7 of 8 (111 Views)

Re: Read path from external file // app.cofig

02-24-2014 08:25 AM in reply to: fieldguy

I'll throw out another option used by many programs for storing paths: registry keys.  Relatively easy to manipulate from multiple sources, and already includes separate locations for per-computer/per-user settings.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
Adopt. Adapt. Overcome. Or be overcome.
A good question will be halfway to a good answer.


Active Contributor
xpeter88
Posts: 42
Registered: ‎11-14-2013
Message 8 of 8 (101 Views)

Re: Read path from external file // app.cofig

02-24-2014 01:10 PM in reply to: xpeter88

Many thanks for your answers guys, it helped me. I've decided to use this part of code. It is something else what I asked for but good enough for now.

 

Dim mycurrentpath As String = My.Application.Info.DirectoryPath

 It takes the current path of loaded *.dll and by this I can get the current path from any place of my application.

I checked for articles and solutions you've sent so next time I will know what options do I have.

 

Peter

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community