Application path

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

    Application path

    Hi,

    I have an application in which I need information of the path to the exe
    file. The application must run on both compact and full framework and on the
    Internet I found this code snip that should work (on the CF at least):
    "Path.GetDirect oryName(Assembl y.GetExecutingA ssembly().GetNa me().CodeBase)"

    It works very fine on Compact Framework where I get:
    "\Program Files\My Company"

    But on the full framework a "file:" and a backslash is applied in front of
    the resulting path as in:
    "file:\C:\Progr am files\My Company"

    What is wrong and how is the correct way to do it( that will work on both CF
    and FF ?

    Thanks,
    Ole


  • Marcin Grzêbski

    #2
    Re: Application path

    Hi Ole,

    I haven't got any practise with CompactFramewor k.
    But if you want to get path of executing binary then you can use:
    Application.Exe cutablePath
    or
    Application.Sta rtupPath - to get its directory

    HTH
    Marcin
    [color=blue]
    > Hi,
    >
    > I have an application in which I need information of the path to the exe
    > file. The application must run on both compact and full framework and on the
    > Internet I found this code snip that should work (on the CF at least):
    > "Path.GetDirect oryName(Assembl y.GetExecutingA ssembly().GetNa me().CodeBase)"
    >
    > It works very fine on Compact Framework where I get:
    > "\Program Files\My Company"
    >
    > But on the full framework a "file:" and a backslash is applied in front of
    > the resulting path as in:
    > "file:\C:\Progr am files\My Company"
    >
    > What is wrong and how is the correct way to do it( that will work on both CF
    > and FF ?
    >
    > Thanks,
    > Ole
    >
    >[/color]

    Comment

    • Sergey Bogdanov

      #3
      Re: Application path

      Also for a Full Framework you must use
      System.Reflecti on.Assembly.Get EntryAssembly() .Location. At runtime you
      can detect framework version (System.Environ ment.Version) and switch
      between them.

      Best regards,
      Sergey Bogdanov

      ORC wrote:[color=blue]
      > Hi,
      >
      > I have an application in which I need information of the path to the exe
      > file. The application must run on both compact and full framework and on the
      > Internet I found this code snip that should work (on the CF at least):
      > "Path.GetDirect oryName(Assembl y.GetExecutingA ssembly().GetNa me().CodeBase)"
      >
      > It works very fine on Compact Framework where I get:
      > "\Program Files\My Company"
      >
      > But on the full framework a "file:" and a backslash is applied in front of
      > the resulting path as in:
      > "file:\C:\Progr am files\My Company"
      >
      > What is wrong and how is the correct way to do it( that will work on both CF
      > and FF ?
      >
      > Thanks,
      > Ole
      >
      >[/color]

      Comment

      • ORC

        #4
        Re: Application path

        It is not possible to check OS version during runtime and then use the
        appropiate path detect code line because the compiler doesn't have a
        definition for GetEntryAssembl y in CF. Some other idea?

        Thanks,
        Ole


        "Sergey Bogdanov" <sergey.bogdano v@gmail.com> wrote in message
        news:%23LIPce99 EHA.3236@TK2MSF TNGP15.phx.gbl. ..[color=blue]
        > Also for a Full Framework you must use
        > System.Reflecti on.Assembly.Get EntryAssembly() .Location. At runtime you
        > can detect framework version (System.Environ ment.Version) and switch
        > between them.
        >
        > Best regards,
        > Sergey Bogdanov
        >
        > ORC wrote:[color=green]
        > > Hi,
        > >
        > > I have an application in which I need information of the path to the exe
        > > file. The application must run on both compact and full framework and on[/color][/color]
        the[color=blue][color=green]
        > > Internet I found this code snip that should work (on the CF at least):
        > >[/color][/color]
        "Path.GetDirect oryName(Assembl y.GetExecutingA ssembly().GetNa me().CodeBase)"[color=blue][color=green]
        > >
        > > It works very fine on Compact Framework where I get:
        > > "\Program Files\My Company"
        > >
        > > But on the full framework a "file:" and a backslash is applied in front[/color][/color]
        of[color=blue][color=green]
        > > the resulting path as in:
        > > "file:\C:\Progr am files\My Company"
        > >
        > > What is wrong and how is the correct way to do it( that will work on[/color][/color]
        both CF[color=blue][color=green]
        > > and FF ?
        > >
        > > Thanks,
        > > Ole
        > >
        > >[/color][/color]


        Comment

        • ORC

          #5
          Re: Application path

          The CF doesn't contain a definition for ExecuteablePath or StartupPath so
          the program wont compile.

          Thanks
          Ole

          "Marcin Grzêbski" <mgrzebski@taxu ssi.no.com.spam .pl> wrote in message
          news:cs0fs3$kpm $1@atlantis.new s.tpi.pl...[color=blue]
          > Hi Ole,
          >
          > I haven't got any practise with CompactFramewor k.
          > But if you want to get path of executing binary then you can use:
          > Application.Exe cutablePath
          > or
          > Application.Sta rtupPath - to get its directory
          >
          > HTH
          > Marcin
          >[color=green]
          > > Hi,
          > >
          > > I have an application in which I need information of the path to the exe
          > > file. The application must run on both compact and full framework and on[/color][/color]
          the[color=blue][color=green]
          > > Internet I found this code snip that should work (on the CF at least):
          > >[/color][/color]
          "Path.GetDirect oryName(Assembl y.GetExecutingA ssembly().GetNa me().CodeBase)"[color=blue][color=green]
          > >
          > > It works very fine on Compact Framework where I get:
          > > "\Program Files\My Company"
          > >
          > > But on the full framework a "file:" and a backslash is applied in front[/color][/color]
          of[color=blue][color=green]
          > > the resulting path as in:
          > > "file:\C:\Progr am files\My Company"
          > >
          > > What is wrong and how is the correct way to do it( that will work on[/color][/color]
          both CF[color=blue][color=green]
          > > and FF ?
          > >
          > > Thanks,
          > > Ole
          > >
          > >[/color][/color]


          Comment

          • Guest's Avatar

            #6
            Re: Application path

            So System.Environm ent.OSVersion won't work for you?

            -Chris


            "ORC" <orc@sol.dk> wrote in message
            news:u8ob9199EH A.3120@TK2MSFTN GP12.phx.gbl...[color=blue]
            > It is not possible to check OS version during runtime and then use the
            > appropiate path detect code line because the compiler doesn't have a
            > definition for GetEntryAssembl y in CF. Some other idea?
            >
            > Thanks,
            > Ole
            >
            >
            > "Sergey Bogdanov" <sergey.bogdano v@gmail.com> wrote in message
            > news:%23LIPce99 EHA.3236@TK2MSF TNGP15.phx.gbl. ..[color=green]
            >> Also for a Full Framework you must use
            >> System.Reflecti on.Assembly.Get EntryAssembly() .Location. At runtime you
            >> can detect framework version (System.Environ ment.Version) and switch
            >> between them.
            >>
            >> Best regards,
            >> Sergey Bogdanov
            >>
            >> ORC wrote:[color=darkred]
            >> > Hi,
            >> >
            >> > I have an application in which I need information of the path to the
            >> > exe
            >> > file. The application must run on both compact and full framework and
            >> > on[/color][/color]
            > the[color=green][color=darkred]
            >> > Internet I found this code snip that should work (on the CF at least):
            >> >[/color][/color]
            > "Path.GetDirect oryName(Assembl y.GetExecutingA ssembly().GetNa me().CodeBase)"[color=green][color=darkred]
            >> >
            >> > It works very fine on Compact Framework where I get:
            >> > "\Program Files\My Company"
            >> >
            >> > But on the full framework a "file:" and a backslash is applied in front[/color][/color]
            > of[color=green][color=darkred]
            >> > the resulting path as in:
            >> > "file:\C:\Progr am files\My Company"
            >> >
            >> > What is wrong and how is the correct way to do it( that will work on[/color][/color]
            > both CF[color=green][color=darkred]
            >> > and FF ?
            >> >
            >> > Thanks,
            >> > Ole
            >> >
            >> >[/color][/color]
            >
            >[/color]


            Comment

            • Sergey Bogdanov

              #7
              Re: Application path

              Sorry, my mistake. Try to use P/Invoke GetModuleFileNa me (coredll.dll)
              and GetModuleFileNa me (kernel32.dll).

              Best regards,
              Sergey Bogdanov


              ORC wrote:[color=blue]
              > It is not possible to check OS version during runtime and then use the
              > appropiate path detect code line because the compiler doesn't have a
              > definition for GetEntryAssembl y in CF. Some other idea?
              >
              > Thanks,
              > Ole
              >
              >
              > "Sergey Bogdanov" <sergey.bogdano v@gmail.com> wrote in message
              > news:%23LIPce99 EHA.3236@TK2MSF TNGP15.phx.gbl. ..
              >[color=green]
              >>Also for a Full Framework you must use
              >>System.Reflec tion.Assembly.G etEntryAssembly ().Location. At runtime you
              >>can detect framework version (System.Environ ment.Version) and switch
              >>between them.
              >>
              >>Best regards,
              >>Sergey Bogdanov
              >>
              >>ORC wrote:
              >>[color=darkred]
              >>>Hi,
              >>>
              >>>I have an application in which I need information of the path to the exe
              >>>file. The application must run on both compact and full framework and on[/color][/color]
              >
              > the
              >[color=green][color=darkred]
              >>>Internet I found this code snip that should work (on the CF at least):
              >>>[/color][/color]
              >
              > "Path.GetDirect oryName(Assembl y.GetExecutingA ssembly().GetNa me().CodeBase)"
              >[color=green][color=darkred]
              >>>It works very fine on Compact Framework where I get:
              >>>"\Program Files\My Company"
              >>>
              >>>But on the full framework a "file:" and a backslash is applied in front[/color][/color]
              >
              > of
              >[color=green][color=darkred]
              >>>the resulting path as in:
              >>>"file:\C:\Pr ogram files\My Company"
              >>>
              >>>What is wrong and how is the correct way to do it( that will work on[/color][/color]
              >
              > both CF
              >[color=green][color=darkred]
              >>>and FF ?
              >>>
              >>>Thanks,
              >>>Ole
              >>>
              >>>[/color][/color]
              >
              >
              >[/color]

              Comment

              • Peter Foot [MVP]

                #8
                Re: Application path

                On the Compact Framework you could use this alternative to
                GetEntryAssembl y:-


                If you merely want the same result from
                Path.GetDirecto ryName(Assembly .GetExecutingAs sembly().GetNam e().CodeBase on
                both frameworks then use:-

                string path =
                Path.GetDirecto ryName(Assembly .GetExecutingAs sembly().GetNam e().CodeBase);
                if(Environment. OsVersion.Platf orm!=PlatformID .WinCE)
                {
                path = path.Replace("f ile:\\","");
                }

                This will remove the prefix only on the desktop OS. Although you could call
                this replace on the device also since the path won't contain this string so
                no change will take place.

                Peter

                --
                Peter Foot
                Windows Embedded MVP
                www.inthehand.com | www.opennetcf.org

                "ORC" <orc@sol.dk> wrote in message
                news:u8ob9199EH A.3120@TK2MSFTN GP12.phx.gbl...[color=blue]
                > It is not possible to check OS version during runtime and then use the
                > appropiate path detect code line because the compiler doesn't have a
                > definition for GetEntryAssembl y in CF. Some other idea?
                >
                > Thanks,
                > Ole
                >
                >
                > "Sergey Bogdanov" <sergey.bogdano v@gmail.com> wrote in message
                > news:%23LIPce99 EHA.3236@TK2MSF TNGP15.phx.gbl. ..[color=green]
                >> Also for a Full Framework you must use
                >> System.Reflecti on.Assembly.Get EntryAssembly() .Location. At runtime you
                >> can detect framework version (System.Environ ment.Version) and switch
                >> between them.
                >>
                >> Best regards,
                >> Sergey Bogdanov
                >>
                >> ORC wrote:[color=darkred]
                >> > Hi,
                >> >
                >> > I have an application in which I need information of the path to the
                >> > exe
                >> > file. The application must run on both compact and full framework and
                >> > on[/color][/color]
                > the[color=green][color=darkred]
                >> > Internet I found this code snip that should work (on the CF at least):
                >> >[/color][/color]
                > "Path.GetDirect oryName(Assembl y.GetExecutingA ssembly().GetNa me().CodeBase)"[color=green][color=darkred]
                >> >
                >> > It works very fine on Compact Framework where I get:
                >> > "\Program Files\My Company"
                >> >
                >> > But on the full framework a "file:" and a backslash is applied in front[/color][/color]
                > of[color=green][color=darkred]
                >> > the resulting path as in:
                >> > "file:\C:\Progr am files\My Company"
                >> >
                >> > What is wrong and how is the correct way to do it( that will work on[/color][/color]
                > both CF[color=green][color=darkred]
                >> > and FF ?
                >> >
                >> > Thanks,
                >> > Ole
                >> >
                >> >[/color][/color]
                >
                >[/color]


                Comment

                • Sergey Bogdanov

                  #9
                  Re: Application path

                  .... even better solution :)

                  string codeBase = Assembly.GetExe cutingAssembly( ).GetName().Cod eBase;
                  if (codeBase.Start sWith(@"file:\" )) codeBase = codeBase.Substr ing(6);


                  Best regards,
                  Sergey Bogdanov


                  Sergey Bogdanov wrote:[color=blue]
                  > Sorry, my mistake. Try to use P/Invoke GetModuleFileNa me (coredll.dll)
                  > and GetModuleFileNa me (kernel32.dll).
                  >
                  > Best regards,
                  > Sergey Bogdanov
                  >
                  >
                  > ORC wrote:
                  >[color=green]
                  >> It is not possible to check OS version during runtime and then use the
                  >> appropiate path detect code line because the compiler doesn't have a
                  >> definition for GetEntryAssembl y in CF. Some other idea?
                  >>
                  >> Thanks,
                  >> Ole
                  >>
                  >>
                  >> "Sergey Bogdanov" <sergey.bogdano v@gmail.com> wrote in message
                  >> news:%23LIPce99 EHA.3236@TK2MSF TNGP15.phx.gbl. ..
                  >>[color=darkred]
                  >>> Also for a Full Framework you must use
                  >>> System.Reflecti on.Assembly.Get EntryAssembly() .Location. At runtime you
                  >>> can detect framework version (System.Environ ment.Version) and switch
                  >>> between them.
                  >>>
                  >>> Best regards,
                  >>> Sergey Bogdanov
                  >>>
                  >>> ORC wrote:
                  >>>
                  >>>> Hi,
                  >>>>
                  >>>> I have an application in which I need information of the path to the
                  >>>> exe
                  >>>> file. The application must run on both compact and full framework
                  >>>> and on[/color]
                  >>
                  >>
                  >> the
                  >>[color=darkred]
                  >>>> Internet I found this code snip that should work (on the CF at least):
                  >>>>[/color]
                  >>
                  >> "Path.GetDirect oryName(Assembl y.GetExecutingA ssembly().GetNa me().CodeBase)"
                  >>
                  >>[color=darkred]
                  >>>> It works very fine on Compact Framework where I get:
                  >>>> "\Program Files\My Company"
                  >>>>
                  >>>> But on the full framework a "file:" and a backslash is applied in front[/color]
                  >>
                  >>
                  >> of
                  >>[color=darkred]
                  >>>> the resulting path as in:
                  >>>> "file:\C:\Progr am files\My Company"
                  >>>>
                  >>>> What is wrong and how is the correct way to do it( that will work on[/color]
                  >>
                  >>
                  >> both CF
                  >>[color=darkred]
                  >>>> and FF ?
                  >>>>
                  >>>> Thanks,
                  >>>> Ole
                  >>>>
                  >>>>[/color]
                  >>
                  >>
                  >>[/color][/color]

                  Comment

                  • ORC

                    #10
                    Re: Application path

                    Oh yes it does, but GetEntryAssembl y is not defined in CF and therefore the
                    app wont compile.

                    Thanks
                    Ole

                    "<ctacke/>" <ctacke_AT_Open NETCF_com> wrote in message
                    news:uk2A5799EH A.3472@TK2MSFTN GP14.phx.gbl...[color=blue]
                    > So System.Environm ent.OSVersion won't work for you?
                    >
                    > -Chris
                    >
                    >
                    > "ORC" <orc@sol.dk> wrote in message
                    > news:u8ob9199EH A.3120@TK2MSFTN GP12.phx.gbl...[color=green]
                    > > It is not possible to check OS version during runtime and then use the
                    > > appropiate path detect code line because the compiler doesn't have a
                    > > definition for GetEntryAssembl y in CF. Some other idea?
                    > >
                    > > Thanks,
                    > > Ole
                    > >
                    > >
                    > > "Sergey Bogdanov" <sergey.bogdano v@gmail.com> wrote in message
                    > > news:%23LIPce99 EHA.3236@TK2MSF TNGP15.phx.gbl. ..[color=darkred]
                    > >> Also for a Full Framework you must use
                    > >> System.Reflecti on.Assembly.Get EntryAssembly() .Location. At runtime you
                    > >> can detect framework version (System.Environ ment.Version) and switch
                    > >> between them.
                    > >>
                    > >> Best regards,
                    > >> Sergey Bogdanov
                    > >>
                    > >> ORC wrote:
                    > >> > Hi,
                    > >> >
                    > >> > I have an application in which I need information of the path to the
                    > >> > exe
                    > >> > file. The application must run on both compact and full framework and
                    > >> > on[/color]
                    > > the[color=darkred]
                    > >> > Internet I found this code snip that should work (on the CF at[/color][/color][/color]
                    least):[color=blue][color=green][color=darkred]
                    > >> >[/color]
                    > >[/color][/color]
                    "Path.GetDirect oryName(Assembl y.GetExecutingA ssembly().GetNa me().CodeBase)"[color=blue][color=green][color=darkred]
                    > >> >
                    > >> > It works very fine on Compact Framework where I get:
                    > >> > "\Program Files\My Company"
                    > >> >
                    > >> > But on the full framework a "file:" and a backslash is applied in[/color][/color][/color]
                    front[color=blue][color=green]
                    > > of[color=darkred]
                    > >> > the resulting path as in:
                    > >> > "file:\C:\Progr am files\My Company"
                    > >> >
                    > >> > What is wrong and how is the correct way to do it( that will work on[/color]
                    > > both CF[color=darkred]
                    > >> > and FF ?
                    > >> >
                    > >> > Thanks,
                    > >> > Ole
                    > >> >
                    > >> >[/color]
                    > >
                    > >[/color]
                    >
                    >[/color]


                    Comment

                    • ORC

                      #11
                      Re: Application path

                      Thanks All,

                      The solution with getting rid of the leading "file:\" seems to be the one
                      I'm looking for!

                      Thanks,
                      Ole

                      "Peter Foot [MVP]" <feedback@no-spam.inthehand. com> wrote in message
                      news:uszN1C%239 EHA.1264@TK2MSF TNGP12.phx.gbl. ..[color=blue]
                      > On the Compact Framework you could use this alternative to
                      > GetEntryAssembl y:-
                      >[/color]
                      http://blog.opennetcf.org/pfoot/Perm...d-3dc8e7525cc4[color=blue]
                      >
                      > If you merely want the same result from
                      > Path.GetDirecto ryName(Assembly .GetExecutingAs sembly().GetNam e().CodeBase[/color]
                      on[color=blue]
                      > both frameworks then use:-
                      >
                      > string path =
                      > Path.GetDirecto ryName(Assembly .GetExecutingAs sembly().GetNam e().CodeBase);
                      > if(Environment. OsVersion.Platf orm!=PlatformID .WinCE)
                      > {
                      > path = path.Replace("f ile:\\","");
                      > }
                      >
                      > This will remove the prefix only on the desktop OS. Although you could[/color]
                      call[color=blue]
                      > this replace on the device also since the path won't contain this string[/color]
                      so[color=blue]
                      > no change will take place.
                      >
                      > Peter
                      >
                      > --
                      > Peter Foot
                      > Windows Embedded MVP
                      > www.inthehand.com | www.opennetcf.org
                      >
                      > "ORC" <orc@sol.dk> wrote in message
                      > news:u8ob9199EH A.3120@TK2MSFTN GP12.phx.gbl...[color=green]
                      > > It is not possible to check OS version during runtime and then use the
                      > > appropiate path detect code line because the compiler doesn't have a
                      > > definition for GetEntryAssembl y in CF. Some other idea?
                      > >
                      > > Thanks,
                      > > Ole
                      > >
                      > >
                      > > "Sergey Bogdanov" <sergey.bogdano v@gmail.com> wrote in message
                      > > news:%23LIPce99 EHA.3236@TK2MSF TNGP15.phx.gbl. ..[color=darkred]
                      > >> Also for a Full Framework you must use
                      > >> System.Reflecti on.Assembly.Get EntryAssembly() .Location. At runtime you
                      > >> can detect framework version (System.Environ ment.Version) and switch
                      > >> between them.
                      > >>
                      > >> Best regards,
                      > >> Sergey Bogdanov
                      > >>
                      > >> ORC wrote:
                      > >> > Hi,
                      > >> >
                      > >> > I have an application in which I need information of the path to the
                      > >> > exe
                      > >> > file. The application must run on both compact and full framework and
                      > >> > on[/color]
                      > > the[color=darkred]
                      > >> > Internet I found this code snip that should work (on the CF at[/color][/color][/color]
                      least):[color=blue][color=green][color=darkred]
                      > >> >[/color]
                      > >[/color][/color]
                      "Path.GetDirect oryName(Assembl y.GetExecutingA ssembly().GetNa me().CodeBase)"[color=blue][color=green][color=darkred]
                      > >> >
                      > >> > It works very fine on Compact Framework where I get:
                      > >> > "\Program Files\My Company"
                      > >> >
                      > >> > But on the full framework a "file:" and a backslash is applied in[/color][/color][/color]
                      front[color=blue][color=green]
                      > > of[color=darkred]
                      > >> > the resulting path as in:
                      > >> > "file:\C:\Progr am files\My Company"
                      > >> >
                      > >> > What is wrong and how is the correct way to do it( that will work on[/color]
                      > > both CF[color=darkred]
                      > >> > and FF ?
                      > >> >
                      > >> > Thanks,
                      > >> > Ole
                      > >> >
                      > >> >[/color]
                      > >
                      > >[/color]
                      >
                      >[/color]


                      Comment

                      • Chris Tacke, eMVP

                        #12
                        Re: Application path

                        Also using GetCallingAssem bly may be better than GetExecutingAss embly. If
                        your code is in a library that is GAC installed, you'll get a path to the
                        GAC folder, not the app folder with GetExecutingAss embly

                        --
                        <ctacke/>

                        Your CF searches start and end here


                        "ORC" <orc@sol.dk> wrote in message
                        news:e0XUEJ%239 EHA.3368@TK2MSF TNGP10.phx.gbl. ..[color=blue]
                        > Thanks All,
                        >
                        > The solution with getting rid of the leading "file:\" seems to be the one
                        > I'm looking for!
                        >
                        > Thanks,
                        > Ole
                        >
                        > "Peter Foot [MVP]" <feedback@no-spam.inthehand. com> wrote in message
                        > news:uszN1C%239 EHA.1264@TK2MSF TNGP12.phx.gbl. ..[color=green]
                        >> On the Compact Framework you could use this alternative to
                        >> GetEntryAssembl y:-
                        >>[/color]
                        > http://blog.opennetcf.org/pfoot/Perm...d-3dc8e7525cc4[color=green]
                        >>
                        >> If you merely want the same result from
                        >> Path.GetDirecto ryName(Assembly .GetExecutingAs sembly().GetNam e().CodeBase[/color]
                        > on[color=green]
                        >> both frameworks then use:-
                        >>
                        >> string path =
                        >> Path.GetDirecto ryName(Assembly .GetExecutingAs sembly().GetNam e().CodeBase);
                        >> if(Environment. OsVersion.Platf orm!=PlatformID .WinCE)
                        >> {
                        >> path = path.Replace("f ile:\\","");
                        >> }
                        >>
                        >> This will remove the prefix only on the desktop OS. Although you could[/color]
                        > call[color=green]
                        >> this replace on the device also since the path won't contain this string[/color]
                        > so[color=green]
                        >> no change will take place.
                        >>
                        >> Peter
                        >>
                        >> --
                        >> Peter Foot
                        >> Windows Embedded MVP
                        >> www.inthehand.com | www.opennetcf.org
                        >>
                        >> "ORC" <orc@sol.dk> wrote in message
                        >> news:u8ob9199EH A.3120@TK2MSFTN GP12.phx.gbl...[color=darkred]
                        >> > It is not possible to check OS version during runtime and then use the
                        >> > appropiate path detect code line because the compiler doesn't have a
                        >> > definition for GetEntryAssembl y in CF. Some other idea?
                        >> >
                        >> > Thanks,
                        >> > Ole
                        >> >
                        >> >
                        >> > "Sergey Bogdanov" <sergey.bogdano v@gmail.com> wrote in message
                        >> > news:%23LIPce99 EHA.3236@TK2MSF TNGP15.phx.gbl. ..
                        >> >> Also for a Full Framework you must use
                        >> >> System.Reflecti on.Assembly.Get EntryAssembly() .Location. At runtime you
                        >> >> can detect framework version (System.Environ ment.Version) and switch
                        >> >> between them.
                        >> >>
                        >> >> Best regards,
                        >> >> Sergey Bogdanov
                        >> >>
                        >> >> ORC wrote:
                        >> >> > Hi,
                        >> >> >
                        >> >> > I have an application in which I need information of the path to the
                        >> >> > exe
                        >> >> > file. The application must run on both compact and full framework
                        >> >> > and
                        >> >> > on
                        >> > the
                        >> >> > Internet I found this code snip that should work (on the CF at[/color][/color]
                        > least):[color=green][color=darkred]
                        >> >> >
                        >> >[/color][/color]
                        > "Path.GetDirect oryName(Assembl y.GetExecutingA ssembly().GetNa me().CodeBase)"[color=green][color=darkred]
                        >> >> >
                        >> >> > It works very fine on Compact Framework where I get:
                        >> >> > "\Program Files\My Company"
                        >> >> >
                        >> >> > But on the full framework a "file:" and a backslash is applied in[/color][/color]
                        > front[color=green][color=darkred]
                        >> > of
                        >> >> > the resulting path as in:
                        >> >> > "file:\C:\Progr am files\My Company"
                        >> >> >
                        >> >> > What is wrong and how is the correct way to do it( that will work on
                        >> > both CF
                        >> >> > and FF ?
                        >> >> >
                        >> >> > Thanks,
                        >> >> > Ole
                        >> >> >
                        >> >> >
                        >> >
                        >> >[/color]
                        >>
                        >>[/color]
                        >
                        >[/color]


                        Comment

                        • Alex Feinman [MVP]

                          #13
                          Re: Application path

                          For the sake of integrity I need to point out that the correct way of
                          "getting rid of" file:// is to use the Uri class and its accessors

                          --
                          Alex Feinman
                          ---
                          Visit http://www.opennetcf.org
                          "ORC" <orc@sol.dk> wrote in message
                          news:e0XUEJ%239 EHA.3368@TK2MSF TNGP10.phx.gbl. ..[color=blue]
                          > Thanks All,
                          >
                          > The solution with getting rid of the leading "file:\" seems to be the one
                          > I'm looking for!
                          >
                          > Thanks,
                          > Ole
                          >
                          > "Peter Foot [MVP]" <feedback@no-spam.inthehand. com> wrote in message
                          > news:uszN1C%239 EHA.1264@TK2MSF TNGP12.phx.gbl. ..[color=green]
                          >> On the Compact Framework you could use this alternative to
                          >> GetEntryAssembl y:-
                          >>[/color]
                          > http://blog.opennetcf.org/pfoot/Perm...d-3dc8e7525cc4[color=green]
                          >>
                          >> If you merely want the same result from
                          >> Path.GetDirecto ryName(Assembly .GetExecutingAs sembly().GetNam e().CodeBase[/color]
                          > on[color=green]
                          >> both frameworks then use:-
                          >>
                          >> string path =
                          >> Path.GetDirecto ryName(Assembly .GetExecutingAs sembly().GetNam e().CodeBase);
                          >> if(Environment. OsVersion.Platf orm!=PlatformID .WinCE)
                          >> {
                          >> path = path.Replace("f ile:\\","");
                          >> }
                          >>
                          >> This will remove the prefix only on the desktop OS. Although you could[/color]
                          > call[color=green]
                          >> this replace on the device also since the path won't contain this string[/color]
                          > so[color=green]
                          >> no change will take place.
                          >>
                          >> Peter
                          >>
                          >> --
                          >> Peter Foot
                          >> Windows Embedded MVP
                          >> www.inthehand.com | www.opennetcf.org
                          >>
                          >> "ORC" <orc@sol.dk> wrote in message
                          >> news:u8ob9199EH A.3120@TK2MSFTN GP12.phx.gbl...[color=darkred]
                          >> > It is not possible to check OS version during runtime and then use the
                          >> > appropiate path detect code line because the compiler doesn't have a
                          >> > definition for GetEntryAssembl y in CF. Some other idea?
                          >> >
                          >> > Thanks,
                          >> > Ole
                          >> >
                          >> >
                          >> > "Sergey Bogdanov" <sergey.bogdano v@gmail.com> wrote in message
                          >> > news:%23LIPce99 EHA.3236@TK2MSF TNGP15.phx.gbl. ..
                          >> >> Also for a Full Framework you must use
                          >> >> System.Reflecti on.Assembly.Get EntryAssembly() .Location. At runtime you
                          >> >> can detect framework version (System.Environ ment.Version) and switch
                          >> >> between them.
                          >> >>
                          >> >> Best regards,
                          >> >> Sergey Bogdanov
                          >> >>
                          >> >> ORC wrote:
                          >> >> > Hi,
                          >> >> >
                          >> >> > I have an application in which I need information of the path to the
                          >> >> > exe
                          >> >> > file. The application must run on both compact and full framework
                          >> >> > and
                          >> >> > on
                          >> > the
                          >> >> > Internet I found this code snip that should work (on the CF at[/color][/color]
                          > least):[color=green][color=darkred]
                          >> >> >
                          >> >[/color][/color]
                          > "Path.GetDirect oryName(Assembl y.GetExecutingA ssembly().GetNa me().CodeBase)"[color=green][color=darkred]
                          >> >> >
                          >> >> > It works very fine on Compact Framework where I get:
                          >> >> > "\Program Files\My Company"
                          >> >> >
                          >> >> > But on the full framework a "file:" and a backslash is applied in[/color][/color]
                          > front[color=green][color=darkred]
                          >> > of
                          >> >> > the resulting path as in:
                          >> >> > "file:\C:\Progr am files\My Company"
                          >> >> >
                          >> >> > What is wrong and how is the correct way to do it( that will work on
                          >> > both CF
                          >> >> > and FF ?
                          >> >> >
                          >> >> > Thanks,
                          >> >> > Ole
                          >> >> >
                          >> >> >
                          >> >
                          >> >[/color]
                          >>
                          >>[/color]
                          >
                          >[/color]


                          Comment

                          Working...