Compartilhar via


How to: Get the Application Directory

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Because there is no inherent current directory setting in Pocket PC applications, specifying a file name in your code with no path specification returns a FileNotFoundException. Pocket PC applications store data files with your assembly files under \Program Files\myAssembly\, where myAssembly is the name of your assembly.

Example

This example shows how to determine the path of the currently running application by getting the fully qualified directory name of the executing assembly and appending it with the application file name. Note that if the application is running in the root directory of the device, the returned path information is an empty string.

Dim strAppDir As String = Path.GetDirectoryName( _
    Assembly.GetExecutingAssembly().GetName().CodeBase)
Dim strFullPathToMyFile As String = Path.Combine(strAppDir, "myFileName.txt")

MessageBox.Show(String.Format("Path to the application is: '{0}'." + _
    "Full path to the file in the application folder is: '{1}'", _
    strAppDir, strFullPathToMyFile))
        String strAppDir = Path.GetDirectoryName(
            Assembly.GetExecutingAssembly().GetName().CodeBase);
        String strFullPathToMyFile = Path.Combine(strAppDir, "fileName.txt");

        MessageBox.Show(String.Format("Path to the application is: '{0}'." +
            "Full path to the file in the application folder is: '{1}'",
            strAppDir, strFullPathToMyFile));
                                                                                                                                

Compiling the Code

This example requires references to the following namespaces:

See Also

Other Resources

Pocket PC Development and the .NET Compact Framework

Building Applications and Core Tasks in the .NET Compact Framework