Windows Phone 8安装包中的文件和独立存储区中的文件访问

安装包中的文件:

Windows Phone 8访问安装包中的文件可以直接采用相对路径的形式,"apps/readme.txt"。例如:FileStream stream = File.OpenRead("apps/readme.txt"); 也可以采用下面的方式:

string installPath = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;;
string path = Path.Combine(installPath, "apps/readme.txt");
FileStream stream = File.OpenRead(path);

要通过WebBrowser的Navigate方法只能使用"apps/readme.txt"形式,如:

WebBrowser browser = new WebBrowser();

Uri url = new Uri("html/index.html", UriKind.Relative);

browser.Navigate(uri);

独立存储区的文件:

对于独立存储区的访问需要使用IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();或者使用string localPath = ApplicationData.Current.LocalFolder.Path; 不能直接采用相对路径。

但是对于WebBrowserr的Navigate方法访问独立存储区中的文件,可以也只能使用相对路径:

WebBrowser browser = new WebBrowser();

Uri url = new Uri("html/index.html", UriKind.Relative);

browser.Navigate(uri);

也就是说,WebBrowser访问安装包和独立存储区都要采取相对路径。

这样,当安装包和独立存储区中有同样路径的同样文件时,WebBrowser会优先访问独立存储区中的文件。

微软真是闲的蛋疼啊!!一个字:“混乱”, 我要疯了。

原文地址:https://www.cnblogs.com/imlucky/p/2795154.html