如何在紧凑框架中获取当前目录?

时间:2022-01-25 07:23:15

How do you get the current directory where your app is running?

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

3 个解决方案

#1


17  

You could try this:

你可以试试这个:

using System.IO;
using System.Reflection;

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

#2


6  

Try this:

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

#3


-1  

Public Shared Sub WriteDBStatus(ByVal strString As String)

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

#1


17  

You could try this:

你可以试试这个:

using System.IO;
using System.Reflection;

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

#2


6  

Try this:

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

#3


-1  

Public Shared Sub WriteDBStatus(ByVal strString As String)

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