473,325 Members | 2,671 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,325 software developers and data experts.

find the startup path of a console application


In c# windows applicatiopns the Application.StartupPath can be used to
find the path for the executable file. How can the same be found for a
console application?(we can't use application because it inherits from
the System.Windows.Forms namespace)
Thanks in advance.
*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
5 62615

Something like this might work:
new Uri(Assembly.GetExecutingAssembly.CodeBase)
Use Uri.LocalPath to get the local path.

Regards,
Thi - http://thith.blogspot.com

Eranga wrote:
In c# windows applicatiopns the Application.StartupPath can be used to
find the path for the executable file. How can the same be found for a
console application?(we can't use application because it inherits from
the System.Windows.Forms namespace)
Thanks in advance.
*** Sent via Developersdex http://www.developersdex.com ***


Nov 17 '05 #2
try this instead

string appPath =
System.IO.Path.GetDirectoryName(Assembly.GetEntryA ssembly().Location);

cheers
Nov 17 '05 #3
"Eranga" <km***@yahoo.com> wrote in message news:%2***************@TK2MSFTNGP09.phx.gbl...

In c# windows applicatiopns the Application.StartupPath can be used to
find the path for the executable file. How can the same be found for a
console application?(we can't use application because it inherits from
the System.Windows.Forms namespace)
Thanks in advance.


how about this:

using System.IO;

DirectoryInfo di = new DirectoryInfo(".");
Console.WriteLine(di.FullName);
Nov 17 '05 #4
That is equivalent with Directory.GetCurrentDirectory, which does not
always equal to Application.StartupPath (the path of the executable
that started the app).

The best way, I guess, to get Appication.StartupPath is:
Process.GetCurrentProcess().MainModule.FileName

Note that this returns the full path to the executable file while
Application.StartupPath does not contain the file name. To get the path
without file name use Path.GetDirectoryName function.

Bill Butler wrote:
"Eranga" <km***@yahoo.com> wrote in message news:%2***************@TK2MSFTNGP09.phx.gbl...

In c# windows applicatiopns the Application.StartupPath can be used to
find the path for the executable file. How can the same be found for a
console application?(we can't use application because it inherits from
the System.Windows.Forms namespace)
Thanks in advance.


how about this:

using System.IO;

DirectoryInfo di = new DirectoryInfo(".");
Console.WriteLine(di.FullName);


Nov 17 '05 #5
"Truong Hong Thi" <th*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
That is equivalent with Directory.GetCurrentDirectory, which does not
always equal to Application.StartupPath (the path of the executable
that started the app).
Thanks,

I always start my console Apps from the same directory as the app, so I have never come across this.

Bill


The best way, I guess, to get Appication.StartupPath is:
Process.GetCurrentProcess().MainModule.FileName

Note that this returns the full path to the executable file while
Application.StartupPath does not contain the file name. To get the path
without file name use Path.GetDirectoryName function.

Bill Butler wrote:
"Eranga" <km***@yahoo.com> wrote in message news:%2***************@TK2MSFTNGP09.phx.gbl...
>
> In c# windows applicatiopns the Application.StartupPath can be used to
> find the path for the executable file. How can the same be found for a
> console application?(we can't use application because it inherits from
> the System.Windows.Forms namespace)
> Thanks in advance.
>


how about this:

using System.IO;

DirectoryInfo di = new DirectoryInfo(".");
Console.WriteLine(di.FullName);

Nov 17 '05 #6

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

Similar topics

3
by: Loi | last post by:
Hi All, I use Bulk insert to put data to myTable. When the SQL server is in local machin, it works well. But when I put the data in a sql server situated not locally, then I get a error message...
7
by: Job Lot | last post by:
How can I terminate console application in Try…Catch…Finally…End Try block so that code in Finally gets executed. If I use End statement Finally does not get executed. Following is my code...
2
by: Scafe | last post by:
hi, how can i get the startup path of a console application? thanks for any help
5
by: JJ | last post by:
Hi, Using the app.config scenario and I added a Connectionstring to appSettings area in xml. In the value string I have the datasource equal to a absolute path on my dev machine. Now how can I...
7
by: ajikoe | last post by:
Hello All, It is said that : Enabling the console window is easy. From Microsoft Visual Studio®, right-click on the project and choose Properties. Change the output type from Windows Application...
1
by: Jan | last post by:
Hi, What is the easiest way to retrieve the path from a console application? Right now I am using: - System.Reflection.Assembly.GetEntryAssembly().Location to extract the path and filename -...
2
by: JezB | last post by:
I'm compiling an old C program within Visual Studio to give me the advantages of debugging within this environment. I'm building it as a Console application using C++ as the language. It compiles...
0
by: =?Utf-8?B?U3RldmUgTWFydGlu?= | last post by:
I am attempting to launch a console application from a service under a different set of credentials running on Windows Server 2003. I am getting an error "0xC06D007E: Module not found." from the...
1
by: CeciMar | last post by:
I'm new to vb.net and I have a very simple console application. When I attempt to compile it at the command prompt I get error BC30420 Sub Main not found. I know the namespace and module name but...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: 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

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.