Click to See Complete Forum and Search --> : Bug in GetFolderPath (beta)?
zips
October 7th, 2005, 10:33 AM
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. 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?
Jason Isom
October 7th, 2005, 11:04 AM
That's strange. When I run it my output is
C:\Documents and Settings\Jason\Application Data
Press any key to continue . . .
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.
static void Main(string[] args)
{
string AStr = System.Environment.
GetFolderPath(
System.Environment.SpecialFolder.
ApplicationData).ToString();
Console.WriteLine(AStr);
}
poochi
October 7th, 2005, 11:08 AM
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.
crackersixx
October 7th, 2005, 01:28 PM
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\"
zips
October 7th, 2005, 01:33 PM
I have found thatPath.DirectorySeparatorChar.ToString() == "\\"on this system, contrary to what is stated in help topicms-help://MS.VSCC.v80/MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref/html/F_System_IO_Path_DirectorySeparatorChar.htmThus, 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.
Jason Isom
October 7th, 2005, 01:36 PM
I have found thatPath.DirectorySeparatorChar.ToString() == "\\"
I'm confused. What's your point? The following is also true.
Path.DirectorySeparatorChar.ToString() == @"\"
There is no double slash.
zips
October 7th, 2005, 01:48 PM
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.
poochi
October 7th, 2005, 04:48 PM
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).
cilu
October 7th, 2005, 05:06 PM
I have found that
Path.DirectorySeparatorChar.ToString() == "\\"
And that is correct.
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:
Console.WriteLine("\\");
Console.WriteLine(@"\");
Then try to compile this one:
Console.WriteLine("\");
You will see that the string is not ended, because the second " is escaped with the backslash.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.