473,785 Members | 2,938 Online
Bytes | Software Development & Data Engineering Community
+ 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.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
Nov 16 '05 #1
12 5460
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
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

Nov 16 '05 #2
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 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

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 GetEntryAssembl y in CF. Some other idea?

Thanks,
Ole
"Sergey Bogdanov" <se************ *@gmail.com> wrote in message
news:%2******** ********@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 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

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*******@taxu ssi.no.com.spam .pl> wrote in message
news:cs******** **@atlantis.new s.tpi.pl...
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
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

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

-Chris
"ORC" <or*@sol.dk> wrote in message
news:u8******** ******@TK2MSFTN GP12.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 GetEntryAssembl y in CF. Some other idea?

Thanks,
Ole
"Sergey Bogdanov" <se************ *@gmail.com> wrote in message
news:%2******** ********@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 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
>
>


Nov 16 '05 #6
Sorry, my mistake. Try to use P/Invoke GetModuleFileNa me (coredll.dll)
and GetModuleFileNa me (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 GetEntryAssembl y in CF. Some other idea?

Thanks,
Ole
"Sergey Bogdanov" <se************ *@gmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
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:
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:\Pr ogram 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
GetEntryAssembl y:-
http://blog.opennetcf.org/pfoot/Perm...d-3dc8e7525cc4

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" <or*@sol.dk> wrote in message
news:u8******** ******@TK2MSFTN GP12.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 GetEntryAssembl y in CF. Some other idea?

Thanks,
Ole
"Sergey Bogdanov" <se************ *@gmail.com> wrote in message
news:%2******** ********@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 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
>
>


Nov 16 '05 #8
.... 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:
Sorry, my mistake. Try to use P/Invoke GetModuleFileNa me (coredll.dll)
and GetModuleFileNa me (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 GetEntryAssembl y in CF. Some other idea?

Thanks,
Ole
"Sergey Bogdanov" <se************ *@gmail.com> wrote in message
news:%2******** ********@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 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


Nov 16 '05 #9
ORC
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:uk******** ******@TK2MSFTN GP14.phx.gbl...
So System.Environm ent.OSVersion won't work for you?

-Chris
"ORC" <or*@sol.dk> wrote in message
news:u8******** ******@TK2MSFTN GP12.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 GetEntryAssembl y in CF. Some other idea?

Thanks,
Ole
"Sergey Bogdanov" <se************ *@gmail.com> wrote in message
news:%2******** ********@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 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
>
>



Nov 16 '05 #10

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

Similar topics

11
2770
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 other. On my application startup, I configure the objects usting the RemotingConfiguration class to load the config file. Then I "ping" each of the objects to call their constructors. This all works fine if no one is attempting to connect at the...
3
5425
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 application I have a file upload page and I wish to upload the files to the main application. I have tried this application of MapPath and it fails. string myPath = "http://main.com"
2
1840
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 seems to be no set drop off point either that would point to a specific code problem. I went through and made sure that I explicitly closed all my connections when done and even called the dispose method after each one. I noticed that asp.net...
1
3159
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 Windows Server 2003 Enterprise Edition Only. This works on Windows 2000, Windows 2003 Web Edition and
2
2222
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 intended to create a new directory under Photos such as "Relatives".
4
4403
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 RELEASE as appropriate in the Application Folder and on the Users Desktop and Start menu. I didn't know whether the Project Output though would be enough or whether I would need to add the .mdb file to the Application folder too. I tested the deployment...
6
1936
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 software. The immediate customer for this application is happy to install Python on their machine, but I'd like to remove the hassle of asking them to continually install new versions of great third-party Python software that isn't packaged for their...
0
3998
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 work-around to get it working? For me, it seems to mess up the path of the folder where user.config is saved. If I Access the property :--
4
2874
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 web page hosted on a unix driven file server. The user wants to have this file converted to a pdf. My page takes the query string and turns it into a windows unc path, then I copy the file down to the web server and place it into a directory. This...
0
2024
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 different machines. - domain ASPNET account that handles the function/permissions of the (traditionally) local machine ASP.NET account.
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10330
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10153
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9952
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3654
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.