Connecting Tech Pros Worldwide Forums | Help | Site Map

How can I get A XML file In Windows Mobile 6.o using C#?

Member
 
Join Date: Sep 2009
Location: Sunvillage
Posts: 42
#1: Sep 8 '09
I m new in developing windows mobile.
I am facing a problem to getting a xml file in code.

I have a XML file named trial.xml in the same folder where the application's executable exist.

Iused the following Code

Expand|Select|Wrap|Line Numbers
  1.  XmlDocument xd = new XmlDocument();
  2.             xd.Load("trial.xml");
It does not worked then I used

Expand|Select|Wrap|Line Numbers
  1. xd.Load("trial.xml");
  2. XmlTextReader reader = new XmlTextReader("trial.xml");
  3. XmlNodeList nodelst;
  4. nodelst = XmlDoc.GetElementsByTagName("detail");
It also not worked.
There is a error Occurs that directory or file not found.

Can anybody give me the solution of this Problem.


I hope you will help me.

Thanx in Advance

markmcgookin's Avatar
Moderator
 
Join Date: Dec 2006
Location: Northern Ireland / England
Posts: 546
#2: Sep 8 '09

re: How can I get A XML file In Windows Mobile 6.o using C#?


Hey, this is one of my favourite ways to rip through XML in c#

Expand|Select|Wrap|Line Numbers
  1. XmlDocument xmlFile = new XmlDocument();
  2.             xmlFile .Load(@"\My Documents\myXML.xml");
  3.             XmlNodeList nodeList = xmlFile.GetElementsByTagName("resources");
  4.             foreach (XmlElement elem in nodeList)
  5.             {
  6.                 foreach (XmlElement elem2 in elem.ChildNodes)
  7.                 {
  8.                   //.... do all your stuff here or loop more!
  9.  
Member
 
Join Date: Sep 2009
Location: Sunvillage
Posts: 42
#3: Sep 9 '09

re: How can I get A XML file In Windows Mobile 6.o using C#?


Hi!, markmcgookin

I had tried your suggestion but I not works in Windows Mobile Application.
Can you give me this in Windows Mobile SDK6.0

Thanxxxx
markmcgookin's Avatar
Moderator
 
Join Date: Dec 2006
Location: Northern Ireland / England
Posts: 546
#4: Sep 9 '09

re: How can I get A XML file In Windows Mobile 6.o using C#?


Kapil,

That was copied and pasted from a Windows Mobile 5/6 project.

What is the error/problem that you are getting?

Mark

EDIT: Oh I just saw in your original post that it can't find/access the file. Are you SURE that the file is in the local directory on the PDA? ... i.e. "Program Files/YourApplication/Trial.xml" You should check on the device to make sure that the file is there. Try manually copying the file into My Documents/Business on the PDA then change this line in the code I sent code

Expand|Select|Wrap|Line Numbers
  1. xmlFile .Load(@"\My Documents\Business\trial.xml");
  2.  
codegecko's Avatar
Moderator
 
Join Date: May 2007
Location: United Kingdom
Posts: 395
#5: Sep 9 '09

re: How can I get A XML file In Windows Mobile 6.o using C#?


This was taken from MSDN when I googled "c# mobile application path":

Expand|Select|Wrap|Line Numbers
  1. path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
  2.  
Then try:

Expand|Select|Wrap|Line Numbers
  1. xmlFile .Load(path + @"\trial.xml");
  2.  
Hope this helps.

codegecko
Member
 
Join Date: Sep 2009
Location: Sunvillage
Posts: 42
#6: Sep 10 '09

re: How can I get A XML file In Windows Mobile 6.o using C#?


Thank You to all.
But I got the solution.
I had placed that file in my application's folder. So its not getting in Mobile emulator.

After all trying what ever you suggest me I place that file in SD Card and than Write the direct path I got the file.

Expand|Select|Wrap|Line Numbers
  1. XmlDocument Xdoc=new XmlDocument();
  2. Xdoc.Load("\\Storage Card\\trial.xml");
  3.  
It returns me the file.
But first I have to configure my emulators shared folder.
markmcgookin's Avatar
Moderator
 
Join Date: Dec 2006
Location: Northern Ireland / England
Posts: 546
#7: Sep 10 '09

re: How can I get A XML file In Windows Mobile 6.o using C#?


Yeah, if you right click the file in VS2008 and make sure that in Build Options it is set to "Copy Always" over to the device
Reply