Solved

Where did my files go?

Posted on 2011-09-10
8
281 Views
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?
0
Comment
Question by:DrDamnit
  • 3
  • 3
  • 2
8 Comments
 
LVL 40
ID: 36516964
You need to Upgrade the settings in the newer version.
My.Settings.Upgrade()

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.
0
 
LVL 83

Expert Comment

by:CodeCruiser
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.
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 36517022
@CodeCruiser.

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.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 83

Expert Comment

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

http://msdn.microsoft.com/en-us/library/ms228995.aspx
0
 
LVL 32

Author Comment

by:DrDamnit
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.
0
 
LVL 32

Author Closing Comment

by:DrDamnit
ID: 36517678
This post gave me the idea to use: My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData
0
 
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.
0
 
LVL 32

Author Comment

by:DrDamnit
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.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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