.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Read path from external file // app.cofig

7 REPLIES 7
Reply
Message 1 of 8
xpeter88
440 Views, 7 Replies

Read path from external file // app.cofig

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

7 REPLIES 7
Message 2 of 8
mzakiralam
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.
Message 3 of 8
xpeter88
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

 

 

Message 5 of 8
HJohn1
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

Message 6 of 8
fieldguy
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.

Message 7 of 8
dgorsman
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.
"I don't know" is the beginning of knowledge, not the end.


Message 8 of 8
xpeter88
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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost