如何在Xamarin ios中找到目录资源

时间:2016-04-27 09:59:27

标签: ios xamarin xamarin.ios xamarin.forms xamarin-studio

我目前正在使用Xamarin.iOS并尝试从项目资源和项目目录中的目录中获取数据。但是我在获取信息时无法获取数据。我甚至可以看到整个目录没有复制到应用程序包本身。

以下是我的代码。

string localHtmlUrl = Path.Combine(NSBundle.MainBundle.BundlePath,
                                   string.Format("NewFolder/webref/index.html")
                      );

1 个答案:

答案 0 :(得分:2)

从这个sample我认为你需要的就是这个:

string fileName = "NewFolder/webref/index.html"; // remember case-sensitive
string localHtmlUrl = Path.Combine (NSBundle.MainBundle.BundlePath, fileName);
webView.LoadRequest(new NSUrlRequest(new NSUrl(localHtmlUrl, false)));

如果你有这样的文件夹结构:

enter image description here

如果它在你的Resource文件夹中,那么你需要将它放在你的路径中:

string fileName = "Resource/NewFolder/webref/index.html";

请记住,为所有文件设置Build ActionBundleResource

也可以试试这个:

var fileName = "NewFolder/webref/index.html";
webView.LoadHtmlString (File.ReadAllText (fileName), NSUrl.FromFilename (fileName));