none
Error when saving with My.Settings.Save() RRS feed

  • Question

  • Is there a way to display the path to where my application is saving its settings using My.Settings.Save()? I have a user that is getting an error when My.Settings.Save() is called and I would like to display the path for him in a message box to see if that folder is set to locked or to figure out why he might be receiving this error.

    Thank you,

    HR


    Hal Roenick

    Tuesday, October 29, 2019 9:43 PM

Answers

  • Karen,

    Thank you for your post, it looks very promising. However, as you can see from the picture below there are errors when I try to dimension the "config" variable even though I have included the files you suggested. Any thoughts?

    Thanks again,


    Hal Roenick


    Add a reference to the project for System.Configuration then an Import statement for System.Configuration to the file.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by VCADDCAMM Wednesday, October 30, 2019 12:24 AM
    Tuesday, October 29, 2019 11:47 PM
    Moderator

All replies

  • Hi

    What is the 'error'?

    I have dozens of applications that use the My.Settings and not one uses My.Settings.Save as I have the [Application Settings -> Save My Settings on ShutDown] enabled (which I believe is the default).

    As fora message to the User: put a Try .... Catch... End Try around the My.Settings.Save and in the Catch, MessageBox.Show(Ex.Message)


    Regards Les, Livingston, Scotland



    • Edited by leshay Tuesday, October 29, 2019 9:54 PM
    Tuesday, October 29, 2019 9:48 PM
  • Add this file to your project, name is MyLocations.vb

    Imports System.Configuration
    Imports System.IO
    
    Namespace My
        Partial Class MySettings
            Public ReadOnly Property ConfigurationFolder() As String
                Get
                    Dim config = ConfigurationManager.
                            OpenExeConfiguration(ConfigurationUserLevel.
                                                    PerUserRoamingAndLocal)
                    Return config.FilePath.Replace("\user.config", "")
                End Get
            End Property
            Public ReadOnly Property ConfigurationFolderExists() As Boolean
                Get
                    Return Directory.Exists(ConfigurationFolder)
                End Get
            End Property
            Public Function ConfigurationFile() As String
                Return Path.GetFileName(
                    ConfigurationManager.
                        OpenExeConfiguration(
                            ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath)
            End Function
        End Class
    End Namespace

    Used perhaps in a button click event

    If My.Settings.ConfigurationFolderExists Then
        MessageBox.Show(My.Settings.ConfigurationFolder)
    Else
        MessageBox.Show("Not found")
    End If


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, October 29, 2019 10:32 PM
    Moderator
  • Karen,

    Thank you for your post, it looks very promising. However, as you can see from the picture below there are errors when I try to dimension the "config" variable even though I have included the files you suggested. Any thoughts?

    Thanks again,


    Hal Roenick


    • Edited by VCADDCAMM Tuesday, October 29, 2019 11:07 PM
    Tuesday, October 29, 2019 11:06 PM
  • Karen,

    Thank you for your post, it looks very promising. However, as you can see from the picture below there are errors when I try to dimension the "config" variable even though I have included the files you suggested. Any thoughts?

    Thanks again,


    Hal Roenick


    Add a reference to the project for System.Configuration then an Import statement for System.Configuration to the file.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by VCADDCAMM Wednesday, October 30, 2019 12:24 AM
    Tuesday, October 29, 2019 11:47 PM
    Moderator
  • Karen,

    Thanks a bunch, well done!


    Hal Roenick

    Wednesday, October 30, 2019 12:26 AM