Where did my files go?

Posted on 2011-09-10
Medium Priority
Last Modified: 2013-11-08
My application has an XML file that holds the settings. Whenever I add some features, re-compile, and re-publish using ClickOnce, and then someone clicks "OK" because there is an update available, the settings file, settings.xml, is not retained.

It looks like that every version gets installed under appdata as a new version, which is why settings.xml is no longer available.

Question: how do I make the settings file persistent so that even though an upgrade comes down the pipe, and the client gets the new version of the program, they don't have to go through and re-enter all their settings?
Question by:DrDamnit
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
LVL 40
ID: 36516964
You need to Upgrade the settings in the newer version.

Open in new window

There seem to be a little bug with that however. It should not be a big problem, but might be annoying for some.

This works everywhere except when you install through ClickOnce on the same computer that holds the server from which the application is deployed.

This happens on my station, that is at the same time my usual workstation, my development station and the on on which I run my server. What I do is that on that station, I do not use the application through a ClickOnce install, but I use it directly from the compilation directory. This has an extra advantage: I get the debugger when there is a bug while I am using the application for real work.
LVL 83

Expert Comment

ID: 36517006
Can you not use the app.exe.config file with settings having User scope. I think these settings do not get reset during updates.
LVL 40

Accepted Solution

Jacques Bourgeois (James Burger) earned 2000 total points
ID: 36517022

Contrary to standard Windows Application, with ClickOnce, the User scoped settings get overwritten when you install a new version of the application, because the AppData directory for a ClickOnce install is different for all versions.

This is why an Update has to be called. It will copy the already existing settings from the old configuration file to the new one.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 83

Expert Comment

ID: 36517075
Yeah looks that way. Here is some info

LVL 32

Author Comment

ID: 36517675
I am not using app.exe.config. I am using a custom file that is created at runtime called settings.xml.

My.Settings.Upgrade() doesn't appear to know about the file.

But... your post gave me the idea to use: My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData & "myapp\settings.xml"

That works like a charm, and no upgrade needed.
LVL 32

Author Closing Comment

ID: 36517678
This post gave me the idea to use: My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData
LVL 40
ID: 36517888
No wonder that My.Settings.Upgrade does nothing. Your settings and "our" settings are not the same.

Your use of the term "settings" misled us. A standard configuration file in .NET is prepared by using the Settings tab of the project properties, and My.Settings is the class used to write and retrieve information from the configuration file. So we thought that this is what you were talking about.

You are right, My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData & "myapp\settings.xml"
would probably work (we do not have the big picture, thus the "would").

But I would add 2 remarks.

First one. My is a namespace that makes things easy for amateur programmers, for whom it was conceived. But it also hides a lot of possibilities. While you have 30 or so methods to work with files, directories and drives through My.Computer.FileSystem, you have more than that only for files, only for directories and only for drives through the System.IO namespace. This gives you a lot more to "play" with. If you program for fun, My.Computer.FileSystem is probably sufficient. But if programming is part of your job, working with the classes in System.IO will open more possibilities.

Second one. There is already an easy to use feature to work with "settings" in the framework: the configuration file. This thing has been designed by people who know the framework and it intricacies a lot more than any of the "experts" here, because they designed .NET. Why work hard to try to implement something on your own, when the one that is already there is doing the job for almost everybody. There are probably thing you did not think about that the programmers at Microsoft knew and cared for.

If it is there, and if it is well designed and work, and if you do not need something very special, using what is already there is both the easiest and best way to do things.
LVL 32

Author Comment

ID: 36523009
I code utilities to make my job easier. So, I cannot say that I am full-time 40 hours a week coding by an means of the imagination. But, I have been coding for 20+ years in multiple languages. Most of the time, however, it is not .NET. :-)

I didn't know about the settings class, and will certainly use that from now on rather than coding my own settings files from scratch.

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question