应用程序配置在控制台应用 [英] Application configuration in console application
问题描述
大家好,
我创建了一个控制台应用程序,其中文本文件内容被移动到数据库表.I想在app app中声明文本文件路径可以任意1告诉如何在app config中声明文本文件路径如何在控制台应用程序中调用它
Hi All,
I have created a console application where the text file contents are being moved to a database table .I want to declare the text file path in app config can any 1 tell how to declare the text file path in app config n how to call it in a console application
推荐答案
你好,
我认为你可以添加所需的数据作为键和值,如:
打开app.config文件并添加配置下的appsetting节点。将值添加为键和值对
Hello there,
I think you can add the required data as Key and Values like :
Open the app.config file and add the "appsetting" node under configuration. Add the values as key and value pair
<appSettings>
<add key="Key1" value="Key1Value"/>
<add key="Key2" value="Key2Value"/>
</appSettings>
要从app.config获取值,您需要添加您的控制台应用程序中的System.Configuration注意事项。
在Key的帮助下访问该值:
string keyval = ConfigurationManager.AppSettings 。获取(Key1);
我认为这将达到目的。如果这不是你想要的,请告诉我。
问候
To get the values from the app.config you need to add the System.Configuration reffrence in your Console application.
To access the value with the help of Key :
string keyval = ConfigurationManager.AppSettings.Get("Key1");
I think this is going to serve the purpose. Do let me know if this is not what you want.
regards
对不起您的部分代码发布不可见但如果您只想在app config中获取文件的路径,则可以为文件保存[完整路径]或[部分路径],例如
Sorry some of the part of the code you have posted was not visible but If you just want to have the path for a file in app config yes you can save either [Full Path] or [Partial path] for the file like
<appSettings>
<add key="Key1" value="D:/data.xml"/>
<add key="Key2" value="Key2Value"/>
</appSettings>
并访问该值:
string keyval = ConfigurationManager .AppSettings.Get(Key1);
检查该位置是否存在该文件:
bool boo =文件。存在(keyval);
您的应用需要System.IO参考。
问候
and to access the value :
string keyval = ConfigurationManager.AppSettings.Get("Key1");
check if the file exists on the location or not :
bool boo = File.Exists(keyval);
You need System.IO reference in your app.
Regards
所以,如果我给我的文件路径像
< appsettings>
< add key =Key1value =net.txt =>
这个有效吗?
string keyval = ConfigurationManager.AppSettings.Get(Key1);
so if i give my file path like
<appsettings>
<add key="Key1" value="" net.txt="">
is this valid?
string keyval = ConfigurationManager.AppSettings.Get("Key1");
这篇关于应用程序配置在控制台应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!