Curious behavior from Enviroment.SpecialFolder

  • Thread starter Thread starter Anthony
  • Start date Start date
A

Anthony

Hello Everyone,

I've raised a similar question in the group before but am still puzzled by
this behavior and I'd like to understand what is going on here. If anyone
would be so kind as to take a shot at explaining this, I'd be most greatful.

I'm writing an application for Windows Mobile that will store its
configuration file in the \ApplicationData folder of the device. Let's name
the configuration file 'myApp.conf'. At first, I thought this code would
work:

Dim oFile as New
StreamReader(System.Enviroment.GetFolderPath(Enviroment.GetSpecialFolder.ApplicationData)
& "\myApp.conf")

However, if I print the filename of oFile in a messagebox, I get something
like '26\myApp.conf' which, obviously isn't the folder name I'm looking for
in that path.

So I convert the path to a string using like this

oFile = New
StreamReader(CStr(System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
& "\myApp.conf"))

And everything works fine.

Can anyone explain why these methods would return an integer instead of a
string until they are explicitly converted to a string? Am I missing
something critical here or is this just one of those weird and goofy things?

Thanks!
Anthony
 
Hello Everyone,

I've raised a similar question in the group before but am still puzzled
by this behavior and I'd like to understand what is going on here. If
anyone would be so kind as to take a shot at explaining this, I'd be
most greatful.

I'm writing an application for Windows Mobile that will store its
configuration file in the \ApplicationData folder of the device. Let's
name the configuration file 'myApp.conf'. At first, I thought this code
would work:

Dim oFile as New
StreamReader(System.Enviroment.GetFolderPath(Enviroment.GetSpecialFolder.ApplicationData)
& "\myApp.conf")

However, if I print the filename of oFile in a messagebox, I get
something like '26\myApp.conf' which, obviously isn't the folder name
I'm looking for in that path.

So I convert the path to a string using like this

oFile = New
StreamReader(CStr(System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
& "\myApp.conf"))

And everything works fine.

Can anyone explain why these methods would return an integer instead of
a string until they are explicitly converted to a string? Am I missing
something critical here or is this just one of those weird and goofy
things?

Thanks!
Anthony

The int value of SpecialFolder.ApplicationData is 26, so it would appear
when you write the messagebox out, you are not calling GetFolderPath.

When you recoded the line with the CStr, you must have fixed the call
somehow.
 
Can anyone explain why these methods would return an integer instead of
The int value of SpecialFolder.ApplicationData is 26, so it would appear
when you write the messagebox out, you are not calling GetFolderPath.

When you recoded the line with the CStr, you must have fixed the call
somehow.

Hi Mike,

Thanks Mike. I suppose that's pretty clear and I appreciate the quick
response.

Anthony
 
Back
Top