MKS
MKS

Reputation: 786

Delete a directory from Isolated storage windows phone 7

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?

Upvotes: 1

Views: 513

Answers (1)

John Gardner
John Gardner

Reputation: 25116

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.

Upvotes: 2

Related Questions