Template10: Question: Saving user settings to LocalSharedFolder

Created on 8 Mar 2017  路  19Comments  路  Source: Windows-XAML/Template10

This is not an issue ,

I'm using SettingsService, but how can I save user settings to LocalSharedFolder?
_appSettings = new MyAppSettings(SettingsService.Create(SettingsStrategies.Local, nameof(MyAppSettings)));
that interface settings have bool , string , int , etc. it stores the settings of my app , and it is stored in : C:Users%username%AppDataLocalPackagesAppPackageSettingssettings.dat

I want it to save in the app SharedFolder , how can i create my settings to my SharedFolder location?

NOTE: I want all machine users to have same settings on my app , there is a a thread how to do that , and I was able to do it on my db , different users shares one/same db , but not settings ,thread: https://blogs.msdn.microsoft.com/notime/2016/03/04/sharing-data-between-users-of-a-universal-app/

Most helpful comment

@NicoTiing working on a rough attempt...

All 19 comments

At present the code you can't do what you are asking but a small change to the existing code would allow for it, best through extension (interfaces for the win) unless Jerry feels it would be a worth inclusion to the code base.

Keep in mind though that what is proposed by that post requires a policy change on the machine in question related to a registry key (something which the app is incapable of doing without an administrator physically intervening). Not exactly the ideal solution.

I think this could open up a can of worms personally, I would create another interface to extend the current code base, override what you need.

@mvermef

I hope Sir Jerry would consider it , ok , can you please give me an example of what you meant , Iam really new to this, hope you dont mind

Thank You

@NicoTiing working on a rough attempt...

@mvermef
Thank You , I think the best way for this is , create my own 'SettingsService'

here is the SettingsService :
`public class SettingsService : ISettingsService {
public static ISettingsService Local { get; }
public static ISettingsService Roaming { get; }
public IPropertyMapping Converters { get; set; }
public IPropertySet Values { get; }
protected ApplicationDataContainer Container { get; }

    public static ISettingsService Create(SettingsStrategies strategy, string folderName = null, bool createFolderIfNotExists = true);
    public void Clear(bool deleteSubContainers = true);
    public bool Exists(string key);
    public ISettingsService Open(string folderName, bool createFolderIfNotExists = true);
    public T Read<T>(string key, T fallback = default(T));
    public void Remove(string key);
    public void Write<T>(string key, T value);
}`

here is the Interface:
`public interface ISettingsService {
IPropertyMapping Converters { get; set; }
IPropertySet Values { get; }

    void Clear(bool deleteSubContainers = true);
    bool Exists(string key);
    ISettingsService Open(string folderName, bool createFolderIsNotExists = true);
    T Read<T>(string key, T fallback = default(T));
    void Remove(string key);
    void Write<T>(string key, T value);
}`

and here is the SettingsStrategies:
public enum SettingsStrategies { Local = 0, Roam = 1, Temp = 2 }

Think just needs to add LocalSharedFolder location on SettingsStrategies.

Actually I was digging into this the implementation is completely different, reason being is that ApplicationData.Current.SharedLocalFolder isn't the same thing as you would expect, it not a Settings folder so it would require a completely different approach than what is present.

the type of the SharedLocalFolder is as expect a StorageFolder type, where as LocalSettings for example is of type ApplicationDataContainer, very different beasts.

Pealing layers of this onion is gonna difficult at best especially with the security aspects of this change associated with the machine. It can't be something the App can change on the machine, this is the nature of UWP, respect it.

@mvermef
yes, thats why I think i just need to create my own SettingsStrategies, and add shared location path, but is it possible and will it create settings.dat in that path?

In theory yes but not sure why you want to have users share settings, just a little odd is all.. Almost better if you really need certain settings to propagate to each user that are identical hook it up to a DataSource (azure or webapi) and push the settings that way, storing it locally with SQLite.

@mvermef
uhhm ok ok , can you please let me know if you found out how? , funny but that's what the client wanted

Thanks

This is going in the direction of more trouble that its honestly worth in the end. The Client wanted to make it easier for UWP app to share settings, I don't know that the App Store will even certify this in the end. The only option for something of this nature might be a side load install.. I am not trying to deflect this but I think its going to turn into a nightmare for you.

Don't forget the Customer is not always right...

@mvermef
Actually , they want it to be installed for all users too , but after searching found out that its not possible , may I know about Sideload apps? I followed this thread : https://technet.microsoft.com/itpro/windows/deploy/sideload-apps-in-windows-10?f=255&MSPPError=-2147217396

but cant install app on sideload mode

the link you found is the only source of information for sideloading apps.

@mvermef
Actually , what I did is on my machine with 2 users , i manually installed the app package to each users , and they have the same database.

I read articles about that , Im a bit confused about the difference between 'Sideload apps' and 'developer mode' in Developer features , may I know the difference specifically?

Thanks

Sideload app = trusted with certificate
Developer mode = untrusted... etc.

@mvermef
Im confused yesterday , yeah youre right , what i need is a new ApplicationDataContainer that will create on my SharedFolder location

problem is you can't it doesn't exists for the type of ApplicationData.Current.ShardLocalFolder

@mvermef

What do you mean I can't? , even I create my own SettingsService or ApplicationData?

No I mean SharedLocalFolder is not an ApplicationDataContainer type, it's StorageFolder!

@mvermef
Oh yes, I meant I will create a new ApplicationDataContainer and located to my SharedFolder.
What will you advice for me about this issue? What do you think is the best way ? except for creating config sql db

It's such an extreme use case and I haven't really looked at much past the initial comment. Reason it isn't something I would ever entertain

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JerryNixon picture JerryNixon  路  7Comments

ghost picture ghost  路  4Comments

JerryNixon picture JerryNixon  路  5Comments

Joebeazelman picture Joebeazelman  路  5Comments

govindrawat55 picture govindrawat55  路  6Comments