In a C# 2010 desktop application, I have the following code:
string Format_Date = DateTime.Now.AddMonths(-1).ToString("MM-yyyy");
string filesaveLocation = ConfigurationSettings.AppSettings["Location"] + "\\" + Format_Date + "\\";
if (Directory.Exists(filesaveLocation))
When the value is displayed from filesaveLocation the value: "C:\\\\Trans\\12-2012\\".
The problem is once I get to the following line of code:
if (Directory.Exists(filesaveLocation)) the same is always true.
It does not make any difference if I say (!Directory.Exists(filesaveLocation)).
This answer is true also.
Thus can you show me in code how to correct this problem?
Loading
VulpesPosted Jan 29, 2013, 10:16 AM
dcPosted Jan 29, 2013, 9:42 AM
VulpesPosted Jan 29, 2013, 9:29 AM
I assume therefore that you're not using Windows 7.
dcPosted Jan 29, 2013, 8:20 AM
Can you tell me why this would make a dufference?
Jignesh TrivediPosted Jan 28, 2013, 10:45 PM
I think there is no problem in you code, it might directory exists in the passed location.
i hvae try following code it work fine for me in VS2010 / windows 7 platform.
string filesaveLocation = "E:\\\\Trans\\12-2012\\";
bool bo = Directory.Exists(filesaveLocation);
it return true when directory is exist else return false.
hope this will help you.
VulpesPosted Jan 28, 2013, 3:04 PM
In this situation, Directory.Exists should always return false and !Directory.Exists should therefore return true.
It appears that there is a mistake in Configuration.AppSettings which is causing this problem.
I'd either correct it in there or you could do instead:
filesaveLocation = filesaveLocation.Replace("\\\\", "\\");
just before using Directory.Exists.