c#:Dataset读取XML文件动态生成菜单
Step 1:Form1 上添加一个ToolStripContainer控件
Step2:实现代码
private void Form2_Load(object sender, EventArgs e)
{
CMenuEx menu = new CMenuEx();
string sPath = "D:\\Menu.xml";//xml的内容
if (menu.FileExit())
{
menu.LoadAllMenu(sPath, toolStripContainer1);
}
else
{ MessageBox.Show("XML文件加载失败!"); }
}
/// <summary>
/// 菜单读取类
/// </summary>
public class CMenuEx
{
private string _Path;
/// <summary>
/// 设置XML配置文件路径
/// </summary>
public string Path
{
get { return _Path; }
set { _Path = value; }
}
/// <summary>
/// 判断文件是否存在
/// </summary>
/// <returns>文件是否存在</returns>
public bool FileExit()
{
if (File.Exists(_Path))
{ return true; }
else return false;
}
/// <summary>
/// 加载菜单
/// </summary>
/// <param name="menuStrip">母菜单对象</param>
public void LoadAllMenu(string sXmlPath, ToolStripContainer pToolStripContainer)
{
DataSet ds = new DataSet();
ds.ReadXml(sXmlPath, XmlReadMode.Auto);
相关文档:
通过调用CreateDataSetfromXml取得XML数据
Imports System.Xml
Public Const FILE_CONFIG = "MZZ.xml"
Public Const PATH_CONFIG = "\XML\"
Dim dstXML As DataSet
Dim tblXML_DB As DataTable
Dim dtCod As New DataTable
Dim strSQL As String = ""
clsPublic ......
Backup.aspx
protected void Button1_Click(object sender, EventArgs e)
{
string path = Server.MapPath("") + @"\Backup";
if (!Directory.Exists(path))
......
在web程序中,经常会使用在一个网页使用其他网页提交的数据信息,这里可以使用Request内置对象来完成,来获取用户提交的信息,根据客户端提交数据方式的不同,Request对象分别使用Form和QueryString集合属性来获取数据。下面是两种集合获取方式的不同点:通过Form获取数据时在form属性中简单的添加action=“跳转的网页 ......