无法删除文件异常WP8独立存储

时间:2014-02-21 12:10:25

标签: c# windows-phone-8 delete-file isolatedstorage

我尝试删除一个包含所有文件的文件夹...但是我收到了一个错误...我不知道为什么...该文件夹也是建立在文件内部但是当代码尝试删除时我得到了问题......

  
public static bool DeleteFolder(string FolderName)
        {
            using (var iso = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (iso.DirectoryExists(FolderName))
                {
                    try
                    {
                        //get all files in the folder
                        String[] Files = iso.GetFileNames(FolderName + @"\*");
                        //delete all files
                        foreach (var file in Files)                   
                        {
                            iso.DeleteFile(Path.Combine(FolderName, file));  

                        }
                        //delete the directory
                        iso.DeleteDirectory(FolderName);
                        //return true when it's done
                        if (!iso.DirectoryExists(FolderName))
                            return true;

                    }
                    catch (Exception e)
                    {
                        throw new MyException(MyExceptionsMessages.UnknownError + e.Message);

                    }

                }
                return true;

            }

        }

0 个答案:

没有答案