C#手机开发的路径问题

    技术2026-05-28  7

    mobile开发读取文件的路径与一般的winform开发路径有所不同,路径是基于根目录的,以手机空间为例,/   :表示根目录如果卡上有一个文件夹AA,里面有一个bb.xml,那么要访问该文件夹内的bb文件即应该是

    DataSet ds=new DataSet();

    ds.ReadXml(/AA/bb.xml);

     

    如果要读取当文件运行文件夹的路径即可以用

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

    其中apppath就是程序的运行路径,即如果一个exe运行文件对应的目录下面有一个bb.xml文件,要在运行文件时访问该xml文件可以这样写

     

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

    apppath=apppath.Substring(0,apppath.LastIndexOf("//"));

    DataSet ds = new DataSet();ds.ReadXml(apppath+@"/billDataSet.xml");dataGrid1.DataSource = ds.Tables[0];

     

    这样写无论在测试环境还是在手机上都可行.

    最新回复(0)