Application.StartupPath not working in VS2005 (worked in VS2003)

H

hayworth

I had some code to build the name of a file:
' Build the name of the XML config file.
g_strFiles.strConfig =
My.Computer.FileSystem.CombinePath(Application.StartupPath,
"\Settings\Config main.xml")
This worked fine in Visual Studio 2003. But now that I updated to
VS2005, it no longer works. The Application.StartupPath apparently
seems OK in the editor (no syntax errors and I'm able to select
StartupPath from the Intellisense pop up menu), however when it goes to
run, I get a runtime error:
"StartupPath is not a member of MyApplication"
Where on earth is it getting "MyApplication" -- I didn't have that
word in my line of code. I have Application but not MyApplication.
Indeed, MyApplicattion won't even bring up the Intellisense.
If I do something slightly different, My.Application., it brings up
Intellisense but doesn't have the StartupPath property. How can I get
it to do what you would intuitively want it to do, and why did it work
in VS2003 but not with vs2005?
 
H

hayworth

Actually, that wasn't necessarily an error, it just had a black
exclamation point in a red circle when I stopped there in the debugger
but it didn't throw an exception. But the result is
g_strFiles.strConfig = "D:\Settings\Config main.xml"
as if the startup path was merely the drive's root folder and not the
actual startup folder. It should have been something like
"D:\MyAppFolder\Settings\Config main.xml" Why is it not getting the
full folder? (Again, it was no problem for VS2003.)
 
H

Homer J Simpson

Actually, that wasn't necessarily an error, it just had a black
exclamation point in a red circle when I stopped there in the debugger
but it didn't throw an exception. But the result is
g_strFiles.strConfig = "D:\Settings\Config main.xml"
as if the startup path was merely the drive's root folder and not the
actual startup folder. It should have been something like
"D:\MyAppFolder\Settings\Config main.xml" Why is it not getting the
full folder? (Again, it was no problem for VS2003.)

Do you have the right 'Imports' set?
 
H

hayworth

Actually I was using the FileSystemObject in VS2003 since it didn't
have the My.Computer namespace yet. I was using something like
g_fsoFile.BuildPath(folder, basefilename)
Then I converted to the My.Computer.FileSystem.CombinePath way which is
the replacement.
If I do
dim folder as string = Application.StartupPath
it give the correct path but even if I pass it in, it seems to strip
off the folder and jsut give the drive.
I.e.
dim folder as string = Application.StartupPath
g_strFiles.strConfig =
My.Computer.FileSystem.CombinePath(folder,
"\Settings\Config main.xml")
still gives "D:\Settings\Config main.xml" instead of
"D:\MyAppFolder\Settings\Config main.xml"
I have Inherits System.Windows.Forms.Form at the top of the module.
I'm not sure what else I need. Generally I don't use Imports
preferring to just use the lengthy but explicit full namespace. I know
it's longer but I don't have to worry about where it's at since I can
see the full thing unlike with Imports where I think you see only the
last few parts.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top