asp.net - how to give xml file source in app.config and write/read those xml files form winform?
问题描述
DataSet ds = CreateDynamicDataSet();
ds.WriteXml(@"E:\AppScienti\AppScienti-POSLite\POSLite-Dev\XML\POSLite.xml");
private DataSet CreateDynamicDataSet()
{
DataSet ds = new DataSet("DS");
//ds.Namespace = "StdNamespace";
dtOutletMapping.TableName = "Tables[2]";
ds.Tables.Add(dtOutletMapping);
dtxmlEmployee.TableName = "Tables[0]";
ds.Tables.Add(dtxmlEmployee);
dtxmlOrg.TableName = "Tables[1]";
ds.Tables.Add(dtxmlOrg);
return ds;
}
In above code I have path directly in winform and its working fine, now I want to keep path in app.config
and use a path to write a dataset into file
any possible solution please?
解决方案
确保您已添加对System.Configuration
. (右键单击项目并选择“添加引用”并在“.Net”选项卡中找到它)。
修改 app.config 文件,如下所示: 在 下appSettings
,添加您的文件名,如下所示。
<configuration>
<appSettings>
<add key="xmlFile" value="c:\\users\\test.xml" />
</appSettings>
</configuration>
现在在代码中添加命名空间
using System.Configuration;
当你想读取文件名时,如下所示
string filename = ConfigurationManager.AppSettings.Get("xmlFile");
DataSet ds = CreateDynamicDataSet();
ds.WriteXml(filename);
推荐阅读
- python - instapy 没有登录帐户
- json - 使用 Reactjs、Axios 和本地 JSON 文件的登录过程
- reactjs - i18 文本内的材质 ui 图标
- wordpress - 在具有木材值的树枝模板中设置上下文,
- c# - 实体框架未映射连接
- python - Django Nginx:给出警告:django.request:未找到:运行服务器时
- batch-file - 在批处理脚本中编写一个宏,将另一个库文件批处理中的其他宏加载到内存中
- php - PHP Discord Webhook POST 请求返回字符串(0)
- kotlin - 使用 kotlin 在函数内部返回一个函数(返回一个字符串)
- node.js - 我的测试服务器(连接到测试 PostgreSQL 数据库)没有以 JSON 格式显示数据?