14

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

nportelli
  • 3,934
  • 7
  • 37
  • 52

3 Answers3

19

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);
        }
    }
}
Kieron
  • 26,748
  • 16
  • 78
  • 122
7

Try this:

Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
Todd
  • 5,017
  • 1
  • 25
  • 16
-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