你如何获得紧凑框架中的当前目录?

时间:2008-11-12 14:14:19

标签: windows-mobile compact-framework

如何获取运行应用程序的当前目录?

3 个答案:

答案 0 :(得分:17)

你可以试试这个:

using System.IO;
using System.Reflection;

namespace Utilities
{
    static public class DirectoryHelper
    {
        static public string GetCurrentDirectory ()
        {
            return Path.GetDirectoryName (Assembly.GetExecutingAssembly ().GetName ().CodeBase);
        }
    }
}

答案 1 :(得分:6)

试试这个:

Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);

答案 2 :(得分:-1)

Public Shared Sub WriteDBStatus(ByVal strString As String)

    Try

        Dim FILE_NAME As String = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + "\DBStatus"

        Dim sr As IO.StreamWriter = Nothing
        If Not IO.File.Exists(FILE_NAME) Then
            sr = IO.File.CreateText(FILE_NAME)
            sr.WriteLine(strString)
        End If
        sr.Close()
    Catch ex As Exception

    End Try


End Sub