In a C# 2008 desktop application, I would like to come up with a test to see if the value 'CUST' is a valid directory level within a directory path supplied to the program. Basically the directory path would look like:
"C:\RData\CUST\Omaha\book.xlsx".
The code I am using the following code, but it is not working:
string filesaveLocation=ConfigurationSettings.AppSettings["Location"];
if (filesaveLocation == "*CUST*").
The value for filesaveLocation is obtained from the app.config file.
Thus can you show me how to change the code listed above, so that I can verify that 'CUST' is one of the directory folder names listed in a file path that looks like "C:\RData\CUST\Omaha\book.xlsx"?
Loading
Pankaj PandeyPosted May 24, 2013, 12:42 AM
please try this..
using System.Io;
if(FIle.Exist(C:\RData\CUST\Omaha\book.xlsx))
{
//do something
}
or
if(Directory.Exist(C:\RData\CUST\Omaha\"))
{
//do something
}
Terrance CPosted May 23, 2013, 7:02 PM
if (filesaveLocation.Contains(@"\CUST\"))
{
//do something
}
else
{
// filesaveLocation does not contain \CUS\ so run this code...
}
or
if (!(filesaveLocation.Contains(@"\CUST\")))
-- Added the NOT ! condition if '\CUST\' is not contained in string.
Also, in the top code if the contains does not find the string your looking for it's going to go to the else condition. Does this help?
dcPosted May 23, 2013, 6:32 PM
I also have to test to see if the directory file path does not = 'CUST', in the directory path called ""C:\RData\CUST\Omaha\book.xlsx".
Can you tell me how to make that code change also?
VulpesPosted May 23, 2013, 4:54 PM