我在My project With Name(ReportFile)中添加了一个文件夹,我正在该文件夹中保存xml文件。
我想在Xml
中显示所有DropDownList
文件名
(存储在该文件夹中)
我的掉落:
<asp:DropDownList ID="ddlReportTemplate" runat="server" AutoPostBack="True">
</asp:DropDownList>
答案 0 :(得分:2)
在
背后的代码的Page_Load中 protected void Page_Load(object sender, EventArgs e)
{
var reportFolderPath = Server.MapPath("~/Reports"); //change the "~/Reports" to your report folder name
IEnumerable<string> xmlFiles = Directory.GetFiles(reportFolderPath, "*.xml");
//As a common practice server file path should not be shown to the client, use file name instead
xmlFiles = xmlFiles.Select(o => Path.GetFileNameWithoutExtension(o)).Where(o => o.Contains("Arun"));;
ddlReportTemplate.DataSource = xmlFiles;
ddlReportTemplate.DataBind();
}