XmlDocument doc = new XmlDocument();
//doc.Load(Microsoft.SqlServer.Server.MapPath("Reres.xml")); doc.Load(HttpContext.Current.Server.MapPath("~/Reres.xml")); XmlNodeList nodes1 = doc.GetElementsByTagName("Table");
foreach (XmlNode node1 in nodes1) //第一层
{
if (node1.Attributes["Name"].Value == "User_Info")
{
XmlNodeList nodes2 = node1.ChildNodes;
foreach (XmlNode node2 in nodes2)//第二层nodes1
{
if (node2.Attributes["Name"].Value == "User_ID")
{
textBox1.Text += node2["Chinese"].InnerText;
textBox2.Text += node2["English"].InnerText;
textBox3.Text += node2["Type"].InnerText;
}
}
}
}
doc.Load(HttpContext.Current.Server.MapPath("~/Reres.xml"));这句提示未将对象引用设置到对象的实例,求教各位指导啊
//doc.Load(Microsoft.SqlServer.Server.MapPath("Reres.xml")); doc.Load(HttpContext.Current.Server.MapPath("~/Reres.xml")); XmlNodeList nodes1 = doc.GetElementsByTagName("Table");
foreach (XmlNode node1 in nodes1) //第一层
{
if (node1.Attributes["Name"].Value == "User_Info")
{
XmlNodeList nodes2 = node1.ChildNodes;
foreach (XmlNode node2 in nodes2)//第二层nodes1
{
if (node2.Attributes["Name"].Value == "User_ID")
{
textBox1.Text += node2["Chinese"].InnerText;
textBox2.Text += node2["English"].InnerText;
textBox3.Text += node2["Type"].InnerText;
}
}
}
}
doc.Load(HttpContext.Current.Server.MapPath("~/Reres.xml"));这句提示未将对象引用设置到对象的实例,求教各位指导啊
6楼 net_lover,我是在winform中使用的,那该怎么解决这个问题呢?
exe文件和xml在同一路径下或者doc.Load(Application.ExecutablePath + "\\Reres.xml");
c# winform用
1:“Application.StartupPath”:获取当前应用程序所在目录的路径,最后不包含“\”;
2:“Application.ExecutablePath ”:获取当前应用程序文件的路径,包含文件的名称;
3:“AppDomain.CurrentDomain.BaseDirectory”:获取当前应用程序所在目录的路径,最后包含“\”;
4:“System.Threading.Thread.GetDomain().BaseDirectory”:获取当前应用程序所在目录的路径,最后包含“\”;
5:“Environment.CurrentDirectory”:获取当前应用程序的路径,最后不包含“\”;
6:“System.IO.Directory.GetCurrentDirectory”:获取当前应用程序的路径,最后不包含“\”;