简体   繁体   中英

How can I access the filepath to Resources (iOS) folder in Xamarin.Forms?

I have a .sqlite file in the Resources folder of the iOS part of my app. In AppDelegate.cs right now I have:

string dbname = "test.sqlite";
string folderPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Resources), "..", "Library");
string fullPath = Path.Combine(folderPath, dbname);

My issue with this is that when I load up the sqlite file using the sqlite-net-pcl library it shows an empty database, despite there being over 10,000 rows in the sqlite file. I think the issue is I'm linking to the wrong thing.

Once again, the sqlite file is in the Resources folder. How can I access its filepath?

Hallelujah I figured it out!

NSBundle.MainBundle.PathForResource("test", "sqlite");

Returns the filepath for the resource (at least it works on my simulator). I'm going to test this on an actual device and I'll post the results, but for now it's working. Essentially the above command searches for the specified resource, with the first string being the name and the second string being the extension, in this case sqlite.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM