vb.net desk app using app.config file
-
In a vb.net 2010 desktop application, I added an app.config file to the application 2 years ago. I did not so I can point to different directly paths without needing to recompile the application. This change worked at that time. I have not needed to change the application until recently. Now I actually have to recompile the application so the app.config file changes will be picked up. Thus can you tell me what I can do to the application so I can change the app.config file without needing to recompile the application?
-
In a vb.net 2010 desktop application, I added an app.config file to the application 2 years ago. I did not so I can point to different directly paths without needing to recompile the application. This change worked at that time. I have not needed to change the application until recently. Now I actually have to recompile the application so the app.config file changes will be picked up. Thus can you tell me what I can do to the application so I can change the app.config file without needing to recompile the application?
Does you code actually look for a setting in the app.config file? What does that code look like?
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
Does you code actually look for a setting in the app.config file? What does that code look like?
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave KreskowiakThe code in the application looks like the following:
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
frmMain.GlobalForm = Me
Dim strUserName As String = ConfigurationManager.AppSettings("NameofUser")
If strUserName = "ANN" Then
Dim strDirectoryPath As String = ConfigurationManager.AppSettings("File_directory_path")
If Not (Directory.Exists(strDirectoryPath)) Then
Application.Exit()
Exit Sub
End If
Else
Dim strDirectoryPath2 As String = ConfigurationManager.AppSettings("File_directory_path_KARON")
If Not (Directory.Exists(strDirectoryPath2)) Then
Application.Exit()
Exit Sub
End If
End IfThe code in the app.config file looks like:
-
The code in the application looks like the following:
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
frmMain.GlobalForm = Me
Dim strUserName As String = ConfigurationManager.AppSettings("NameofUser")
If strUserName = "ANN" Then
Dim strDirectoryPath As String = ConfigurationManager.AppSettings("File_directory_path")
If Not (Directory.Exists(strDirectoryPath)) Then
Application.Exit()
Exit Sub
End If
Else
Dim strDirectoryPath2 As String = ConfigurationManager.AppSettings("File_directory_path_KARON")
If Not (Directory.Exists(strDirectoryPath2)) Then
Application.Exit()
Exit Sub
End If
End IfThe code in the app.config file looks like:
It's not entirely clear what you're doing or what you expect. Any setting you want can be placed into the app.config appSettings section and loaded with an appropriate call to ConfigurationManager.AppSettings("name") to get the setting of that name. The app.config file is NEVER compiled into the application. It must reside in the same folder as the .EXE that is loading it. In your code snippets, you try to get settings called "File_directory_path" and "File_directory_path_KARON", but these never show up in the app.config file so the values returned for those names will be null, not any string value. When you change the setting in app.config, the new setting will be loaded on the next call to retrieve that setting in the code.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
It's not entirely clear what you're doing or what you expect. Any setting you want can be placed into the app.config appSettings section and loaded with an appropriate call to ConfigurationManager.AppSettings("name") to get the setting of that name. The app.config file is NEVER compiled into the application. It must reside in the same folder as the .EXE that is loading it. In your code snippets, you try to get settings called "File_directory_path" and "File_directory_path_KARON", but these never show up in the app.config file so the values returned for those names will be null, not any string value. When you change the setting in app.config, the new setting will be loaded on the next call to retrieve that setting in the code.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave KreskowiakI did not show the values in app.config file for "File_directory_path" and "File_directory_path_KARON", since I just wanted to show you an example. I know what the code is supposed to do by it is not working. The app.config file will not let me change the values outside of the application. The file is locked. Once a user signs on to their computer, I try to change the values in the app.config file. The permissions are locked. The network people say that the user and I have all the rights (permissions) that are needed. I open up the app.config file in notepad in the users computer and the values are not saved. Do you know what else could be wrong so I can not change the permissions. I install the application using the old setup and deployment project that is in visual studio.
-
I did not show the values in app.config file for "File_directory_path" and "File_directory_path_KARON", since I just wanted to show you an example. I know what the code is supposed to do by it is not working. The app.config file will not let me change the values outside of the application. The file is locked. Once a user signs on to their computer, I try to change the values in the app.config file. The permissions are locked. The network people say that the user and I have all the rights (permissions) that are needed. I open up the app.config file in notepad in the users computer and the values are not saved. Do you know what else could be wrong so I can not change the permissions. I install the application using the old setup and deployment project that is in visual studio.
If the app isn't running, the only other common possibility is that the executable (and the config file) are under Program Files, which is READ ONLY to everyone on the machine, except admins. If you're an admin on the machine and can't understand why when YOU try to save the changes to app.config, it's because you have to run Notepad as an administrator. (Search for notepad.exe, right-click it, pick Run as administrator..) If you're putting settings in a file that needs to be written to by your app or even Notepad, put them in a file under C:\ProgramData\appName\... You can then modify the code to load the settings from that path instead of from under Program Files. See this[^] for examples.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
If the app isn't running, the only other common possibility is that the executable (and the config file) are under Program Files, which is READ ONLY to everyone on the machine, except admins. If you're an admin on the machine and can't understand why when YOU try to save the changes to app.config, it's because you have to run Notepad as an administrator. (Search for notepad.exe, right-click it, pick Run as administrator..) If you're putting settings in a file that needs to be written to by your app or even Notepad, put them in a file under C:\ProgramData\appName\... You can then modify the code to load the settings from that path instead of from under Program Files. See this[^] for examples.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave KreskowiakIn the bin directory, there is a runtime config file called 'programname.exe.config'. I do not deploy this when I deploy the application. Do I need to include the 'programname.exe.config' as part of the deployment? if so, when the application is only a user's computer, would I change the 'programname.exe.config' file and/or the app.config file in notepad?
-
In the bin directory, there is a runtime config file called 'programname.exe.config'. I do not deploy this when I deploy the application. Do I need to include the 'programname.exe.config' as part of the deployment? if so, when the application is only a user's computer, would I change the 'programname.exe.config' file and/or the app.config file in notepad?
Are you kidding me? YES!! That's your app.config file. It has to go with your app if you expect settings to work. Configuring Apps by using Configuration Files | Microsoft Docs[^]
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak