C# 从独立存储中删除文件不是';不起作用。
目录已按照LoadFiles方法中的指示进行映射。但是,删除代码无法从隔离存储中的目录中删除文件,即使它已被映射 以下是LoadFile方法:C# 从独立存储中删除文件不是';不起作用。,c#,visual-studio-2010,windows-phone-7,isolatedstorage,C#,Visual Studio 2010,Windows Phone 7,Isolatedstorage,目录已按照LoadFiles方法中的指示进行映射。但是,删除代码无法从隔离存储中的目录中删除文件,即使它已被映射 以下是LoadFile方法: private ObservableCollection<FileItem> _files; public ObservableCollection<FileItem> Files { get { this._file
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;
}
在第一个代码段中,您使用this.Store访问IsolatedStorage,在第二个代码段中,您指的是IsolatedStorageFile.GetUserStoreForApplication();这两个都指向同一个位置吗
另外,在第二个代码段中,storage.FileExists(item.FileName)是否返回true?或者您需要将“FlashCardApp\”附加到文件名中吗?例如:
storage.FileExists(“FlashCardApp\\”+item.FileName)代码>在第一个代码段中,您使用this.Store访问IsolatedStorage,在第二个代码段中,您指的是IsolatedStorage File.GetUserStoreForApplication();这两个都指向同一个位置吗
另外,在第二个代码段中,storage.FileExists(item.FileName)是否返回true?或者您需要将“FlashCardApp\”附加到文件名中吗?例如:storage.FileExists(“FlashCardApp\\”+item.FileName)代码>我已经编辑了我的问题,添加了隔离存储类。是的,它们似乎指向同一个位置。关于第二个问题,我不确定它是否返回true,我也不知道如何将“FlashCardApp\\”附加到文件名中。它应该返回true,因为它是如果(发生了什么事){那么发生了什么事}
这是我使用visual basic studio 2010完成的一个项目,请不要删除标记。@fatty-谢谢你,伙计,没想到会这么容易!我花了两天时间试图解决这个问题!只是一个小插件:可能您希望使用我编辑的问题,添加隔离存储类。是的,它们似乎指向同一个位置。关于第二个问题,我不确定它是否返回true,我也不知道如何将“FlashCardApp\\”附加到文件名中。它应该返回true,因为它是如果(发生了什么事){那么发生了什么事}
这是我使用visual basic studio 2010完成的一个项目,请不要删除标记。@fatty-谢谢你,伙计,没想到会这么容易!我花了两天时间试图解决这个问题!只是一个小插件:可能你希望使用
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 in removedItems)
Files.Remove(item);
}
private IsolatedStorageFile currentStore;
public IsolatedStorageFile Store
{
get
{
this.currentStore = this.currentStore ?? IsolatedStorageFile.GetUserStoreForApplication();
return this.currentStore;
}
}