Domanda

In simple way, I want to save some data in XML file when i tried this code it ran successfully but,unfortunately i didn't the file in the project folder or anywhere on my computer.When I changed the path also i didn't find it. The following is the used code

string configFile = @"config.xml";
XmlDocument xml = new XmlDocument();
XmlElement element = xml.CreateElement("Configuration");
xml.AppendChild(element);
//---create the <LastAccess> element---
element = xml.CreateElement("LastAccess");
element.InnerText = DateTime.Now.ToString();
xml.DocumentElement.AppendChild(element);
//---create the <LastSearchString> element---
element = xml.CreateElement("LastSearchString");
element.InnerText = "sushi";
xml.DocumentElement.AppendChild(element);
xml.Save(configFile);

Can you help me in this problem please.

When I wrote this code and ran the application the file must be saved whatever where

    XmlDocument xml = new XmlDocument();
    XmlElement element = xml.CreateElement("First");
    xml.AppendChild(element);
    element = xml.CreateElement("Second");
    element.InnerText = "LaLa";
    xml.DocumentElement.AppendChild(element);
    xml.Save(@"XML.xml");

and then i try this code as the file has been saved

    element.InnerText = "LaLa";
    xml.DocumentElement.AppendChild(element);
    xml.Save(@"XML.xml");

I got that exception Could not find file '\XML.xml'. please can you help me in this problem.

È stato utile?

Soluzione

The emulator is, for all intents and purposes of this question, a completely separate device. It does not "share" any part of it's file system with the host PC, so there's no way to "browse" it's files (like the one you created" from the PC's Windows Explorer, or the standard file system APIs.

If you want access to the file from the PC, you need to use one of the following to retrieve it:

  1. Configure the emulator to share a folder with the PC. This is don't in the options of the Emulator itself and allows you to "mount" a Host PC folder. That folder becomes the "\Storage Card" root folder in the emulator, so you'd have to change your code appropriately (i.e. save to "\storage card\config.xml")
  2. Use a tool like Remote Registry Editor (in the Start menu under Visual Studio 22008 remote tools), connect to the emulator and download the file.
  3. Use the Emulator Manager to "dock" the emulator so it shows up in ActiveSync/WMDC. When that occurs, a shell extension will show the device in Windows Explorer - though be aware that it is purely a shell extension. There is still no file API access to that system, so you could not write a desktop app that navigates to "My Device\MyFolder\MyFile.xml".
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top