Opening XML File on Pocket PC

I'm trying to load an xml file in Pocket PC, but its giving me DirectoryNotFoundException.
I know why the exception is occuring becaue Pocket PC file structure is not like the local Drive system we have in windows.

I'm trying to do the following to resolve the exception but it still does not works:

String path = Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "\\MyPocketCal2003\\QuantitiesUnits.xml";


String path = Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "\\MyPocketCal2003\\MyPocketCal2003\\QuantitiesUnits.xml";

Please suggest a solution.


Answer this question

Opening XML File on Pocket PC

  • Marcos B

    You absolutely can. In fact that is the common way to solve the issue f hard coded paths. There’s even “how to” article on MSDN about it.



  • Joannes Vermorel - MSP

    If you can't find file with explorer, then it does not exists and there's absolutely no way you can avoid getting FileNotFoundException.

    You need to set deploy condition to anything but never. It's in the same properties group as “Build Action”. I believe it's called "Copy to Output Directory". Set it to "Copy Always".

    You can also copy this file manually via AS or mapped storage folder (in emulator properties).

    Keep in mind you would need to take care of this file when you done and need to do actual deployment without VS.



  • JFoushee

    I couldn't find the file in the File Explorer, may be I was looking wrong but the file is part of the project then why should be in the File Explorer.

    I changed the action to "content" but still I get FileNotFoundException.

    The file does exists because I've changed the path to the windows desktop path & run the .exe file directly from debug folder & it works fine. The problem occurs when I run the emulator. And use the path of Program File as I told earlier.

    How to you set the deploy condition to "never". I'm using VS 2005 Pro. Edition

  • KavyaKonda

    Please use file explorer on device to make sure file actually exists. If not, you need to copy it to device.

    If it’s added to your project, please make sure action is set to “Content” and deploy condition is not set to “Never”.



  • sandeep437

    Sorry man, the forum was giving me an error when actually it was posting at the back.

  • Jan Meeusen

    I couldn't find the file in the File Explorer, may be I was looking wrong but the file is part of the project then why should be in the File Explorer.

    I changed the action to "content" but still I get FileNotFoundException.

    The file does exists because I've changed the path to the windows desktop path & run the .exe file directly from debug folder & it works fine. The problem occurs when I run the emulator. And use the path of Program File as I told earlier.

    How to you set the deploy condition to "never". I'm using VS 2005 Pro. Edition

  • Giorgio Sardo

    I was hitting the same error ... I tried everything mentioned in the thread. In my case, I also SEE the XML file I am trying to open in the File Explorer, yet the application EXE, present in the same folder, returns a FileNotFoundException for the following called

    FileStream fooConfigFileStream = new FileStream("Foo.config.xml", FileMode.Open);

    An unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll

    Additional information: Could not find file '\Foo.config.xml'.

    The same code compiling on .NET for Windows Desktop works just fine ..

  • SXMdev

    Note it complains about “\Foo.Config.xml” which means it's looking for a file in a root folder. Is your file in the root folder I would guess it’s not. So you have to specify full path as devices do not support relative paths like desktop does.



  • James Cornell

    I couldn't see the file in the file explorer. The file is added in my Project already & I set the Action to "Content" but still FillNotFoundException.

    Well the file exist, it works perfectly find when I change the path to a normal windows desktop path & go to the debug folder & run the .exe but when I deploy it on the emulator the path changes and I'm trying to get that changed path.

    I don't know how to set deploy condition to "Never".
    I also don't know how to copy the file to the emulator but why should I need to do that when the file is part of the project.

  • abuck

    Keep in mind Environment.GetFolderPath() does not work for all IDs on all platforms, it will return empty string if path is unavailable. I would suggest printing out resulting path and using file explorer to make sure it exists.

    This way may work better:

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/dncfhowto/html/HOWTOExecutingAppPath.asp



  • TrueDanimal

    i executed the following code on my Pocket PC to know the path of the executable.

    string path;
    path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
    MessageBox.Show(path);

    the path returned was \Program Files\MyPocketCal2003

    and then I gave the following path for my xml file \Program Files\MyPocketCal2003\QuantitiesUnits.xml & run the emulator but it still gave me FillNotFoundException.

  • Greg D Clark

    I couldn't find the file in the File Explorer, may be I was looking wrong but the file is part of the project then why should be in the File Explorer.

    I changed the action to "content" but still I get FileNotFoundException.

    The file does exists because I've changed the path to the windows desktop path & run the .exe file directly from debug folder & it works fine. The problem occurs when I run the emulator. And use the path of Program File as I told earlier.

    How to you set the deploy condition to "never". I'm using VS 2005 Pro. Edition

  • aashta

    Yep that was the problem (that devices do not support relative paths) ...

    Kind of an orthogonal followup question, but let's assume our EXE and XML are always in the same folder ... can we use reflection to always get the current folder in which the EXE is running, so that we can prepend that to the XML file before trying to open it (This way we don't have to harcode any specific path names in the EXE itself)


  • Opening XML File on Pocket PC