473,326 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Application path

ORC
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.GetDirectoryName(Assembly.GetExecutingAssemb ly().GetName().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:\Program 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
Nov 16 '05 #1
12 5408
Hi Ole,

I haven't got any practise with CompactFramework.
But if you want to get path of executing binary then you can use:
Application.ExecutablePath
or
Application.StartupPath - to get its directory

HTH
Marcin
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.GetDirectoryName(Assembly.GetExecutingAssemb ly().GetName().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:\Program 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

Nov 16 '05 #2
Also for a Full Framework you must use
System.Reflection.Assembly.GetEntryAssembly().Loca tion. At runtime you
can detect framework version (System.Environment.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 least):
"Path.GetDirectoryName(Assembly.GetExecutingAssemb ly().GetName().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:\Program 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

Nov 16 '05 #3
ORC
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 GetEntryAssembly in CF. Some other idea?

Thanks,
Ole
"Sergey Bogdanov" <se*************@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Also for a Full Framework you must use
System.Reflection.Assembly.GetEntryAssembly().Loca tion. At runtime you
can detect framework version (System.Environment.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 least):
"Path.GetDirectoryName(Assembly.GetExecutingAssemb ly().GetName().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:\Program 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

Nov 16 '05 #4
ORC
The CF doesn't contain a definition for ExecuteablePath or StartupPath so
the program wont compile.

Thanks
Ole

"Marcin Grzêbski" <mg*******@taxussi.no.com.spam.pl> wrote in message
news:cs**********@atlantis.news.tpi.pl...
Hi Ole,

I haven't got any practise with CompactFramework.
But if you want to get path of executing binary then you can use:
Application.ExecutablePath
or
Application.StartupPath - to get its directory

HTH
Marcin
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.GetDirectoryName(Assembly.GetExecutingAssemb ly().GetName().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:\Program 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

Nov 16 '05 #5
So System.Environment.OSVersion won't work for you?

-Chris
"ORC" <or*@sol.dk> wrote in message
news:u8**************@TK2MSFTNGP12.phx.gbl...
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 GetEntryAssembly in CF. Some other idea?

Thanks,
Ole
"Sergey Bogdanov" <se*************@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Also for a Full Framework you must use
System.Reflection.Assembly.GetEntryAssembly().Loca tion. At runtime you
can detect framework version (System.Environment.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 least):
> "Path.GetDirectoryName(Assembly.GetExecutingAssemb ly().GetName().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:\Program 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
>
>


Nov 16 '05 #6
Sorry, my mistake. Try to use P/Invoke GetModuleFileName (coredll.dll)
and GetModuleFileName (kernel32.dll).

Best regards,
Sergey Bogdanov
ORC wrote:
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 GetEntryAssembly in CF. Some other idea?

Thanks,
Ole
"Sergey Bogdanov" <se*************@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Also for a Full Framework you must use
System.Reflection.Assembly.GetEntryAssembly().Lo cation. At runtime you
can detect framework version (System.Environment.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 least):

"Path.GetDirectoryName(Assembly.GetExecutingAssemb ly().GetName().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:\Program 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


Nov 16 '05 #7
On the Compact Framework you could use this alternative to
GetEntryAssembly:-
http://blog.opennetcf.org/pfoot/Perm...d-3dc8e7525cc4

If you merely want the same result from
Path.GetDirectoryName(Assembly.GetExecutingAssembl y().GetName().CodeBase on
both frameworks then use:-

string path =
Path.GetDirectoryName(Assembly.GetExecutingAssembl y().GetName().CodeBase);
if(Environment.OsVersion.Platform!=PlatformID.WinC E)
{
path = path.Replace("file:\\","");
}

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" <or*@sol.dk> wrote in message
news:u8**************@TK2MSFTNGP12.phx.gbl...
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 GetEntryAssembly in CF. Some other idea?

Thanks,
Ole
"Sergey Bogdanov" <se*************@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Also for a Full Framework you must use
System.Reflection.Assembly.GetEntryAssembly().Loca tion. At runtime you
can detect framework version (System.Environment.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 least):
> "Path.GetDirectoryName(Assembly.GetExecutingAssemb ly().GetName().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:\Program 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
>
>


Nov 16 '05 #8
.... even better solution :)

string codeBase = Assembly.GetExecutingAssembly().GetName().CodeBase ;
if (codeBase.StartsWith(@"file:\")) codeBase = codeBase.Substring(6);
Best regards,
Sergey Bogdanov
Sergey Bogdanov wrote:
Sorry, my mistake. Try to use P/Invoke GetModuleFileName (coredll.dll)
and GetModuleFileName (kernel32.dll).

Best regards,
Sergey Bogdanov
ORC wrote:
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 GetEntryAssembly in CF. Some other idea?

Thanks,
Ole
"Sergey Bogdanov" <se*************@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Also for a Full Framework you must use
System.Reflection.Assembly.GetEntryAssembly().Loca tion. At runtime you
can detect framework version (System.Environment.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 least):


"Path.GetDirectoryName(Assembly.GetExecutingAssemb ly().GetName().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:\Program 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


Nov 16 '05 #9
ORC
Oh yes it does, but GetEntryAssembly is not defined in CF and therefore the
app wont compile.

Thanks
Ole

"<ctacke/>" <ctacke_AT_OpenNETCF_com> wrote in message
news:uk**************@TK2MSFTNGP14.phx.gbl...
So System.Environment.OSVersion won't work for you?

-Chris
"ORC" <or*@sol.dk> wrote in message
news:u8**************@TK2MSFTNGP12.phx.gbl...
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 GetEntryAssembly in CF. Some other idea?

Thanks,
Ole
"Sergey Bogdanov" <se*************@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Also for a Full Framework you must use
System.Reflection.Assembly.GetEntryAssembly().Loca tion. At runtime you
can detect framework version (System.Environment.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 least): >

"Path.GetDirectoryName(Assembly.GetExecutingAssemb ly().GetName().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:\Program 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
>
>



Nov 16 '05 #10
ORC
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]" <fe******@no-spam.inthehand.com> wrote in message
news:us****************@TK2MSFTNGP12.phx.gbl...
On the Compact Framework you could use this alternative to
GetEntryAssembly:-
http://blog.opennetcf.org/pfoot/Perm...d-3dc8e7525cc4
If you merely want the same result from
Path.GetDirectoryName(Assembly.GetExecutingAssembl y().GetName().CodeBase on both frameworks then use:-

string path =
Path.GetDirectoryName(Assembly.GetExecutingAssembl y().GetName().CodeBase);
if(Environment.OsVersion.Platform!=PlatformID.WinC E)
{
path = path.Replace("file:\\","");
}

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" <or*@sol.dk> wrote in message
news:u8**************@TK2MSFTNGP12.phx.gbl...
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 GetEntryAssembly in CF. Some other idea?

Thanks,
Ole
"Sergey Bogdanov" <se*************@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Also for a Full Framework you must use
System.Reflection.Assembly.GetEntryAssembly().Loca tion. At runtime you
can detect framework version (System.Environment.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 least): >

"Path.GetDirectoryName(Assembly.GetExecutingAssemb ly().GetName().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:\Program 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
>
>



Nov 16 '05 #11
Also using GetCallingAssembly may be better than GetExecutingAssembly. 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 GetExecutingAssembly

--
<ctacke/>
www.OpenNETCF.org
Your CF searches start and end here
"ORC" <or*@sol.dk> wrote in message
news:e0****************@TK2MSFTNGP10.phx.gbl...
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]" <fe******@no-spam.inthehand.com> wrote in message
news:us****************@TK2MSFTNGP12.phx.gbl...
On the Compact Framework you could use this alternative to
GetEntryAssembly:-

http://blog.opennetcf.org/pfoot/Perm...d-3dc8e7525cc4

If you merely want the same result from
Path.GetDirectoryName(Assembly.GetExecutingAssembl y().GetName().CodeBase

on
both frameworks then use:-

string path =
Path.GetDirectoryName(Assembly.GetExecutingAssembl y().GetName().CodeBase);
if(Environment.OsVersion.Platform!=PlatformID.WinC E)
{
path = path.Replace("file:\\","");
}

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" <or*@sol.dk> wrote in message
news:u8**************@TK2MSFTNGP12.phx.gbl...
> 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 GetEntryAssembly in CF. Some other idea?
>
> Thanks,
> Ole
>
>
> "Sergey Bogdanov" <se*************@gmail.com> wrote in message
> news:%2****************@TK2MSFTNGP15.phx.gbl...
>> Also for a Full Framework you must use
>> System.Reflection.Assembly.GetEntryAssembly().Loca tion. At runtime you
>> can detect framework version (System.Environment.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 least): >> >
> "Path.GetDirectoryName(Assembly.GetExecutingAssemb ly().GetName().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:\Program 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
>> >
>> >
>
>



Nov 16 '05 #12
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" <or*@sol.dk> wrote in message
news:e0****************@TK2MSFTNGP10.phx.gbl...
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]" <fe******@no-spam.inthehand.com> wrote in message
news:us****************@TK2MSFTNGP12.phx.gbl...
On the Compact Framework you could use this alternative to
GetEntryAssembly:-

http://blog.opennetcf.org/pfoot/Perm...d-3dc8e7525cc4

If you merely want the same result from
Path.GetDirectoryName(Assembly.GetExecutingAssembl y().GetName().CodeBase

on
both frameworks then use:-

string path =
Path.GetDirectoryName(Assembly.GetExecutingAssembl y().GetName().CodeBase);
if(Environment.OsVersion.Platform!=PlatformID.WinC E)
{
path = path.Replace("file:\\","");
}

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" <or*@sol.dk> wrote in message
news:u8**************@TK2MSFTNGP12.phx.gbl...
> 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 GetEntryAssembly in CF. Some other idea?
>
> Thanks,
> Ole
>
>
> "Sergey Bogdanov" <se*************@gmail.com> wrote in message
> news:%2****************@TK2MSFTNGP15.phx.gbl...
>> Also for a Full Framework you must use
>> System.Reflection.Assembly.GetEntryAssembly().Loca tion. At runtime you
>> can detect framework version (System.Environment.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 least): >> >
> "Path.GetDirectoryName(Assembly.GetExecutingAssemb ly().GetName().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:\Program 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
>> >
>> >
>
>



Nov 16 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Timothy Shih | last post by:
Hi, I am having a freezing issue with my application. My application serves several remotable objects, all of which must be initialized before their use. Furthermore, some of them depend on each...
3
by: ramonred | last post by:
Hi, I have two web apps. Lets say main and admin for the sake of simplicity. admin is a web app within main (as a subdomain). So the path for admin is http://admin.main.com within the admin...
2
by: mark | last post by:
Can't figure this one out. I appears to not be code related. After surfing my asp.net web app for a while 5 - 10 min. it fails to open any further connections to my access 2000 database. There...
1
by: Keith | last post by:
All, I have been told this is an ASP.NET issue and not an IIS issue, so I am posting this here. I have a problem with ASP.NET returning an HTTP 500 error when trying to run ASPX pages on...
2
by: Ross | last post by:
Hi I have an application using asp.net that I am running on my PC. The web form has a text box where you can enter a name for a new Photo category then click on the button. The code is...
4
by: JOHN MALONEY | last post by:
Hi Everybody, I have created a three-tiered db application in VB .NET but I can't get the deployment to work right. I have added a SetUp project to the existing application. I also selected...
6
by: Ben Finney | last post by:
Howdy all, I'm improving an existing application that's partly written using Python and the standard library. Many of the improvements I want to make can be done by using third-party free...
0
by: steve | last post by:
I am using vb.net 2005 Express Edition. Application Settings would be a very useful thing, as a global program database that persists; if only it would work! Does anyone know a hack or a...
4
by: =?Utf-8?B?VkIgSm9ubmll?= | last post by:
I am at my witless end here, please help! I have an ASP.Net aspx web page, hosted on Windows Server 2003, that receives a query string with the path to an autocad drawing file selected from a...
0
by: Steve | last post by:
Hello- Your assistance with this issue is greatly appreciated. Environment: - Load-balanced IIS 6.0 servers (Win2003) - web servers point (via UNC path) to a Microsoft File Cluster on...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.