Reputation: 163
I have a directory, which is created after executing the app. During using the app it's filled with some pictures, which are the ItemsSource of ComboBox. Before closing the app I'm trying to clear ItemsSource by setting new() or NULL and delete that directory. If the directory is empty it's deleted normally. But else - nothing happens, and there is no exception. What am I doing wrong?
Creating directory and assigning the value of path to "FeedBackScreenshotsPath"
`Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Screenshots"));
MailHelper.FeedBackScreenShotsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Screenshots");`
Deleting
`if (Directory.Exists(MailHelper.FeedBackScreenShotsPath))
{
Directory.Delete(MailHelper.FeedBackScreenShotsPath, true);
}`
Message handling before closing
`private void OnCloseProgramMessageReceived(CloseProgramMessage message)
{
Screenshots = null;
// or Screenshots.Clear();
// or Screenshots = new ObservableCollection<PictureWrapper>();
}`
Upvotes: 1
Views: 94
Reputation: 161
Try it with this:
string [] dirs = System.IO.Directory.GetDirectories("C:\\Test\\");
string[] files = System.IO.Directory.GetFiles("C:\\Test\\");
if (dirs.Length == 0 && files.Length == 0)
{
// Is Empty
}
else
{
// Not Empty
}
Hope it helps :)
Upvotes: 2