The dialog uses InitialDirectory = "D:\Executech\Hotel\Documents"
To see the documents in the folder I must specify the parent folder of "Documents". If I use the same path as InitialDirectory, no files are seen.
This is my code that shows the files.
Private Sub saveFileDialog_DirectoryRequesting(ByVal sender As Object, ByVal e As DirectoryRequestingEventArgs) Handles RadSaveFileDialog1.DirectoryRequesting If Not e.Directory.FullName.StartsWith("D:\Executech\Hotel") Then e.Cancel = True End IfEnd Sub
4 Answers, 1 is accepted
Hello Jeff,
You need to include the parent folders as well:
Private Sub SaveFile_DirectoryRequesting(ByVal sender As Object, ByVal e As Telerik.WinControls.FileDialogs.DirectoryRequestingEventArgs)
e.Cancel = True
If e.Directory.FullName = "C:\" OrElse e.Directory.FullName = "C:\Program Files" OrElse e.Directory.FullName = "C:\Program Files\Docker" OrElse e.Directory.FullName.StartsWith("C:\Program Files\Docker\Docker") Then
e.Cancel = False
End If
End SubLet me know how this works for you.
Regards,
Dimitar
Progress Telerik
This gets me closer. Thanks.
Using e.Directory.FullName.StartsWith() on that last OrElse gives access to all sub folders in the users "Home" folder.
Since I won't know the path each customer has I need code that will allow any folder to work. This code creates an array from each parent folder but the sub gets called again after it completes. Am I doing something wrong or is there something I can do to break the loop?
Private Sub saveFileDialog_DirectoryRequesting(ByVal sender As Object, ByVal e As DirectoryRequestingEventArgs) Handles RadSaveFileDialog1.DirectoryRequesting e.Cancel = True If FileName = "" Then 'File Name of the document that was opened for edit. Blank if new. FileName = My.Application.Info.DirectoryPath() End If Dim FolderName As String = Path.GetDirectoryName(FileName) Dim AllowedPath As String = "" Dim Folders() As String Folders = Split(FileName, "\") For X = 0 To UBound(Folders) Select Case X Case 0 AllowedPath = Folders(X) & "\" Case 1 AllowedPath += Folders(X) Case Else AllowedPath += "\" & Folders(X) End Select If e.Directory.FullName = AllowedPath Then e.Cancel = False End If If X = UBound(Folders) Then If e.Directory.FullName.StartsWith(AllowedPath) Then e.Cancel = False End If End If ' MsgBox(AllowedPath) 'Just checking that the path is correctly formatted and all are there Next 'MsgBox(AllowedPath) 'Just trying to see how many times this loops. Forever it seems . . .
I want to suggest a slightly different approach. You can build a list of directories for the before showing the dialog and then use it in the event. Here is the code:
Private FileName As String = "C:\Program Files\Docker\Docker"Private dirs As List(Of String)Private Sub RadButton1_Click(ByVal sender As Object, ByVal e As EventArgs) Dim saveFile As New RadSaveFileDialog() saveFile.InitialDirectory = FileName saveFile.ExpandToCurrentDirectory = True AddHandler saveFile.DirectoryRequesting, AddressOf SaveFile_DirectoryRequesting dirs = New List(Of String)() Dim di As New DirectoryInfo(FileName) Do While di.Parent IsNot Nothing di = di.Parent dirs.Add(di.FullName) Loop Dim dr As DialogResult = saveFile.ShowDialog()End SubPrivate Sub SaveFile_DirectoryRequesting(ByVal sender As Object, ByVal e As Telerik.WinControls.FileDialogs.DirectoryRequestingEventArgs) e.Cancel = True If e.Directory.FullName.StartsWith(FileName) Then e.Cancel = False Return End If For Each dir In dirs If e.Directory.FullName = dir Then e.Cancel = False Exit For End If Next dirEnd SubI hope this helps. Should you have any other questions, do not hesitate to ask.
Dimitar
Progress Telerik
