This is a migrated thread and some comments may be shown as answers.

DirectoryRequesting Behavior

4 Answers 66 Views
FileDialogs
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 17 Jul 2019, 04:04 PM

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 If
End Sub

 

4 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 18 Jul 2019, 07:44 AM

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 Sub

Let me know how this works for you.

Regards, Dimitar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Jeff
Top achievements
Rank 1
answered on 18 Jul 2019, 04:34 PM

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 . . .

 

0
Jeff
Top achievements
Rank 1
answered on 18 Jul 2019, 04:40 PM
The above code is missing the "End Sub"
0
Dimitar
Telerik team
answered on 19 Jul 2019, 06:57 AM
Hi Jeff,

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 Sub
 
Private 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 dir
End Sub

I hope this helps. Should you have any other questions, do not hesitate to ask.
 
Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
FileDialogs
Asked by
Jeff
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or