I am trying to develop a C# program for Window Mobile, it is an expenses program using an XML file as a database. I am using Visual Studio 2005 with the Windows Mobile SDK and have created the XML file through the IDE.
I believe I have the right file path but am getting an exception when trying to open the file.
Quote
Could not find file '\Program Files\DeviceApplication1\budget.xml'.
The XML file is obviously called budget.xml, I have tried hard coding the file path and also retrieving it.
class XMLHandler
{
private XmlDocument xdoc;
private string filePath;
private Hashtable expenses;
public XMLHandler ()
{
xdoc = new XmlDocument();
filePath = "\\Program Files\\DeviceApplication1\\budget.xml";
// filePath = System.IO.Path.GetDirectoryName(
//System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\budget.xml";
expenses = new Hashtable();
}
public void openAndRead()
{
FileStream rfile = new FileStream(filePath, FileMode.Open);
xdoc.Load(rfile);
//get all the Expense nodes
XmlNodeList list = xdoc.GetElementsByTagName("Expense");
foreach (XmlElement currentElement in list)
{
string expenseName = currentElement.GetAttribute("Name");
string expenseValue = currentElement.FirstChild.InnerText;
expenses.Add(expenseName, expenseValue);
}
}
public ArrayList getExpenses()
{
ArrayList exp = new ArrayList();
foreach (DictionaryEntry entry in expenses)
{
exp.Add(entry.ToString());
}
return exp;
}
}
I am getting the exception on this line: FileStream rfile = new FileStream(filePath, FileMode.Open);
I am testing this on the emulator which comes in the SDK, and have tried to locate the XML in the emulator but have not been able to, if anyone could guide me in the right direction that would be great.
Thanks
Jono

New Topic/Question
Reply



MultiQuote





|