1
votes

I created a directory named "MyFolder" and wrote some text files there. Now, I want delete that directory and I am using the following code:

 public void DeleteDirectory(string directoryName)
        {
            try
            {
                using (IsolatedStorageFile currentIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (!string.IsNullOrEmpty(directoryName) && currentIsolatedStorage.DirectoryExists(directoryName))
                    {
                        currentIsolatedStorage.DeleteDirectory(directoryName);
                        textBox1.Text = "deleted"; 
                    }
                }
            }
            catch (Exception ex)
            {
                // do something with exception
            }
        }

I tried with

DeleteDirectory("MyFolder") 
DeleteDirectory("IsolatedStore\\MyFolder")

however it didn't delete that directory. Any idea to solve that?

1
did you delete everything in it first? i'm not sure that is required... but it might be?John Gardner
I first tried to delete files, but same results. not sure thats the problem.MKS
stackoverflow.com/questions/6858050/… I hope that it will help youAlik Khilazhev

1 Answers

2
votes

Have you deleted all of the contents of that directory?

http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefile.deletedirectory(v=vs.80).aspx

says (although it isn't the windows phone version of the documentation):

A directory must be empty before it is deleted. The deleted directory cannot be recovered once deleted.

The Deleting Files and Directories example demonstrates the use of the DeleteDirectory method.