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