private static DataTable _ConfigDataSource;
private static DataTable ConfigDataSource
{
get
{
if (_ConfigDataSource == null)
{
DataSet ds = new DataSet();
ds.ReadXml(HttpContext.Current.Server.MapPath("~/lgr/config/config.xml"));
_ConfigDataSource = ds.Tables[0];
}
return _ConfigDataSource;
}
}
private string[] GetConfigs(string pid)
{
DataTable dt = ConfigDataSource;
string condition = "Id='" + pid + "'";
string[] configs = new string[3];
DataRow[] row = dt.Select(condition);
if (row.Length > 0)
{
configs[0] = row[0]["type"].ToString();
configs[1] = row[0]["filetype"].ToString();
configs[2] = row[0]["filename"].ToString();
}
return configs;
}
xml文件
<?xml version="1.0" encoding="UTF-8"?>
<Products>
<Product Id="2">
<type>ExportPolicy.b,ExportPolicy</type>
<filetype>text/xml</filetype>
<filename>{1}_{0:yyyyMMddHHmmss}.xml</filename>
</Product>
<Product Id="9">
<type>ExportPolicy.a,ExportPolicy</type>
<filetype>text/xml</filetype>
<filename>{1}_{0:yyyyMMddHHmmss}.xml</filename>
</Product>
</Products>
调用
string[] configs = GetConfigs(pid);
string[] types = configs[0].Split(',');