Winform custom xml configuration files and configuration file path to get

Scenes

In Winform program, a number of configuration items you need to store the configuration file, then you need a custom xml configuration file format. And some tools to get in the path of the configuration file and load its content.

Public concern number
overbearing program ape
acquisition-related programming e-books, tutorials and push for free download.

achieve

First, create a new file in the project folder named config, then add the right xml file.

 

 

A custom xml node follows

<? XML Version = " 1.0 " encoding = " UTF-. 8 " ?> 
<the Configure> 
    <-! default number of the Y-axis. 1 -> 
    <yConut> . 1 </ yConut> 
    <-! Y axis sets - > 
    <the YAxis> 
        <-!> - Y-axis first 
        <Yaxi> 
            <NUM> . 1 </ NUM> 
            <title> temperature </ title> 
            <Color> Black </ Color> 
            <min> - 1500 </ min> 
            <max> 1500 </ max> 
        </ Yaxi> 
        <-! second axis Y ->
        <Yaxi>
            <num>2</num>
            <title>电压</title>
            <color>black</color>
            <min>-1500</min>
            <max>1500</max>
        </Yaxi>
    </YAxis>
   
</Configure>

 

Then we'll create a new project under utils package, to create a new class of tools in this package for reading the configuration file.

At this time, we can see the paths of the two files in VS is the following relationship:

 

 

At this time, the path required to obtain the profile of the tool described above in the following classes.

Note: If we create a new directory in VS and add the configuration file, then packaged in the final project, only

Release or debug exe files exist under the bin, and then if you need to read configuration files in other directories, you will not find.

So it is necessary configuration files are stored in the debug or release directory under the bin, but we also can be configured in VS during development.

Right-click in the VS profile - Advanced Properties - copied to the output directory - the copy if newer, it will automatically copy it to debug or release directory under the bin when changing.

 

 

Such debug or release the bin directory of the project in a real will exists.

 

 

How to get debug or release directory under the bin directory

// get the path to the executable file - that is, debug or release directory under the bin directory 
String context = System.Windows.Forms.Application.StartupPath;
 String path = String.Concat (context, @ " \ config \ YAxisSet.xml " ) ;

 

Guess you like

Origin www.cnblogs.com/badaoliumangqizhi/p/11454149.html