My problem is similar but not the same as that exhibited in:
"Could not find file" when using Isolated Storage
I've written an application that saves user settings in a file in isolated storage, I'm using the user store for assembly storage.
The application checks for a file in Isolated Storage on startup, and if it's not there assumes that it's the first time the application has been run and asks the user to configure it, this process then saves to Isolated Storage.
In Windows XP this works fine, I've not seen any issues whatsoever. However, I was running a demonstration to the client on their Windows Vista laptop and when I ran the client for the 2nd time to show that the settings were saved the application couldn't find the file.
Are there any known issues that might cause this to happen in Windows Vista and not Windows XP?
Both references to retrieve Isolated Storage are in the same .cs file, so it's definitely the same assembly that is making the call, and I didn't log in as another user, so I know it's the same user.
Isolated storage location will change as soon as you change the application version.
The proper place to store application configuration is in \ProgramData for all users and \Users\\AppData for user settings.
Related
I've created a database windows application using in C#. My application is running successfully on Windows XP, but it doesn't properly execute on Vista or Windows 7 systems. My application shows a message similar to
Failed to update .mdf database because the database is read-only
Can anyone give me a solution to this?
The big thing that changed between Windows XP and Windows Vista/7 is the introduction of UAC which means that users, even if created as administrators, don't routinely have read/write access to "important" locations such as the %programfiles% (Usually C:\Program Files or C:\Program Files (x86)) directory. This is why your application works on Windows XP and not on Windows Vista.
You need to store your DATA in the %programdata% directory (which is usually C:\ProgramData) if the data is shared between users on the machine or %appdata% (which is usually C:\Users\USERNAME_GOES_HERE\AppData\Roaming) if it is specific to a given user. You'll now no longer encounter the problem of being unable to write to the file.
The reason for this is that by storing data in your programs installation directory you were doing the wrong thing. Windows didn't stop you from doing this previously, but it was fairly widely documented that %programfiles% was not the appropriate place to store data.
If the MDB file is in your application path, then the default permissions would require elevation of rights to be able to write to the files -- I'd recommend moving the data to the ApplicationData shared folder, where end users will have write permissions by default
I ran into this related to localdb, the file is named:
myfolder/mysolution/myproject/App_Data/something.mdf
The way I fixed it is to right-click on the top level folder (myfolder) and then choose Properties, then choose Edit, then select Users, add to users either the Modify permission or both Modify and full control (this is a development environment) and then click apply.
So in other words, in my experience, it doesn't matter what folder you put the localdb in, you just need to give Users permission to write.
You should add the Modify permissions for IIS_IUSRS user to *.mdf file.
go to the folder Where the program is installed and right click on the database file and Properties -> Security -> Group or Username (Click users one by one and see below for the permissions)
If for the user if not set to full control, then click EDIT -> Select the user and give full control..
I've stored some data in the ApplicationData.Current.RoamingSettings following the Example here http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh700362.aspx .
The problem is that after storing the data in the RoamingSettings and then removing the same data using ApplicationData.Current.RoamingSettings.Values.Remove(key) (I've checked and actually the data are no more there), if I Uninstall and re-install the App on my Phone the Data I've deleted are back in RoamingSettings...
I've tried also ApplicationData.Current.ClearAsync() that clean all but after uninstalling and re-installing the app same thing.. the data are back.
Any suggestions?
RoamingSettings are designed to work like that. They can be used to store settings between devices. After you uninstall the App from all devices, the settings would persist in the cloud for some time in case the User installs the App again. If you want to use only local data - take a look at LocalSettings.
You will find more information about Guidlines for Roaming Data here at MSDN.
And here at the blog you will find similar answer:
Q. What happens to roaming app data when an app is uninstalled?
A. As noted in the previous question, an app’s app data folders are removed from a device when the app is uninstalled. Roaming app data, however, persists in the cloud so long as the user has the same app installed on other devices. When the user uninstalls the app from all of his or her devices, roaming app data continues to persist in the cloud for a reasonable time (a matter of a few weeks) so that it’s still available if the user decides to reinstall the app within that time. Note that when you make a change to an app project in Microsoft Visual Studio and that change (such as changing the manifest) forces a full reinstall, app data is removed as part of the process. References: Guidelines for roaming app data(overview docs).
So your to remove permanently your RoamingSettings you will have to wait.
EDIT - thanks to Pablo we have more detailed information here at MSDN:
Roaming data for an app is available in the cloud as long as it is accessed by the user from some device within the required time interval. If the user does not run an app for longer than this time interval, its roaming data is removed from the cloud. If a user uninstalls an app, its roaming data isn't automatically removed from the cloud, it's preserved. If the user reinstalls the app within the time interval, the roaming data is synchronized from the cloud. The current policy specifies that this time interval is 30 days.
I am trying to use the correct class for storing data in my windows app. I used IsolatedStorageSettings on the Windows Phone app, but I need to use the Windows.Storage class in my Windows store App begin written with VS Express 2013
I need the data to remain secure on the device when the app is not in use and don't want it to be saved in the cloud or removed unless the use logs out of the app. SO it just need to stay secure while the user remains logged in regardless if they are using the app or its in the background or Windows shut it down for memory reasons.
I suspect roaming is not the way to go but which should I use: local or temporary?
OK, after some more research I found this.
http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
Looks like local app data is the correct method as temporary data can be removed by the device at any time. Roaming as it says is for data that you want to use across devices that is stored on OneDrive(old Skydrive).
And if someone needs the example code then here is the link for a simple example.
local
Data that exists on the current device and is backed up in the cloud.
roaming
Data that exists on all devices on which the user has installed the app.
temporary
Data that could be removed by the system at any time.
localcache
Persistent data that exists only on the current device.
In my C# application, if I wanted to be able to download an "add-in" from our website and store it locally on the user's computer, and then run it (assume it's an assembly DLL or EXE, doesn't matter), I assume I can't store it in a subdirectory of my Program Files folder, and that's not really the right place for it since add-ins are user-specific. Where should I store these, and what kinds of trust/security issues might I run into?
The application data directory of the current user would be one place to store them.
string basePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
basePath = System.IO.Path.Combine(basePath, "MyProgram");
if (!Directory.Exists(basePath))
Directory.CreateDirectory(basePath);
Trying to write anything inside of Program files after installation will run into problems in Vista, Windows 2008 server, Windows 7 and later. Unless of course your application requires elevation. Also you mentioned your files are specific per user.
Use the IsolatedStorage class provided in .NET for storing user specific stuff.
More information: Working with Isolated Storage in .NET
The Winform application is release with ClickOnce in our Intranet. We store personal preference for the GUI in the Isolated Storage. All works pretty fine :)
The problem is when we have a new version of the application, we publish... all preferences are lost! User need to setup their preference over and over each version.
Is there a way to freeze the isolation for the whole application instead of the version?
You need to use application scoped, rather than domain scoped, isolated storage. This can be done by using one of IsolatedStorageFileStream's overloaded constructors.
Example:
using System.IO;
using System.IO.IsolatedStorage;
...
IsolatedStorageFile appScope = IsolatedStorageFile.GetUserStoreForApplication();
using(IsolatedStorageFileStream fs = new IsolatedStorageFileStream("data.dat", FileMode.OpenOrCreate, appScope))
{
...
However, now you will run into the issue of this code only working when the application has been launched via ClickOnce because that's the only time application scoped isolated storage is available. If you don't launch via ClickOnce (such as through Visual Studio), GetUserStoreForApplication() will throw an exception.
The way around this problem is to make sure AppDomain.CurrentDomain.ActivationContext is not null before trying to use application scoped isolated storage.
I was working on a ClickOnce app a while ago and used Environment.GetFolderPath(ApplicationData) - e.g. roaming app data folder, to store all settings. Worked fine and survived numerous updates. Just create a subdireectory with the name of your app or CompanyName/AppName or whatever and store everything in there.
a summary from the other answers:
IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetUserStoreForAssembly();//for visual studio
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
{
isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();//for click once applications
}
You have to store a permanent version of user settings in a more durable store like database. Your application can decide to use the isolated storage if it is available. If it is not available (because of a newer version), the app should get the settings from database and use it to re-initialize the settings in isolated storage. If settings are changed, you should update both places. Unless there is a newer version of the app, your app should not have to get the settings from DB.