天天看点

Silverlight中Divelements.SilverlightTools之路径是否存在判断

Divelements.SilverlightTools是一个应用在Silverlight中类似于asp.net中的iframe的第三方控件,在和数据库中路径动态绑定时,需要判断从数据库中取出的路径文件实际上是否存在,这里判断需要用到

IsolatedStorageFile类,使用该类,需要引用using System.IO.IsolatedStorage;命名空间。

操作代码简单如下:

IList<Video> videos = e.Result;

foreach (Video video in videos)

{

string url = string.Format("http://localhost/ZXSK{0}", video.SPURL);

Uri uri = new Uri(url, UriKind.RelativeOrAbsolute);

Uri uri2 = new Uri(" http://localhost/ZXSK/DHM/noVideo.html", UriKind.RelativeOrAbsolute);

//如果该路径下不存在这个文件的话,需要处理一下

using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())

if (store.FileExists(url))

//存在文件,赋给正确的地址

//MessageBox.Show("文件存在!");

this.htmlPlaceholderHost.SourceUri = uri;

}

else

//不存在文件

//MessageBox.Show("文件不存在!");

this.htmlPlaceholderHost.SourceUri = uri2;