|
-
October 7th, 2005, 10:33 AM
#1
Bug in GetFolderPath (beta)?
I am using Visual Studio 2005 (and .NET Framework), build beta2.50215-4400, with Microsoft Windows XP Professional, v5.1.2600 Service Pack 2 Build 2600.
When I use the following statement, the result has DOUBLED backslashes in every position which, of course, do not work very well in Windows IO functions.
Code:
string AStr = System.Environment.
GetFolderPath(
System.Environment.SpecialFolder.
ApplicationData).ToString();
Locals:
AStr "C:\\Documents and Settings\\user.login\\Application Data"
Has anyone else encountered this anomaly?
-
October 7th, 2005, 11:04 AM
#2
Re: Bug in GetFolderPath (beta)?
That's strange. When I run it my output is
 Originally Posted by Output
C:\Documents and Settings\Jason\Application Data
Press any key to continue . . .
 Originally Posted by SystemInfo
OS Name Microsoft Windows XP Professional
Version 5.1.2600 Service Pack 2 Build 2600
OS Manufacturer Microsoft Corporation
The code is exactly as you have it.
Code:
static void Main(string[] args)
{
string AStr = System.Environment.
GetFolderPath(
System.Environment.SpecialFolder.
ApplicationData).ToString();
Console.WriteLine(AStr);
}
Jason Isom
.NET 2.0 / VS2005 Developer
-
October 7th, 2005, 11:08 AM
#3
Re: Bug in GetFolderPath (beta)?
Do you see "@" infront of the value when you see it in "Local window"? If not, the extra slash is probably an escape char. Like Jason did, you can check the value by printing them in the console.
-
October 7th, 2005, 01:28 PM
#4
Re: Bug in GetFolderPath (beta)?
it's an escape char. You cannot have a \ in a string without escaping it first.
string tmp = "this \will fail";
You can escape it by using a double backslash, or by specifying the string with an @ sign to contain no escape codes.
string tmp = "this \\will not fail";
string tmp = @"this \will not fail";
the output of:
string path = "C:\\program files\\someprogram\\";
can be used properly and displayed properly as:
"C:\program files\someprogram\"
Last edited by crackersixx; October 7th, 2005 at 01:32 PM.
-
October 7th, 2005, 01:33 PM
#5
Re: Bug in GetFolderPath (beta)?
I have found that
Code:
Path.DirectorySeparatorChar.ToString() == "\\"
on this system, contrary to what is stated in help topic
ms-help://MS.VSCC.v80/MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref/html/F_System_IO_Path_DirectorySeparatorChar.htm
Thus, Path.Combine also puts DOUBLE backslash between the two arguments.
BTW, this DOUBLE backslash did not occur using the same statements on my previous machine Win2000, using VS v1.1.
Last edited by zips; October 7th, 2005 at 01:37 PM.
-
October 7th, 2005, 01:36 PM
#6
Re: Bug in GetFolderPath (beta)?
 Originally Posted by zips
I have found that
Code:
Path.DirectorySeparatorChar.ToString() == "\\"
I'm confused. What's your point? The following is also true.
Code:
Path.DirectorySeparatorChar.ToString() == @"\"
There is no double slash.
Last edited by Jason Isom; October 7th, 2005 at 01:38 PM.
Jason Isom
.NET 2.0 / VS2005 Developer
-
October 7th, 2005, 01:48 PM
#7
Re: Bug in GetFolderPath (beta)?
The point is that folder and filenames built up using the System.(etal) are not being understood by, for example, OpenFileDialog InitialDirectory or FileName with WinXP VS2005, whereas the same code worked fine with Win2000 VS2003.
Last edited by zips; October 7th, 2005 at 02:00 PM.
-
October 7th, 2005, 04:48 PM
#8
Re: Bug in GetFolderPath (beta)?
I tested your code in VS2005 Beta 2 and Windows XP professional SP2. It works fine. The problem you face is somewhere else.
Post a small compilable sample code to reproduce your problem (including the OpenFileDialog code).
-
October 7th, 2005, 05:06 PM
#9
Re: Bug in GetFolderPath (beta)?
 Originally Posted by zips
I have found that
Code:
Path.DirectorySeparatorChar.ToString() == "\\"
And that is correct.
 Originally Posted by zips
on this system, contrary to what is stated in help topic
No, it's exactly what MSDN says:
The value of this field is a slash ("/") on Unix, and a backslash ("\") on the Windows and Macintosh operating systems.
backslash (\) is an escape caracter. So, if you want to have a string with a backslash in it you must escape it like this "\\". In C# you can use @ before the string to create a verbatim string (what you see is what you get), in which case you don't need escaping the backslash. @"\"
The correct reading of MSDN is:
The value of this field is a slash (/) on Unix, and a backslash (\) on the Windows and Macintosh operating systems.
(notice the missing quotes)
Run this code and see what it outputs:
Code:
Console.WriteLine("\\");
Console.WriteLine(@"\");
Then try to compile this one:
Code:
Console.WriteLine("\");
You will see that the string is not ended, because the second " is escaped with the backslash.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|