0
votes

I use the "Sqlite for Windows Runtime" and sqlite-net (just as described at http://timheuer.com/blog/archive/2012/08/07/updated-how-to-using-sqlite-from-windows-store-apps.aspx) to develop a Windows 8 Metro-App, just . If I want to open a Database at the Program-Directory is no problem:

var dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite");
using (var db = new SQLite.SQLiteConnection(dbPath)) {
  ...
}

But when I want to use an extern Path like this:

var dbPath = "C:\\Users\\xxxxxx\\db.sqlite";

then an error occurs with "Cannot open database file". Why? Here I am using C#, normally I use C++, but for this problem I am sure it doesn't matter ;)

2
Why on earth would you choose to use an extern Path? My suggestion is use Visual Studio to verify the path you are actually trying to use is correct. This show very little research on your part this can EASILY be solved after you spend 5 minutes debugging the code. - Security Hound
Are you allowed to acces this path, from explorer? You can only acces directory of current user... as an "user dependent" application. - neagoegab
There is a reason this code uses Windows.Storage.ApplicationData.Current.LocalFolder.Path because that is one of the few locations a Metro application can actually access. - Security Hound
What if I want to save the database in a Dropbox-Folder for automatic sync, just as an example? This is not possible? - Berschi
@Berschi Where would your Dropbox-Folder be located? If your dropbox is one of the locations I listed below then you can save there, otherwise you can have the user use the FileSavePicker to pick a location at which to save. msdn.microsoft.com/en-us/library/windows/apps/… - N_A

2 Answers

6
votes

You cannot select arbitrary files on the file system. See here for details.

By default you can access these locations:

  • Application install directory
  • Application data locations
  • User’s Downloads folder

and

Additionally, your app can access some of the files on connected devices by default. This is an option if your app uses the AutoPlay Device extension to launch automatically when users connect a device, like a camera or USB thumb drive, to their system. The files your app can access are limited to specific file types that are specified via File Type Association declarations in your app manifest. Of course, you can also gain access to files and folders on a removable device by calling the file picker (using FileOpenPicker and FolderPicker) and letting the user pick files and folders for your app to access. Learn how to use the file picker in Quickstart: Accessing files with file pickers.

If you have the right capabilities declared you can also access:

A combination of the following capabilities is needed. The home and work networks capability:

PrivateNetworkClientServer

And at least one internet and public networks capability:

InternetClient InternetClientServer

And, if applicable, the domain credentials capability:

EnterpriseAuthentication

Note You must add File Type Associations to your app manifest that declare specific file types that your app can access in this location.

1
votes

In windows metro application... It support only sandbox property of an application.

So you cant use

var dbPath = "C:\\Users\\xxxxxx\\db.sqlite";

U can only store data in local storage or application installed directory.

Please avoid to use any other path . it will not work .