Solved

Where did my files go?

Posted on 2011-09-10
8
278 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

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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
Comment Utility
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
Comment Utility
@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
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Yeah looks that way. Here is some info

http://msdn.microsoft.com/en-us/library/ms228995.aspx
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 32

Author Comment

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

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now