App doesn't create a user.config file

J

Jeff Roush

I'm trying to use the User.config file to save a form's size and position.



According to the documentation, the application is supposed to produce a
user.config file and save any settings with user scope to that file . but
that file doesn't seem to be being produced.





I've defined one setting, Location, under "ApplicationSettings" in VS 2005's
Properties window for the form in question, and bound it to the form's
Location property. I was careful to give the Location setting a scope of
"User". I check in the Settings tab of the project's properties window, and
I do in fact see the Location setting, and it does have a scope of "User".



When I run the program, the form does appear at the default location I
specified in the setting. But if I move the form and close it, it always
reappears in its original default location.



After running the program, I see an application.exe.config file, which does
contain the default Location property. But there is no user.config file.



Is there some reason why the user.config file might not be created
automatically?
 
J

Jeffrey Tan[MSFT]

Hi jeff,

Thanks for your post.

How do you do the databinding? Do you use the code snippet below:
this.DataBindings.Add(new System.Windows.Forms.Binding("Location",
global::MyWinApp.Properties.Settings.Default, "Location", true,
System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

default location
I am not sure what do you mean "reappears in its original default
location", because we do not change this default setting, after we closed
form and re-run it, the application code will read the location property
from the user.config. So the form will always have the same position when
opening.

If you want to save the location, we can use the code snippet below:
private void button1_Click(object sender, EventArgs e)
{
global::MyWinApp.Properties.Settings.Default.Save();
}

For more information, please refer to the link below:
"Saving out a Form's Size and Location using the Application Settings
feature"
http://blogs.msdn.com/rprabhu/archive/2005/11/28/497792.aspx

For user.config file, it resides in some special directory, you can get
more information in "Q: You said user.config files go in the user data
path. How can I locate the file? Are there multiple files for an
application or just one?" in the below client setting FAQ
"Client Settings FAQ"
http://blogs.msdn.com/rprabhu/articles/433979.aspx

This FAQ is really a good reference regarding config setting in .Net2.0.

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
S

Stoitcho Goutsev \(100\)

Jeff,

Did you save your settings? The sattings are not saved autmatically, you
need to take care of this. The easies would be to handle form's Closed event
and call

Properties.Settings.Default.Save();

If you want to see the user.config file don't look in the application
folder. The user settings are saved per user and per application in the
user's isolated storage, that is a folder structure inder the user's account
profile:
Somewhere in "Documents and Settings\<username>\Local Settings\Application
Data\......"


--
HTH
Stoitcho Goutsev (100)

"Jeffrey Tan[MSFT]" said:
Hi jeff,

Thanks for your post.

How do you do the databinding? Do you use the code snippet below:
this.DataBindings.Add(new System.Windows.Forms.Binding("Location",
global::MyWinApp.Properties.Settings.Default, "Location", true,
System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

default location
I am not sure what do you mean "reappears in its original default
location", because we do not change this default setting, after we closed
form and re-run it, the application code will read the location property
from the user.config. So the form will always have the same position when
opening.

If you want to save the location, we can use the code snippet below:
private void button1_Click(object sender, EventArgs e)
{
global::MyWinApp.Properties.Settings.Default.Save();
}

For more information, please refer to the link below:
"Saving out a Form's Size and Location using the Application Settings
feature"
http://blogs.msdn.com/rprabhu/archive/2005/11/28/497792.aspx

For user.config file, it resides in some special directory, you can get
more information in "Q: You said user.config files go in the user data
path. How can I locate the file? Are there multiple files for an
application or just one?" in the below client setting FAQ
"Client Settings FAQ"
http://blogs.msdn.com/rprabhu/articles/433979.aspx

This FAQ is really a good reference regarding config setting in .Net2.0.

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeff Roush

Thanks! That's what I was looking for.

Maybe it was the way I was reading into it, but it looked to me like the
documentation was saying that the program saved the settings automatically.

And thanks, Jeffrey, for the links. The blog entry answered the question I
should have asked.

Jeff


Stoitcho Goutsev (100) said:
Jeff,

Did you save your settings? The sattings are not saved autmatically, you
need to take care of this. The easies would be to handle form's Closed
event and call

Properties.Settings.Default.Save();

If you want to see the user.config file don't look in the application
folder. The user settings are saved per user and per application in the
user's isolated storage, that is a folder structure inder the user's
account profile:
Somewhere in "Documents and Settings\<username>\Local Settings\Application
Data\......"


--
HTH
Stoitcho Goutsev (100)

"Jeffrey Tan[MSFT]" said:
Hi jeff,

Thanks for your post.

How do you do the databinding? Do you use the code snippet below:
this.DataBindings.Add(new System.Windows.Forms.Binding("Location",
global::MyWinApp.Properties.Settings.Default, "Location", true,
System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

But if I move the form and close it, it always reappears in its original
default location
I am not sure what do you mean "reappears in its original default
location", because we do not change this default setting, after we closed
form and re-run it, the application code will read the location property
from the user.config. So the form will always have the same position when
opening.

If you want to save the location, we can use the code snippet below:
private void button1_Click(object sender, EventArgs e)
{
global::MyWinApp.Properties.Settings.Default.Save();
}

For more information, please refer to the link below:
"Saving out a Form's Size and Location using the Application Settings
feature"
http://blogs.msdn.com/rprabhu/archive/2005/11/28/497792.aspx

For user.config file, it resides in some special directory, you can get
more information in "Q: You said user.config files go in the user data
path. How can I locate the file? Are there multiple files for an
application or just one?" in the below client setting FAQ
"Client Settings FAQ"
http://blogs.msdn.com/rprabhu/articles/433979.aspx

This FAQ is really a good reference regarding config setting in .Net2.0.

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no
rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top