Need help with Saving a File Path in App Memory. RRS feed

  • Question

  • Hi there.

    I want the user to select a File Path for saving documents created in this App using some Dialog. 

    Saving the File Path to a Var does not retain the info if the App is closed and re-opened. 

    I am not using a DataBase . 

    I remember there is something in the Properties that can be used, I'm not sure.  

    Thursday, May 18, 2017 9:56 AM


All replies

  • Hi VB Nocile,

    According to your description, I guess that you may need to use SaveFileDialog Class to save document.

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim myStream As Stream
            Dim saveFileDialog1 As New SaveFileDialog()
            saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
            saveFileDialog1.FilterIndex = 2
            saveFileDialog1.RestoreDirectory = True
            If saveFileDialog1.ShowDialog() = DialogResult.OK Then
                Dim sw As StreamWriter = New StreamWriter(saveFileDialog1.OpenFile())
                If (sw IsNot Nothing) Then
                    '    myStream = saveFileDialog1.OpenFile()
                    'If (myStream IsNot Nothing) Then
                    '    ' Code to write the stream goes here.
                    '    myStream.Close()
                End If
            End If
        End Sub

    More detailed info, please refer to SaveFileDialog class:

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Wednesday, May 24, 2017 9:01 AM
  • What you probably remember are the Settings. 

    It is a config.sys file and there are ways available to access it from VB.

    However, Personally I prefer setting this kind of things in the registry likewise Microsoft does it themselves. 

    It is very easy to do since version VB7 despite some find it very difficult.


    Wednesday, May 24, 2017 9:34 AM
  • I remember there is something in the Properties that can be used, I'm not sure.  

    Project Properties \ Settings. Click on name to enter a name for your setting, and select the type - string in this case. Leave the Scope at User.

    Then, each time the user makes a new selection in the dialog save the path part of that selection to the settings variable.  It is accessed as My.Settings.<setting name>.  Set the default path for the dialog from the settings variable.

    Wednesday, May 24, 2017 12:21 PM