How to edit application settings of one project from another?

In a VB.Net project, you can use the Settings tab on the properties page to define application settings. To refer to settings in the code, you use the syntax My.Settings.SettingName in VB.

On the Settings tab, you can select an access modifier. It can be “Friend” or “Public”. Presumably, when you select "Public", you make the settings available for other assemblies. However, once “Public” is selected, I cannot understand the syntax to refer to the settings of one project from another. In fact, I see no difference between using "Internal" and "Public" as an access modifier.

My question is: does "Public" choose as the access modifier to make the settings available for other assemblies? If so, what syntax refers to settings from other assemblies? If not, what does "Public" do?

+6
settings
source share
4 answers

You mix things up pretty badly. The installation does not have an accessibility modifier, they are always publicly available. However, in a Winforms application, you do have the Application Settings property in the Properties window for the control. Right upstairs. And a modifier property. The latter is the default Friend in a VB.NET, Private project in a C # application. This determines the availability of the control variable, not the settings.

Yes, My.Settings gives you access to the parameter that stores the value of the control property. But that is where the good news ends. You should always specify the parameter value in the settings designer for the user. So that the value can be saved and restored when your program starts the backup.

Settings with a user area are stored in a file that is difficult to find. A typical path for such a file is C: \ Users \ hpassant \ AppData \ Local \ WindowsFormsApplication1 \ WindowsFormsApplication1._Url_2acx4ldi2zmg42elj3eyqq0snhqco4qe \ 1.0.0.0

The first part is me, the current user of my laptop. The bizarre part of the path name is the hash, a value unique to the name and version of the application. And probably something like moon phase when I compiled the application. The calculation algorithm for this hash is not documented. Just that it will be unique to my application and cannot be broken by another application.

And that in rub, one application cannot find user area settings for another application. You will have to refuse to use the settings if it is important to you. And replace it with, say, an XmlDocument in a well-known place.

+6
source share

I was looking for the same thing, this is this:
In C #:
[Namespace] .Properties.Settings.Default. [SettingName]
In VB:
[Namespace] .My.MySettings.Default. [SettingName]

+3
source share

I think you can transfer an instance of the settings object from one DLL to another DLL (say, when the application starts), and then access this parameter using the Item property of this class (settings classes are inherited by the class from ApplicationSettingsBase)

'In DLL1: Class1 General property settings FromAnotherDLL as ApplicationSettingsBase ...

'In DLL2: (executed at startup) Class1.SettingsFromAnotherDLL = My.Settings.Default

'In DLL2 when accessing the settings Dim Setting As STring = Class1.SettingsFromAnotherDLL.Item ("SettingKey")

0
source share

Here is an example code to get the value of a parameter named DataBaseName any .exe located near our executing application and save it in the variable "dbName":

 string currentDirectory = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string exeName = System.IO.Path.GetFileName(Assembly.GetExecutingAssembly().Location); FileInfo[] fileInfos = new DirectoryInfo(currentDirectory).GetFiles("*.exe"); foreach (FileInfo fi in fileInfos) { if (fi.FullName == System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)) continue; Assembly asm = Assembly.LoadFrom(fi.FullName); Type[] allTypes = asm.GetTypes(); foreach (Type type in allTypes) { if (type.Name != "Settings") continue; Type settingsType = type; PropertyInfo propDefault = type.GetProperty("Default"); object defaultSettings = propDefault.GetValue(null, null); PropertyInfo piDBName = settingsType.GetProperty("DataBaseName"); string dbName = (string)piDBName.GetValue(defaultSettings, null); break; } break; } 
0
source share

All Articles