471,573 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,573 software developers and data experts.

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

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
Sep 8 '09 #1
6 7358
648 Expert 512MB
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!
Sep 8 '09 #2
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

Sep 9 '09 #3
648 Expert 512MB

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

What is the error/problem that you are getting?


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");
Sep 9 '09 #4
533 Expert 512MB
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);
Then try:

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

Sep 9 '09 #5
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");
It returns me the file.
But first I have to configure my emulators shared folder.
Sep 10 '09 #6
648 Expert 512MB
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
Sep 10 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by =?Utf-8?B?Q2hhcmxlcw==?= | last post: by
1 post views Thread by =?Utf-8?B?V29vZGdub21l?= | last post: by
9 posts views Thread by =?Utf-8?B?RGFuaWVs?= | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by Vinnie | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.