关于Windwos CE 加载XML文件失败问题

Windows CE 下读取 XML文件 

private void button1_Click(object sender, EventArgs e)
        {
            string xmlPath = "//Student.xml";
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(xmlPath);
        }

  xmlDoc.Load(URL); 

 

         假设 项目都放在C盘根目录下,其中Student.xml放在 C:\Student.xml 
         但是 红色字体地方会出错,因为是在WinCE下开发,WinCE没有盘符 ,可是这个路径到底怎么写?

其实解决办法很简单:

 

String CodePath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;

CodePath = CodePath.Substring(0, CodePath.LastIndexOf(@"\"));

string filename = CodePath + "\\Student.xml";
xmlDoc.Load(filename);
 

 

猜你喜欢

转载自yangchenglinkd.iteye.com/blog/1677907
ce
今日推荐