specifying path names on mobile devices

hey there....
I am using visual studio to create a program that reads and writes from an xml file "books.xml". Everything deploys ok to my ppc but I'm having trouble specifying the path name of the xml file.

does anybody happen to know...

- How can I specify an absolute path on windows mobile 5 ( "c:/books.xml" doesn't allow me to find the file).

- Where should I put an xml file when using a relative path referring to("books.xml"); and placing the
file in the deployed application directory on my ppc returns an error that it can't find the file either.

any help is would be greatly appreciated....
cheers. camm.




Answer this question

specifying path names on mobile devices

  • sandipan

    Application directory most likely wouldn't be your current directory. It should be easy to find current directory experimentally.

    Your question is not specific to XML. Try to find forum related to Win Mobile.



  • Gerry Aue

    hey there....

    I am using visual studio to create a program that reads and writes from an xml file "books.xml". Everything deploys

    ok to my ppc but I'm having trouble specifying the path name of the xml file.

    does anybody happen to know...

    - How can I specify an absolute path on windows mobile 5 ( "c:/books.xml" doesn't allow me to find the file.)

    - Where should I put an xml file when using a relative path referring to("books.xml"); and placing the

    file in the deployed application directory on my ppc returns an error that it can't find the file either.

    any help is would be greatly appreciated....

    cheers. camm.



  • xxd

    im sure I replied to this topic before and moved it to the correct forum:

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=669893&SiteID=1

    please do not create duplicate topics.

    Thanks



  • George2

    thread moved to the appropriate forum.

    Well mobile devies dont have things like drive letters as on computers/PC's.

    to specify the root path, its just a single backslash:

    \

    think of that as a "C:\" letter

    if you wanted to specify some other path, like the program files folder:

    \Program files

    in .NET CF 2.0 (and .NET 2.0), you have the Environment.GetFolderPath() class/method, which allows you to select from it's enum's/collection the appropriate folder path you want to get back - for example if you wanted to get the documents directory:

     

    Environment.GetFolderPath(Environment.SpecialFolder.Personal)

    would return you generally the folder path (in a string format) to the my documents folder on the device.

    it depends where you wish to place the file, usually in the same directory as the application, so if the file is in the same directory as the application and you specify "books.xml" it should find it but remember, for better design, you should include things like checking to see if the file/directory exists without just going ahead and opening the file otherwise you will get exceptions thrown, as you probably are. It's just better overall design.

    Hope this helps!



  • ratjetoes

    Absolute paths for your windows mobile devices will start with just a \ character. For example \program files\my program.

    You can't directly give a relative path to open a file because windows mobile does not have a 'current directory' to base that relative path off of. Assuming your file will be in some known location relative to your executable you can get the codebase of the currently executing assembly and then derive the absolute path to your data file from that.

    If your file was "books.xml" and it was in the same directory as the executable this snippet would determine the absolute path for you.

    static void Main(string[] args)
    {
    Uri exePath = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase);
    MessageBox.Show("Executable is at: " + exePath.LocalPath);

    string exeDirectory = Path.GetDirectoryName(exePath.LocalPath);
    MessageBox.Show("Executable directory is: " + exeDirectory);

    string pathToBooks = Path.Combine(exeDirectory, "books.xml");
    MessageBox.Show("Path to books is: " + pathToBooks);
    }

    Hope this helps,
    -Noah Falk
    .Net Compact Framework

  • specifying path names on mobile devices