我正在尝试检查隔离存储,然后是一些命令以及它。
我想要的是检查包含"a*" *的目录名,如果目录存在*它将检查以"a +今天日期“命名的目录是否存在。
如果存在,将显示一条弹出消息,告诉它确实存在。
但是,如果没有包含"a*“的目录是存在的,则将显示”不存在“的消息。
下面是我的代码:
如果存在"a*“的created.
代码:
string[] fileNames;
string selectedFolderName;
private void gameBtn_Click(object sender, RoutedEventArgs e)
{
//MediaPlayer.Stop();
string currentDate = DateTime.Now.ToString("MMddyyyy");
string currentDateName = "a" + currentDate;
IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();
fileNames = myStore.GetDirectoryNames("a*");
foreach (var name in fileNames)
{
if (fileNames.Contains(currentDateName))
{
selectedFolderName = currentDateName;
MessageBox.Show("Your schedule for today");
NavigationService.Navigate(new Uri("/DisplaySchedule.xaml?selectedFolderName=" + selectedFolderName, UriKind.Relative));
}
else
{
MessageBox.Show("No Schdule for today", "Schedule Reminder", MessageBoxButton.OK);
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
}
}}
发布于 2011-07-29 07:09:16
你的错误只是一个简单的错误。
if (fileNames.Contains(currentDateName))应该是
if (name.Contains(currentDateName))至于在没有目录"a*“时进行处理,请检查fileNames是否为空。
if (fileNames.Length == 0) // no Directory 'a' was found, create it
{
// create code here
}https://stackoverflow.com/questions/6869461
复制相似问题