Sharing data files between users in a Universal Wi

2019-07-08 23:17发布

I am about to embark on the development of a line of business application using the Universal Windows Platform (Windows 10). One of the requirements of the application is the synchronisation of data from a server to a local SQLite database; this is required because the application needs to be usable where there is no network connectivity.

It is likely that multiple (windows domain) users will be accessing the application on the same device, sometimes simply by "swapping users", other times by logging off the first user and logging on as a new user.

I realise that UWP applications are installed at a user level, however I would like to be able to share the SQLite database between these users instead of forcing each user to download their own copy of the data.

Is this possible? I am struggling to find any reference to this kind of sharing within the Microsoft documentation - but of course that documentation is new and far from complete!

I guess at the end of the day I am looking for access to a folder that is accessible by any user running that application on the same device, such as the "x:\Users\Public" folders that are available from the desktop, but without having to ask the user to provide access to that folder via any picker control - instead simply being able to "open" it.

Thanks.

2条回答
别忘想泡老子
2楼-- · 2019-07-08 23:38

In case anyone runs across this, this functionality is now available as described in this blog post:

We introduced a new storage location Windows 10, ApplicationData.SharedLocalFolder, that allows multiple users of one app to share local data. Obviously this feature is only interesting with devices that will be used by more than one person. For such scenarios, for example in educational uses, it may make sense to place any large downloads in Shared Local. The benefits will be two-fold: any user can access these files without the need to re-download them, also there will be storage space savings

Keep in mind that Shared Local is only available if the machine has the right group policy, otherwise when you call ApplicationData.Current.SharedLocalFolder you will get back a null result.

In order to enable Shared Local the machine administrator should enable the corresponding policy.

Group Policy Change

Alternatively, the administrator could create a REG_DWORD value called AllowSharedLocalAppData with a value of 1 under HKLM\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\AppModel\StateManager

Registry Change

Note that data store in ShareLocal will only be persisted as long as the app is installed on the device and won’t be backed up by the system.

查看更多
Viruses.
3楼-- · 2019-07-08 23:42

In Solution Explorer , Right click on Package.appxmanifest then click on ViewCode , end of this file in both projects add below code :

<Extensions>
  <Extension Category="windows.publisherCacheFolders">
    <PublisherCacheFolders>
      <Folder Name="FolderName" />
    </PublisherCacheFolders>
  </Extension>
</Extensions>

After that in code you can access this folder with below line of code :

StorageFolder sharedDownloadsFolder = ApplicationData.Current.GetPublisherCacheFolder("FolderName");

It`s so important that the folder you will share between two these Apps depend on same publisher info at Certificate File [ProjectName]_TemporaryKey.pfx , if this Certificate File and publisher Info of app is same in both Projects , then you can access the same SharedFolder in both application and use it for create or use dataBase file(like SQLite Database file) or other files that need to be share in both applications.

查看更多
登录 后发表回答