开发者

Deleting of files from isolated storage isn't working.

The directory have been mapped as indicated in the LoadFiles Method. However, the Delete code isn't able to delete the files from the directory in the isolated storage, even though it has already been mapped.

Here is the LoadFile method:

 private ObservableCollection<FileItem> _files;
        public ObservableCollection<FileItem> Files
        {
            get
            {
                this._files = this._files ?? this.LoadFiles();
                return this._files;
            }
        }


        private ObservableCollection<FileItem> LoadFiles()
        {
            ObservableCollection<FileItem> files = new ObservableCollection<FileItem>();


            foreach (string filePath in this.Store.GetFileNames("FlashCardApp\\"))
                files.Add(new FileItem { FileName = filePath });
            return files;
        }

Here's the delete code that it's suppose to delete the files from the directory after it is checked, but it is unable to do so even if the store.FileExist has already been mapped to the LoadFiles method:

  private void OnDeleteSelected()
        {
            IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
            List<FileItem> removedItems = new List<FileItem>();
            foreach (var item in Files)
            {
                if (item.IsChecked)
                    if (storage.FileExists(item.FileName))
                    {
                        storage.DeleteFile(item.FileName);
                        removedItems.Add(item);
                    }
            }

            foreach (var item开发者_StackOverflow社区 in removedItems)
                Files.Remove(item);
        }

EDIT:

Here is the Isolated Storage Class:

  private IsolatedStorageFile currentStore;
        public IsolatedStorageFile Store
        {
            get
            {
                this.currentStore = this.currentStore ?? IsolatedStorageFile.GetUserStoreForApplication();
                return this.currentStore;
            }
        }


In the first code snippet you are using this.Store to access the IsolatedStorage, and in the second you are referring to IsolatedStorageFile.GetUserStoreForApplication(); do these both point to the same location?

Also, in the second code snippet, does the storage.FileExists(item.FileName) return true? or do you need to append "FlashCardApp\" to the filename? For example: storage.FileExists("FlashCardApp\\" + item.FileName);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜