GetCurrentDirectory?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dan

    #1

    GetCurrentDirectory?

    I have built a C# Windows application using a C# library hosted in a DLL.
    Both the library and the application need to access some files which at
    program installation are placed in the EXE's path; thus, I use
    Directory.GetCu rrentDirectory( ) to initialize the default filenames so that
    they point to the EXE's path. This happens in the constructor of some
    objects (for the DLL) and in the OnLoad event of the EXE's form.

    All this works fine in the development workstation (with Visual Studio .NET
    and WinXP Pro), and the EXE's path (e.g. ...\MyExe\Bin\D ebug or the like) is
    retrieved correctly either by the objects in the DLL or in the EXE's OnLoad;
    but when I launch the program on a test machine with just Windows ME and
    dotnet framework runtime only, the path returned by GetCurrentDirec tory is
    just the root (C:\)! (I added a test
    MessageBox.Show (Directory.GetC urrentDirectory ()) instruction to the release
    build). Is this anything I'm doing wrong, or any problem with this OS, or
    what else?

    Thanks to all!


  • Wiktor Zychla

    #2
    Re: GetCurrentDirec tory?

    > Thanks to all!

    use Application.Exe cutablePath instead...


    Comment

    • Dan

      #3
      Re: GetCurrentDirec tory?

      Thanks, this works for the EXE... but I'd prefer to avoid referencing the
      Windows.Forms namespace for the classes hosted in an external library (a
      DLL), which do not belong to any particular application and are pure
      "engine" components without any specific user interface... any idea?

      "Wiktor Zychla" <ieUser@microso ft.com.no.spam> wrote in message
      news:ekrvRMgdDH A.736@TK2MSFTNG P09.phx.gbl...[color=blue][color=green]
      > > Thanks to all![/color]
      >
      > use Application.Exe cutablePath instead...
      >
      >[/color]


      Comment

      • Peter Huang [MSFT]

        #4
        Re: GetCurrentDirec tory?

        Hi Dan,

        I can not reproduce the problem.

        I think the Directory.GetCu rrentDirectory will
        get the current working directory of the application.
        http://msdn.microsoft.com/library/de...us/cpref/html/
        frlrfsystemiodi rectoryclassget currentdirector ytopic.asp

        while the Application.Exe cutablePath will
        get the path for the executable file that started the application,
        including the executable name.
        http://msdn.microsoft.com/library/de...us/cpref/html/
        frlrfsystemwind owsformsapplica tionclassexecut ablepathtopic.a sp


        e.g.
        the current directory is c:\
        the application is located in the e:\test\test.ex e
        c:\>e:\test\tes t.exe
        in this case the Directory.GetCu rrentDirectory will get c:\
        while the Application.Exe cutablePath
        will get e:\test\test.ex e


        Did I answer your question?




        Regards,
        Peter Huang
        Microsoft Online Partner Support
        Get Secure! www.microsoft.com/security
        This posting is provided "as is" with no warranties and confers no rights.
        --------------------[color=blue]
        >From: "Dan" <fusid@iol.it >
        >References: <#tMiTrfdDHA.18 28@TK2MSFTNGP11 .phx.gbl>[/color]
        <ekrvRMgdDHA.73 6@TK2MSFTNGP09. phx.gbl>[color=blue]
        >Subject: Re: GetCurrentDirec tory?
        >Date: Mon, 8 Sep 2003 17:24:22 +0200
        >Lines: 14
        >X-Priority: 3
        >X-MSMail-Priority: Normal
        >X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
        >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
        >Message-ID: <e7LBL1hdDHA.12 80@tk2msftngp13 .phx.gbl>
        >Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
        >NNTP-Posting-Host: ppp-217-133-157-157.cust-adsl.tiscali.it 217.133.157.157
        >Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
        >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1832 14
        >X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
        >
        >Thanks, this works for the EXE... but I'd prefer to avoid referencing the
        >Windows.Form s namespace for the classes hosted in an external library (a
        >DLL), which do not belong to any particular application and are pure
        >"engine" components without any specific user interface... any idea?
        >
        >"Wiktor Zychla" <ieUser@microso ft.com.no.spam> wrote in message
        >news:ekrvRMgdD HA.736@TK2MSFTN GP09.phx.gbl...[color=green][color=darkred]
        >> > Thanks to all![/color]
        >>
        >> use Application.Exe cutablePath instead...
        >>
        >>[/color]
        >
        >
        >[/color]

        Comment

        • Dan

          #5
          Re: GetCurrentDirec tory?

          Many thanks, the behaviour of the function now is clear... I can suppose
          that the different behaviour in the cited machines happens because VS is
          setting the working directory of the debugged application to its output
          path, so that this works when debugging or launching it from the IDE but not
          when launched from another machine (?). So I'll use something like
          Path.GetDirecto ryName(Applicat ion.ExecutableP ath) to get the directory of
          the EXE, but this does not apply to a class-library hosted in a DLL: how
          could I get the DLL full path in such case?

          "Peter Huang [MSFT]" <v-phuang@online.m icrosoft.com> wrote in message
          news:MPcbH1pdDH A.2000@cpmsftng xa06.phx.gbl...[color=blue]
          > Hi Dan,
          >
          > I can not reproduce the problem.
          >
          > I think the Directory.GetCu rrentDirectory will
          > get the current working directory of the application.
          >[/color]
          http://msdn.microsoft.com/library/de...us/cpref/html/[color=blue]
          > frlrfsystemiodi rectoryclassget currentdirector ytopic.asp
          >
          > while the Application.Exe cutablePath will
          > get the path for the executable file that started the application,
          > including the executable name.
          >[/color]
          http://msdn.microsoft.com/library/de...us/cpref/html/[color=blue]
          > frlrfsystemwind owsformsapplica tionclassexecut ablepathtopic.a sp
          >
          >
          > e.g.
          > the current directory is c:\
          > the application is located in the e:\test\test.ex e
          > c:\>e:\test\tes t.exe
          > in this case the Directory.GetCu rrentDirectory will get c:\
          > while the Application.Exe cutablePath
          > will get e:\test\test.ex e
          >
          >
          > Did I answer your question?
          >
          >
          >
          >
          > Regards,
          > Peter Huang
          > Microsoft Online Partner Support[/color]


          Comment

          • Peter Huang [MSFT]

            #6
            Re: GetCurrentDirec tory?

            Hi Dan,

            In the ClassLibrary, you may try the
            Assembly.GetExe cutingAssembly( ).Location which will return the path of the
            classlibrary.
            Did this answer your question?

            Regards,
            Peter Huang
            Microsoft Online Partner Support
            Get Secure! www.microsoft.com/security
            This posting is provided "as is" with no warranties and confers no rights.
            --------------------[color=blue]
            >From: "Dan" <fusid@iol.it >
            >References: <#tMiTrfdDHA.18 28@TK2MSFTNGP11 .phx.gbl>[/color]
            <ekrvRMgdDHA.73 6@TK2MSFTNGP09. phx.gbl>
            <e7LBL1hdDHA.12 80@tk2msftngp13 .phx.gbl>
            <MPcbH1pdDHA.20 00@cpmsftngxa06 .phx.gbl>[color=blue]
            >Subject: Re: GetCurrentDirec tory?
            >Date: Tue, 9 Sep 2003 09:21:58 +0200
            >Lines: 48
            >X-Priority: 3
            >X-MSMail-Priority: Normal
            >X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
            >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
            >Message-ID: <OPpaSMqdDHA.33 32@TK2MSFTNGP09 .phx.gbl>
            >Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
            >NNTP-Posting-Host: ppp-217-133-155-20.cust-adsl.tiscali.it 217.133.155.20
            >Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP09.phx.g bl
            >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1833 65
            >X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
            >
            >Many thanks, the behaviour of the function now is clear... I can suppose
            >that the different behaviour in the cited machines happens because VS is
            >setting the working directory of the debugged application to its output
            >path, so that this works when debugging or launching it from the IDE but[/color]
            not[color=blue]
            >when launched from another machine (?). So I'll use something like
            >Path.GetDirect oryName(Applica tion.Executable Path) to get the directory of
            >the EXE, but this does not apply to a class-library hosted in a DLL: how
            >could I get the DLL full path in such case?
            >
            >"Peter Huang [MSFT]" <v-phuang@online.m icrosoft.com> wrote in message
            >news:MPcbH1pdD HA.2000@cpmsftn gxa06.phx.gbl.. .[color=green]
            >> Hi Dan,
            >>
            >> I can not reproduce the problem.
            >>
            >> I think the Directory.GetCu rrentDirectory will
            >> get the current working directory of the application.
            >>[/color]
            >http://msdn.microsoft.com/library/de...-us/cpref/html[/color]
            /[color=blue][color=green]
            >> frlrfsystemiodi rectoryclassget currentdirector ytopic.asp
            >>
            >> while the Application.Exe cutablePath will
            >> get the path for the executable file that started the application,
            >> including the executable name.
            >>[/color]
            >http://msdn.microsoft.com/library/de...-us/cpref/html[/color]
            /[color=blue][color=green]
            >> frlrfsystemwind owsformsapplica tionclassexecut ablepathtopic.a sp
            >>
            >>
            >> e.g.
            >> the current directory is c:\
            >> the application is located in the e:\test\test.ex e
            >> c:\>e:\test\tes t.exe
            >> in this case the Directory.GetCu rrentDirectory will get c:\
            >> while the Application.Exe cutablePath
            >> will get e:\test\test.ex e
            >>
            >>
            >> Did I answer your question?
            >>
            >>
            >>
            >>
            >> Regards,
            >> Peter Huang
            >> Microsoft Online Partner Support[/color]
            >
            >
            >[/color]

            Comment

            • Dan

              #7
              Re: GetCurrentDirec tory?

              Thanks, that's what I was looking for... :-)

              "Peter Huang [MSFT]" <v-phuang@online.m icrosoft.com> wrote in message
              news:7iuCj%23sd DHA.460@cpmsftn gxa06.phx.gbl.. .[color=blue]
              > Hi Dan,
              >
              > In the ClassLibrary, you may try the
              > Assembly.GetExe cutingAssembly( ).Location which will return the path of the
              > classlibrary.
              > Did this answer your question?[/color]


              Comment

              • Peter Huang [MSFT]

                #8
                Re: GetCurrentDirec tory?

                Hi Dan,

                I am glad that I can help you.

                Regards,
                Peter Huang
                Microsoft Online Partner Support
                Get Secure! www.microsoft.com/security
                This posting is provided "as is" with no warranties and confers no rights.

                --------------------[color=blue]
                >From: "Dan" <fusid@iol.it >
                >References: <#tMiTrfdDHA.18 28@TK2MSFTNGP11 .phx.gbl>[/color]
                <ekrvRMgdDHA.73 6@TK2MSFTNGP09. phx.gbl>
                <e7LBL1hdDHA.12 80@tk2msftngp13 .phx.gbl>
                <MPcbH1pdDHA.20 00@cpmsftngxa06 .phx.gbl>
                <OPpaSMqdDHA.33 32@TK2MSFTNGP09 .phx.gbl>
                <7iuCj#sdDHA.46 0@cpmsftngxa06. phx.gbl>[color=blue]
                >Subject: Re: GetCurrentDirec tory?
                >Date: Tue, 9 Sep 2003 15:33:51 +0200
                >Lines: 12
                >X-Priority: 3
                >X-MSMail-Priority: Normal
                >X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
                >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
                >Message-ID: <ezQSIctdDHA.24 16@TK2MSFTNGP09 .phx.gbl>
                >Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
                >NNTP-Posting-Host: ppp-217-133-156-178.cust-adsl.tiscali.it 217.133.156.178
                >Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP09.phx.g bl
                >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1834 55
                >X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
                >
                >Thanks, that's what I was looking for... :-)
                >
                >"Peter Huang [MSFT]" <v-phuang@online.m icrosoft.com> wrote in message
                >news:7iuCj%23s dDHA.460@cpmsft ngxa06.phx.gbl. ..[color=green]
                >> Hi Dan,
                >>
                >> In the ClassLibrary, you may try the
                >> Assembly.GetExe cutingAssembly( ).Location which will return the path of[/color][/color]
                the[color=blue][color=green]
                >> classlibrary.
                >> Did this answer your question?[/color]
                >
                >
                >[/color]

                Comment

                Working...