以编程方式清除Silverlight应用程序存储?

我为一些客户发布了Silverlight应用程序。 我在发布更新时遇到问题。

我希望当用户最初加载网页时,如果他们的应用程序存储比上次更新网站时更旧,则会发生这种情况。 这将使我的应用程序工作。

那么,有两个问题:

  • 如何检查存储的应用程序存储的用户是否早于Silverlight站点的上次更新?

  • 如何删除站点的应用程序存储?

我试过打电话:

using( var store = IsolatedStorageFile.GetUserStoreForApplication() ) { store.Remove(); } using( var store = IsolatedStorageFile.GetUserStoreForSite()) { store.Remove(); } 

App.xaml.cs文件中,但这些似乎对显示的页面没有影响 – 应用程序存储未完全清除。

•如何检查存储的应用程序存储的用户是否早于Silverlight站点的上次更新?

此代码进入应用程序以检查是否存在并更新到您的SL应用程序我不知道它是否有帮助,但如果您只是想在更新时对那个IsolatedStorageFile执行某些操作它应该是您想要的:

 Application.Current.CheckAndDownloadUpdateAsync(); Application.Current.CheckAndDownloadUpdateCompleted += new CheckAndDownloadUpdateCompletedEventHandler(Current_CheckAndDownloadUpdateCompleted); private void Current_CheckAndDownloadUpdateCompleted(object sender, CheckAndDownloadUpdateCompletedEventArgs e) { if (e.UpdateAvailable) { } } 

•如何删除站点的应用程序存储?

 IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication(); if(store.FileExists(FileName)) { store.DeleteFile(FileName); } 

您可以将xap文件的文件创建日期写入Silverlight对象的initParams。

   

在代码隐藏文件中,你写这样的东西:

 protected string GetInitParams() { string xappath = HttpContext.Current.Server.MapPath(@"~/ClientBin/YourXapFile.xap"); DateTime xapCreationDate = System.IO.File.GetLastWriteTime(xappath); return string.Format("lastUpdateDate={0:d}, xapCreationDate); } 

在Silverlight客户端中,您可以将此日期与应用程序存储的上次更新进行比较。 您可以使用IsolatedStorageFile对象上的GetLastWriteTime()方法GetLastWriteTime()上次更新的日期和时间。

然后,比较这两个日期,并根据需要删除带有Deletefile的文件。