FileDialog.RestoreDirectory Property
Gets or sets a value indicating whether the dialog box restores the directory to the previously selected directory before closing.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Property Value
Type: System.Booleantrue if the dialog box restores the current directory to the previously selected directory if the user changed the directory while searching for files; otherwise, false. The default value is false.
The following code example uses the OpenFileDialog implementation of FileDialog and illustrates creating, setting of properties, and showing the dialog box. The example uses the RestoreDirectory property to ensure that the previously selected directory is restored when the dialog box is closed. The example requires a form with a Button placed on it and the System.IO namespace added to it.
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim myStream As Stream = Nothing Dim openFileDialog1 As New OpenFileDialog() openFileDialog1.InitialDirectory = "c:\" openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" openFileDialog1.FilterIndex = 2 openFileDialog1.RestoreDirectory = True If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then Try myStream = openFileDialog1.OpenFile() If (myStream IsNot Nothing) Then ' Insert code to read the stream here. End If Catch Ex As Exception MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message) Finally ' Check this again, since we need to make sure we didn't throw an exception on open. If (myStream IsNot Nothing) Then myStream.Close() End If End Try End If End Sub
to set the property. Associated enumeration: PermissionState.Unrestricted.
Available since 1.1