Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

.NET 2.0 App.Path equivalent

I'm developing a Compact Framework 2.0 application. I want to use the old App.Path for setting some connection strings; however, App.Path is not used in 2.0. What is the equivalent? Thanks in advance.
[208 byte] By [lagyossarian] at [2007-11-11 8:03:27]
# 1 Re: .NET 2.0 App.Path equivalent
System.Windows.Forms.Application.StartupPath is it i believe
salvinger at 2007-11-11 21:48:10 >
# 2 Re: .NET 2.0 App.Path equivalent
Thanks!
lagyossarian at 2007-11-11 21:49:05 >
# 3 Re: .NET 2.0 App.Path equivalent
A small gotcha to watch out for:

In VB6, you could use App.Path & "yourfilename"

In .NET, you have to add a \ before your filename:

Application.StartupPath & "\yourfilename"
piratepops at 2007-11-11 21:50:14 >
# 4 Re: .NET 2.0 App.Path equivalent
VB6 provided the "\" for you only if your selecting the root. Otherwise, you had to specify it.
edburdo at 2007-11-11 21:51:14 >
# 5 Re: .NET 2.0 App.Path equivalent
VB6 provided the "\" for you only if your selecting the root. Otherwise, you had to specify it.

Which is why I put "yourfilename" in the quotes,
not "yourpathname".
piratepops at 2007-11-11 21:52:13 >
# 6 Re: .NET 2.0 App.Path equivalent
I suggest using the system.io.path.combine function for path and filename concatenation. It takes care of missing or present "\"
darren at 2007-11-11 21:53:12 >