开发学院图形图像Flash 详解Silverlight 2中的独立存储(Isolated Storag... 阅读

详解Silverlight 2中的独立存储(Isolated Storage)

 2008-10-09 11:38:47 来源:WEB开发网   
核心提示: void btnReadFile_Click(object sender, RoutedEventArgs e){if (this.lstDirectories.SelectedItem == null ||this.lstFiles.SelectedItem == null){HtmlP

void btnReadFile_Click(object sender, RoutedEventArgs e)
{
  if (this.lstDirectories.SelectedItem == null ||
    this.lstFiles.SelectedItem == null)
  {
    HtmlPage.Window.Alert("请先选择目录和文件!");
    return;
  }
  using (IsolatedStorageFile store =
            IsolatedStorageFile.GetUserStoreForApplication())
  {
    String filePath = System.IO.Path.Combine(this.lstDirectories.SelectedItem.ToString(),
             this.lstFiles.SelectedItem.ToString());
    if (store.FileExists(filePath))
    {
      StreamReader reader = new StreamReader(store.OpenFile(filePath,
          FileMode.Open, FileAccess.Read));
      this.txtFileContent.Text = reader.ReadToEnd();
      this.txtDirectoryName.Text = this.lstDirectories.SelectedItem.ToString();
      this.txtFileName.Text = this.lstFiles.SelectedItem.ToString();
    }
  }
}

删除目录和文件:

void btnDeleteFile_Click(object sender, RoutedEventArgs e)
{
  if (this.lstDirectories.SelectedItem != null &&
    this.lstFiles.SelectedItem != null)
  {
    using (IsolatedStorageFile store =
            IsolatedStorageFile.GetUserStoreForApplication())
    {
      String filePath = System.IO.Path.Combine(this.lstDirectories.SelectedItem.ToString(),
          this.lstFiles.SelectedItem.ToString());
      store.DeleteFile(filePath);
      HtmlPage.Window.Alert("删除文件成功!");
    }
  }
}
void btnDeleteDirectory_Click(object sender, RoutedEventArgs e)
{
  if (this.lstDirectories.SelectedItem != null)
  {
    using (IsolatedStorageFile store =
            IsolatedStorageFile.GetUserStoreForApplication())
    {
      store.DeleteDirectory(this.lstDirectories.SelectedItem.ToString());
      HtmlPage.Window.Alert("删除目录成功!");
    }
  }
}

获取目录列表和文件列表:

上一页  1 2 3 4 5 6  下一页

Tags:详解 Silverlight 独立

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接