我为一些客户发布了Silverlight应用程序。我在发布更新时遇到问题。
我希望当用户最初加载网页时,如果他们的应用存储空间比上次更新网站时更早,则会发生this。这将使我的应用程序工作。
所以,有两个问题:
如何检查存储的应用程序存储的用户是否早于 Silverlight网站的最后一次更新?
如何删除网站的应用程序存储空间?
我试过打电话:
using( var store = IsolatedStorageFile.GetUserStoreForApplication() ) {
store.Remove();
}
using( var store = IsolatedStorageFile.GetUserStoreForSite()) {
store.Remove();
}
在App.xaml.cs
文件中,但这些似乎对显示的页面没有影响 - 应用程序存储未完全清除。
答案 0 :(得分:4)
•如何检查存储的应用程序存储的用户是否早于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);
}
答案 1 :(得分:0)
您可以将xap文件的文件创建日期写入Silverlight对象的initParams。
<object id="xaml" data="data:application/x-silverlight-2," type="application/x-silverlight-2">
<param name="initParams" value="<%= GetInitParams() %>" />
在代码隐藏文件中你写了这样的东西:
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客户端中,您可以将此日期与应用程序存储的上次更新进行比较。您可以使用GetLastWriteTime()
对象上的方法IsolatedStorageFile
找到上次更新的日期和时间。
然后,比较这两个日期,并根据需要将文件删除Deletefile
。