C#2005 Windows Mobile SmartPhone 5.0下面获取文件路径出错

来源:百度知道 编辑:UC知道 时间:2024/05/30 15:12:23
C#2005 Windows Mobile SmartPhone 5.0下面获取文件路径出错,具体代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace DeviceApplication9
{
public partial class Form1 : Form
{
private DataTable myTable;
//private DataView myView;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);

// create DataTable object
this.myTable = new DataTable();

// load schema and data
this.myTable.ReadXmlSchema(path + "\\cust

设置断点,然后看看System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase具体的目录输出路径,最后把文件考到相关目录下就可以了。

在移动开发中,涉及文件路径时,建议使用绝对路径,而不是相对路径,就像 永恒烛光 说的那样。
还有一个参考的方法就是要注意将customer.xml的属性“复制到输入目录”设置为“始终”或“如果较新则复制”。(默认是不复制)
在调试的时候应该是使用模拟器的吧,跟pc上的调试一样的,建议你去调试一下就知道了。这个问题我以前也遇到过。

你有没有设置断点试试看
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase
这个路径并不是你customers.xsd和customers.xml的路径,而是你的根目录,也就是bin目录下的DeBug目录,所以当然报错了。

你可以直接写路径的,一般的PDA程序的路径都是以
\Program Files\SmartDeviceProject这样的

你可以设置断点试试看

最主要是当前目录的意思是DEBUG下面的 首先 你放到手机里面的时候是否将customers.xsd拷贝到手机里面的当前目录下 模拟器也是一样的的 比如你的程序在\Program Files\deviceapplication9下面 那么你也要将customers.xsd拷贝到这个下面
我想你一定把你的电脑当成手机了 新手经常犯的毛病

this.myTable.ReadXmlSchema(path + "/customers.xsd");
this.myTable.ReadXml(path + "/customers.xml");

永恒烛光 说的对
debug目录,release目录,和你的目录不是一回事