none
Paths With windows mobile 6 and device emulator RRS feed

  • Question

  •  

    Hello All -

     

    I am trying to load 2 small external JPG files into a windows mobile application.  What is the proper way to reference the path so that I will be able to load the JPG in the emulator, and it will still work when I deploy it to an actual device. 

     

    The JPGs reside in the folder with the executable

     

    Thanks -

    Mike  

    Tuesday, August 12, 2008 4:15 PM

Answers

  • Hi Mike

     

    Since Windows Mobile does not support relative path, you need to get the path to the application folder yourself like this:

    string appFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) ;

     

    After that you can combine it with the relative path of the jpg file as follows:

    string path =Path.Combine(appFolder,"xyz.jpg");

     

    This way you get the absolute path to the jpg file regardless of on emulator or on device.

     

    Regards

    Chunsheng Tang

     

    Thursday, August 14, 2008 2:15 AM
    Moderator

All replies

  • Hi Mike

     

    Since Windows Mobile does not support relative path, you need to get the path to the application folder yourself like this:

    string appFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) ;

     

    After that you can combine it with the relative path of the jpg file as follows:

    string path =Path.Combine(appFolder,"xyz.jpg");

     

    This way you get the absolute path to the jpg file regardless of on emulator or on device.

     

    Regards

    Chunsheng Tang

     

    Thursday, August 14, 2008 2:15 AM
    Moderator
  • I don't suppose you have a C++ way of doing that ?
    Friday, June 20, 2014 12:29 PM
  • Oh wait this should work:

    CString CUtils::AppPath(HMODULE hMod)
    {
    	TCHAR szModulePath[MAX_PATH];
    
    	::GetModuleFileName(hMod, szModulePath, MAX_PATH);
    
    	// chop off the backslash and everything after it
    	TCHAR* pChar = _tcsrchr(szModulePath, _T('\\'));
    	*pChar = NULL;
    
    	// return the results
    	return CString(szModulePath);
    }
    And then with this string you can prepend it to the filename in your application's directory.
    Friday, June 20, 2014 12:42 PM