Visual Studio 2012 application settings - c#

I have read the tutorial on application settings, and I don't understand a bit. All I know is that I've created a .settings file using the designer, assigned values to it, and Properties.Settings.Default doesn't let me access them because it says they don't exist (what the tutorial is saying is that if you create an entry called Foo, then you can access it with Properties.Settings.Default.Foo, which, as I said, doesn't work). Can someone please explain to me how to work with .settings files and access the settings themselves?

I had the same problem, but then I used only Settings.Default instead of Properties.Settings.Default, and it works now.

Please, set select Access Modifier as internal and I believe it will help.

Related

How do I make changes to AppConfig userSettings?

So I was having trouble adding a new App.Config userSettings. Without any knowledge. I tried to set the configuration directly in the app.config HML. Files get overwritten. It stays in App.Config but it does not show up in the Settings.Designer or IntelliSense. I know it should show up in the
IntelliSense because the configured userSettings that are already present do.
How do you correctly configure a user setting?
Maybe, this question is a duplicate of this: How to save application settings in a Windows Forms Application?
I guess I would accept that, but it was difficult to find the answer to the question starting from the point of view I started with. I think that there are allot of well meaning souls like me that try to directly edit the app.config file to achieve this and wonder why they get nowhere fast. These askers are are unsure where to find the correct answer. I also suspect that other well meaning souls that answer their questions assuming that the questioner was asking from a prospective where they knew the answer to this question. This of course makes understanding difficult to reach for the original seeker of knowledge.
Answer: I checked Microsoft to learn more and found this link:
https://learn.microsoft.com/en-us/dotnet/framework/winforms/advanced/how-to-create-a-new-setting-at-design-time
which says this:
Open Visual Studio.
In Solution Explorer, right-click your project node and choose Properties.
In the Properties page, select the Settings tab.
In the Settings designer, set the Name, Value, Type, and Scope for your setting. Each row represents a single setting.
I found that I could even use custom types like my enum, which vs will convert from a string in the HML.
Now this procedure populates App.config and Settings.Designer.cs with the setting for you. It shows up in IntelliSense too. Fantastic!
Note: The settings can also be accessed by Settings.Settings.
Now I have noticed, since I continually seem to want to get under the hood and do things in an undocumented way: It is possible to directly edit the Settings.Settings file. Don't do that either, That will get you pretty far but the settings you configure there will not persist when you build.

Pragmatically Open Database connection

I am working on a project and have scoured the internet for answers on this topic but could not find a single answer, not even an open source solution.
Maybe you guys could help me out.
In visual studio you can open the database connection window by browsing View -> server explorer -> add connection. that is all well and known but what if I wanted to open that same form from code or a certain API. I cant seem to figure it out but there must be some sort of way to access this form pragmatically since its native to Visual Studio.
For all who are unsure what form I'm talking about, here's a snippet:
So my question to you is, how can I , through code, open this window? If there is nothing built into Visual Studio and C#, do you know of any open source software that accomplishes this or will I have to recreate it with a windows form application?
I think you would need to build the form yourself if you need any custom logic etc in which case you could use the ConnectionStringBuilder classes and pass the validated fields from your custom form to the relevant builder class to generate the connection string. Visit here for more information.
Microsoft also has library on nuget that you could use, although it's deprecated so use with caution. The nuget file, which you can download manually, also contains the source code so perhaps you could use this to jump start your own UI component. https://www.nuget.org/packages/DataConnectionDialog

Update app.config file after installer upgrade

I'm currently working on a Microsft Word Application-Level Add-in using C#. My application contains an app.config file. In this file I save user-settings (userSettings-Section) and some data defined by a custom ConfigurationSection. The data stored inside of custom ConfigurationSection is also user-specific.
I access the user-settings as follows:
Properties.Settings.Default.MyUserSetting
The custom ConfigurationSection I'm using like:
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal)
.GetSection("MyCustomConfigurationSection")
My questions are:
Do I even use the app.config the "correct" way? (I know that there is probably not only one correct way, but is "my way" one of these?)
Which ConfigurationUserLevel does Propeties.Settings.Default use? Is there a way of setting/changing it?
And Most importantly: Is there a way to automatically keep the user-specific settings during an upgrade of my application, but at the same time add newly created settings?
I deploy my Add-in using an installer built with WiX. At the moment I use CustomActions, which manually insert code for each added/removed/changed setting. But I was wondering whether there is a built-in way of doing this.
I did some researches the whole day now and I think I can answer my questions for myself:
Q: Which ConfigurationUserLevel does Propeties.Settings.Default use? Is there a way of setting/changing it?
A: It seems that Propeties.Settings.Default use ConfigurationUserLevel.PerUserRoamingAndLocal, what sounds logical as they only contain userSettings... I don't know whether it is possible to change it, but for me it is not necessary.
Q: Is there a way to automatically keep the user-specific settings during an upgrade of my application, but at the same time add newly created settings?
A: I found out that there is an Upgrade()-Method in Settings which should take care of copying user settings between an older version of the product and the new one. For more information see http://ngpixel.com/2011/05/05/c-keep-user-settings-between-versions/. I must confess that I haven't had occasion to test it, since I have no permissions to build the installer, but I will rely on it. I will come back to this post after I tested my solution.
Furthermore I am not using a custom ConfigurationSection any more. Instead I derive from System.Configuration.ApplicationSettingsBase, which means that I am able to handle the custom data exactly like the Properties.Settings, including the Upgrade()-Method. See this post for more information about how to use it.
Hope this helps somebody.

Saving a project using VS2010 Postbuild Events

I'm collaborating on a project with my buddy, and I'm working on most of the code while he does the front-end interfaces/graphics. I would like for him to have access to the project when he needs it (for instance to check up on progress). I read that you can set up a post-build event with VS to save your project to somewhere else (dropbox in that case, and in mine as well), but there's no documentation anywhere on the web (that I could find) detailing how to do this. If anyone knows and can point me in the right direction, that'd be great.
P.S. Is this the place I should be posting this? Please tell me if this ought to be in a different forum.
Why don't you use a free online source code repository like CodePlex, GitHub or Visual Studio Online instead? Then it's properly stored somewhere and versioned.

How to create a password protected project Visual Studio 2010

I'm trying to make a password protected project in Visual Studio 2010. Is there an option in Visual Studio to protect the project folder from being accessed without a password or something?
I need this to protect my projects from other nosy people, or an external program of some sort.
Thanks!
As far as I know, there is no an option like this.
Anyway, protecting a folder with a password is a really bad idea because brute forcing it could be really easy.
I suggest you use TrueCrypt to create a protected storage and use that like container, mounting it when you need and dismounting it when you're not sitting in front of your PC.
You can not do that inside Visual Studio, but what you can do like a possible solution if I right understood your trouble is use of source control.
Push your code in some source control (there are a lot of free of them) and even if something goes wrong (for 1000 possible reasons) you always will have a possibility to investigate history of issue and roolback unnecessary changes back.
Commits to source control can be protected by your password, instead.
Hope this helps.

Categories