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

Fileexplorer Path Issue with custom column provider

2 Answers 115 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Jarrett
Top achievements
Rank 2
Jarrett asked on 10 Feb 2012, 04:34 PM
I added a date column to the file explorer and it was working.  I has recently stopped working and I cannot find any reason.  I am getting the following error 

Could not find a part of the path 'D:\www\FreeCE_Net\www\Files\Instructors\~\Files\Instructors\'.



The error is catching on Dim oldItem As DirectoryItem = MyBase.ResolveDirectory(path) in my Public OverLoads Overrides Function ResolveDirectoryPath.  

I have double checked the path it does exist.

.aspx code:

<script type="text/javascript">
        //<![CDATA[


    function OnClientFileOpen(oExplorer, args) {
        var item = args.get_item();
        var fileExtension = item.get_extension();




        if (1 == 1) {// Download the file 
            // File is a image document, do not open a new window


            args.set_cancel(true);


            // Tell browser to open file directly
            var requestImage = "Handler.ashx?path=" + item.get_url();
            document.location = requestImage;
        }
    }
        //]]>
    </script>


    <div style="float: left">
        <telerik:RadFileExplorer runat="server" ID="RadFileExplorer1" Width="734px" Height="400px"
             onclientfileopen="OnClientFileOpen" EnableOpenFile="true" OnExplorerPopulated="RadFileExplorer1_ExplorerPopulated">
            <Configuration ViewPaths="~/Files/Instructors/" DeletePaths="~/Files/Instructors/" SearchPatterns="~/Files/Instructors/"
                UploadPaths="~/Files/Instructors/" />
        </telerik:RadFileExplorer>
    </div>


aspx.vb code:


Imports System
Imports System.Collections
Imports System.Data
Imports System.Configuration
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO
Imports System.Web
Imports System.Collections.Generic
Imports Telerik.Web.UI.Widgets
Imports Telerik.Web.UI






Partial Class Admin_InstructorFileManager2
    Inherits FreeCE.Web.UI.Page
    Protected Sub Page_Load(sender As Object, e As EventArgs)
        If Not IsPostBack Then
            'be sure to set content provider first before doing anything involving paths (e.g. set InitialPath)
            RadFileExplorer1.Configuration.ContentProviderTypeName = GetType(CustomColumnsContentProvider).AssemblyQualifiedName
            RadFileExplorer1.InitialPath = Page.ResolveUrl("~/Files/Instructors/")




        End If
        'AddDateAndOwnerColumns()
    End Sub




    Protected Sub RadFileExplorer1_Load(sender As Object, e As System.EventArgs) Handles RadFileExplorer1.Load
        RadFileExplorer1.Configuration.ContentProviderTypeName = GetType(CustomColumnsContentProvider).AssemblyQualifiedName
        RadFileExplorer1.InitialPath = Page.ResolveUrl("~/Files/Instructors/")
        Dim gridTemplateColumn1 As New GridTemplateColumn()
        gridTemplateColumn1.HeaderText = "Creation Date"
        gridTemplateColumn1.SortExpression = "Date"
        gridTemplateColumn1.UniqueName = "Date"
        gridTemplateColumn1.DataField = "Date"
        ' Add the first column
        RadFileExplorer1.Grid.Columns.Add(gridTemplateColumn1)
    End Sub


    Private Sub AddGridColumn(name As String, uniqueName As String, sortable As Boolean)
        'remove first if grid has a column with that name
        RemoveGridColumn(uniqueName)
        ' Add a new column with the specified name
        Dim gridTemplateColumn1 As New GridTemplateColumn()
        gridTemplateColumn1.HeaderText = name
        If sortable Then
            gridTemplateColumn1.SortExpression = uniqueName
        End If
        gridTemplateColumn1.UniqueName = uniqueName
        gridTemplateColumn1.DataField = uniqueName


        RadFileExplorer1.Grid.Columns.Add(gridTemplateColumn1)
    End Sub


    Private Sub RemoveGridColumn(uniqueName As String)
        If Not [Object].Equals(RadFileExplorer1.Grid.Columns.FindByUniqueNameSafe(uniqueName), Nothing) Then
            RadFileExplorer1.Grid.Columns.Remove(RadFileExplorer1.Grid.Columns.FindByUniqueNameSafe(uniqueName))
        End If
    End Sub


    Private Sub AddDateAndOwnerColumns()




        AddGridColumn("Creation Date", "Date", True)




    End Sub


    Protected Sub RadFileExplorer1_ExplorerPopulated(sender As Object, e As RadFileExplorerPopulatedEventArgs)
        'implement sorting for the custom Date column
        Dim sortingColumn As String = e.SortColumnName
        If sortingColumn = "Date" Then
            Dim dc As New DateComparer()
            e.List.Sort(dc)
            If e.SortDirection.IndexOf("DESC") <> -1 Then
                'reverse order
                e.List.Reverse()
            End If
        End If
    End Sub


    Public Class DateComparer
        Implements IComparer(Of FileBrowserItem)
        Function Compare(item1 As FileBrowserItem, item2 As FileBrowserItem) As Integer Implements IComparer(Of FileBrowserItem).Compare
            'treat folders separate from files
            Dim date1 As DateTime = DateTime.Parse(item1.Attributes("Date"))
            Dim date2 As DateTime = DateTime.Parse(item2.Attributes("Date"))
            If TypeOf item1 Is DirectoryItem Then
                If TypeOf item2 Is DirectoryItem Then
                    Return DateTime.Compare(date1, date2)
                Else
                    Return -1
                End If
            Else
                If TypeOf item2 Is DirectoryItem Then
                    Return 1
                Else
                    Return DateTime.Compare(date1, date2)
                End If
            End If
        End Function
    End Class


    Public Class CustomColumnsContentProvider
        Inherits FileSystemContentProvider
        Public Sub New(context As HttpContext, searchPatterns As String(), viewPaths As String(), uploadPaths As String(), deletePaths As String(), selectedUrl As String, _
            selectedItemTag As String)
            ' Declaring a constructor is required when creating a custom content provider class
            MyBase.New(context, searchPatterns, viewPaths, uploadPaths, deletePaths, selectedUrl, _
                selectedItemTag)
        End Sub




        Public Overloads Overrides Function ResolveDirectory(path As String) As DirectoryItem
            ' Update all file items with the additional information (date, owner)
            Dim oldItem As DirectoryItem = MyBase.ResolveDirectory(path)


            For Each fileItem As FileItem In oldItem.Files
                ' Get the information from the physical file
                Dim fInfo As New FileInfo(Context.Server.MapPath(VirtualPathUtility.AppendTrailingSlash(oldItem.Path) + fileItem.Name))


                ' Add the information to the attributes collection of the item. It will be automatically picked up by the FileExplorer
                ' If the name attribute matches the unique name of a grid column


                fileItem.Attributes.Add("Date", fInfo.CreationTime.ToString())


                ' Type targetType = typeof(System.Security.Principal.NTAccount);
                ' string value = fInfo.GetAccessControl().GetOwner(targetType).Value.Replace("\\", "\\\\");
                'Dim ownerName As String = "PharmCon"
                'fileItem.Attributes.Add("Owner", ownerName)
            Next


            Return oldItem
        End Function


        Public Overloads Overrides Function ResolveRootDirectoryAsTree(path As String) As DirectoryItem
            ' Update all directory items with the additional information (date, owner)
            Dim oldItem As DirectoryItem = MyBase.ResolveRootDirectoryAsTree(path)


            For Each dirItem As DirectoryItem In oldItem.Directories
                ' Get the information from the physical directory
                Dim dInfo As New DirectoryInfo(Context.Server.MapPath(VirtualPathUtility.AppendTrailingSlash(dirItem.Path)))


                ' Add the information to the attributes collection of the item. It will be automatically picked up by the FileExplorer
                ' If the name attribute matches the unique name of a grid column


                dirItem.Attributes.Add("Date", dInfo.LastWriteTime.ToString())


                'Type targetType = typeof(System.Security.Principal.NTAccount);
                'string value = dInfo.GetAccessControl().GetOwner(targetType).Value.Replace("\\", "\\\\");
                'Dim ownerName As String = "PharmCon"
                ' dirItem.Attributes.Add("Owner", ownerName)
            Next
            Return oldItem
        End Function
    End Class




End Class




2 Answers, 1 is accepted

Sort by
0
Dobromir
Telerik team
answered on 13 Feb 2012, 12:05 PM
Hi Jarrett,

The provided configuration of RadFileExplorer incorrect - the value of SearchPatterns property can contain wildcards for the allowed file extensions separated by commas(,) and not path, i.e. SearchValues="*.jpg,*.gif".

Could you please fix this error and see if the problem still exists?

Greetings,
Dobromir
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Jarrett
Top achievements
Rank 2
answered on 13 Feb 2012, 01:48 PM
Thank you for that!!!

I had made a change to the paths, and must have changed the search pattern by accedent, and did not notice. 
Tags
FileExplorer
Asked by
Jarrett
Top achievements
Rank 2
Answers by
Dobromir
Telerik team
Jarrett
Top achievements
Rank 2
Share this question
or