您的位置:知识库 » .NET技术

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

作者: TerryLee  来源: 博客园  发布时间: 2008-10-10 10:49  阅读: 8717 次  推荐: 0   原文链接   [收藏]  

 

删除目录和文件:

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("删除目录成功!");
        }
    }
}

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

void lstDirectories_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (lstDirectories.SelectedItem != null)
    {
        using (IsolatedStorageFile store =
                        IsolatedStorageFile.GetUserStoreForApplication())
        {
            String[] files = store.GetFileNames(
                this.lstDirectories.SelectedItem.ToString() + "/");
            this.lstFiles.ItemsSource = files;
        }
    }
}

void BindDirectories()
{
    using (IsolatedStorageFile store = 
                    IsolatedStorageFile.GetUserStoreForApplication())
    {
        String[] directories = store.GetDirectoryNames("*");
        this.lstDirectories.ItemsSource = directories;
    }
}

0
0

.NET技术热门文章

    .NET技术最新文章

      最新新闻

        热门新闻