473,473 Members | 2,169 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 5415
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.