locked
Embedding and accessing xml files RRS feed

  • Question

  • Hello Guys,

    I want embed xml files into my application so that they are embedded in the exe file and invisible to the smart device user

    and I want to access and edit(read/write) these xml files from c# code in my application but I can't

    would anyone tell me how can I edit these embedded xml files?

    I'm using visual studio 2008, c# language with .net compact framework 2.0

    thanks in advance.

    Tuesday, July 7, 2009 8:54 AM

Answers

  • You can only read the embedded XML file but not write to it (hardly). I notice that Malleswar's sample doesn't mention how to access *embedded* XML files, so I find another:
    http://bytes.com/groups/net-xml/176889-working-embedded-xml-file 


    Please mark the post that helps you, and unmark that does not. This benefits our community members.
    • Marked as answer by warrentang Monday, July 13, 2009 7:38 AM
    Friday, July 10, 2009 6:16 AM
  • You can modify XML document you loaded from the embedded resource, but it will not in any way shape or form be saved back to embedded resource. Embedded resources are a static chunk of binary data stored inside your .exe or .dll file and accessible at runtime. They cannot be modified. If you want to persist your changes between sessions, you need to save to a file located in the filesystem, preferably under \Application Data
    Alex Feinman. MVP .NET Compact Framework
    • Marked as answer by warrentang Monday, July 13, 2009 7:38 AM
    Sunday, July 12, 2009 4:46 PM
  • Yes, they are clear text blobs inside binary files. Anybody can see and extract them. In many cases you can even open binary with, say, notepad and read the XML.

    Besides, all binary files should be signed - which means they are never to be changed even it that's possible (and it's not on NETCF) since that would break digital signature.

    Keep your list in separate file. Configuration file come to mind first.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by warrentang Monday, July 13, 2009 7:38 AM
    Sunday, July 12, 2009 4:54 PM

All replies

  • Tuesday, July 7, 2009 9:29 AM
  • You can only read the embedded XML file but not write to it (hardly). I notice that Malleswar's sample doesn't mention how to access *embedded* XML files, so I find another:
    http://bytes.com/groups/net-xml/176889-working-embedded-xml-file 


    Please mark the post that helps you, and unmark that does not. This benefits our community members.
    • Marked as answer by warrentang Monday, July 13, 2009 7:38 AM
    Friday, July 10, 2009 6:16 AM
  • thank u all for paying attention. But if I can't write to embedded XML file, how can I save data entered from user in an embedded file so that these files are hidden from user in Windows Mobile Application
    thanks in advance.
    Sunday, July 12, 2009 6:41 AM
  • You should use normal files for something which is not read only. They will not be hidden from user - but neither are read only embedded resources.

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Sunday, July 12, 2009 7:29 AM
  • @ Chunsheng : I tried the following code and it worked properly. It can write/read from embedded xml file
    code:

    public

     

    string writeXmlFile()

    {

     

    Assembly assem = this.GetType().Assembly; // get the reference of the current assmbly.

     

    Stream stream = assem.GetManifestResourceStream("ResourceEdit.test_1.xml");

     

    XmlDocument doc = new XmlDocument();

    doc.LoadXml(Properties.

     

    Resources.test_1);

     

     

    XmlNode newNode = doc.CreateNode(XmlNodeType.Element, "color", "");

    newNode.InnerText =

     

    "ABCD"; XmlNodeList nodes = doc.GetElementsByTagName("color");

     

    string colorName = nodes[0].InnerText;

     

    // stream.Flush();
    // stream.Close();
    return colorName;

    doc.DocumentElement.AppendChild(newNode);

     

     

     

    }

    @ Ilya Tumanov : how embedded files are shown to program users? Aren't they embedded in the .EXE file?
    And what if I have a list of countries that user can see and add a new country so that he can see it in the same list next time he use the program?how can I implement that issue?

    thank u all

    • Edited by Usama007 Sunday, July 12, 2009 9:51 AM
    Sunday, July 12, 2009 8:17 AM
  • You can modify XML document you loaded from the embedded resource, but it will not in any way shape or form be saved back to embedded resource. Embedded resources are a static chunk of binary data stored inside your .exe or .dll file and accessible at runtime. They cannot be modified. If you want to persist your changes between sessions, you need to save to a file located in the filesystem, preferably under \Application Data
    Alex Feinman. MVP .NET Compact Framework
    • Marked as answer by warrentang Monday, July 13, 2009 7:38 AM
    Sunday, July 12, 2009 4:46 PM
  • Yes, they are clear text blobs inside binary files. Anybody can see and extract them. In many cases you can even open binary with, say, notepad and read the XML.

    Besides, all binary files should be signed - which means they are never to be changed even it that's possible (and it's not on NETCF) since that would break digital signature.

    Keep your list in separate file. Configuration file come to mind first.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by warrentang Monday, July 13, 2009 7:38 AM
    Sunday, July 12, 2009 4:54 PM