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

CREATION DATE not showing when an custom COLUMN is added to the RAD FILE EXPLORER

3 Answers 278 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Ajay
Top achievements
Rank 2
Ajay asked on 21 Oct 2009, 11:31 AM
Hi Telerik !

I have added an TWO COLUMNS on to my GRID CONTEXT MENU(using your sample code for how to Add Custom Column).

Created Date & Modified Date are the two customs columns that I have added on to the GRID CONTEXT MENU.

Iam not able to get the value against  CREATED DATE in the GRID CONTEXT MENU, though I have used the CODE that you have mentioned (in your samples).

Below is the vode that I have been using in my .CS file :-

using System;  
using System.Collections;  
using System.Data;  
using System.Configuration;  
using System.Drawing;  
using System.Drawing.Imaging;  
using System.IO;  
using System.Web;  
using System.Collections.Generic;  
using Telerik.Web.UI.Widgets;  
using Telerik.Web.UI;  
using System.Data.SqlClient;  
using System.Web.UI.WebControls;  
 
public partial class DocumentManagementSystem : System.Web.UI.Page  
{  
 
    protected void Page_Load(object sender, EventArgs e)  
    {  
        //DocumentsRadFileExplorer.WindowManager.ReloadOnShow = true;   
          
        GetMappedPath GMP = new GetMappedPath();  
 
        Dictionary<string, string> mappedPathsInConfigFile = GMP.GetMappingsFromConfigFile();  
 
        string DocumentPath = "";  
        foreach (KeyValuePair<string, string> mappedPath in mappedPathsInConfigFile)  
        {  
            DocumentPath = mappedPath.Value.Replace("/", "\\");  
        }  
 
        string VirtualPath = Request["__EVENTARGUMENT"];  
        string EventTarget = Request["__EVENTTARGET"];  
        if (EventTarget == "Archive")  
        {  
            if (VirtualPath.LastIndexOf("/") + 1 == VirtualPath.Length)  
            {  
                Archive(VirtualPath, "Folder",DocumentPath );  
            }  
            else  
            {  
                Archive(VirtualPath, "File",DocumentPath );  
            }  
        }  
 
        if (!IsPostBack)  
        {  
            string[] viewPaths = new string[] { DocumentPath };  
            string[] uploadPaths = new string[] { DocumentPath };  
            string[] deletePaths = new string[] { DocumentPath };  
 
            DocumentsRadFileExplorer.Configuration.ContentProviderTypeName = typeof(CustomFileSystemProvider).AssemblyQualifiedName;  
            DocumentsRadFileExplorer.Configuration.ViewPaths = viewPaths;  
            DocumentsRadFileExplorer.Configuration.UploadPaths = uploadPaths;  
            DocumentsRadFileExplorer.Configuration.DeletePaths = deletePaths;  
 
            AddCreatedAndModifiedDate();  
          
        }  
       
      
          
 
 
 
        //if you want the custom context menu item to be visible in the grid as well  
         
        if (!IsPostBack)  
        {  
            //context menu item  
            RadMenuItem customMenuOption = new RadMenuItem("Archive");  
            customMenuOption.PostBack = false;  
            customMenuOption.Value = "Archive";  
            if (DocumentsRadFileExplorer.TreeView.ContextMenus[0].Items.FindItemByText("Archive") == null)  
            {  
                DocumentsRadFileExplorer.TreeView.ContextMenus[0].Items.Add(customMenuOption);  
 
            }  
 
            DocumentsRadFileExplorer.GridContextMenu.Items.Add(customMenuOption.Clone());  
            DocumentsRadFileExplorer.TreeView.OnClientContextMenuItemClicked = "treeContextMenuClicked";  
 
              
        }  
 
    }  
 
 
 
    private void AddGridColumn(string name, string uniqueName, bool sortable)  
    {  
        //remove first if grid has a column with that name  
        //RemoveGridColumn(uniqueName);  
        // Add a new column with the specified name  
        GridTemplateColumn gridTemplateColumn1 = new GridTemplateColumn();  
        gridTemplateColumn1.HeaderText = name;  
        if (sortable)  
        {  
            gridTemplateColumn1.SortExpression = uniqueName;  
            gridTemplateColumn1.UniqueName = uniqueName;  
            gridTemplateColumn1.DataField = uniqueName;  
              
        }  
 
        DocumentsRadFileExplorer.Grid.Columns.Add(gridTemplateColumn1);  
    }  
 
    private void AddCreatedAndModifiedDate()  
    {  
        AddGridColumn("Created Date", "Date", true);  
        AddGridColumn("Modified Date", "Date", true);  
 
 
    }  
 
    private static int DateComparer(FileBrowserItem item1, FileBrowserItem item2)  
    {  
        //treat folders separate from files  
        DateTime date1 = DateTime.Parse(item1.Attributes["Date"]);  
        DateTime date2 = DateTime.Parse(item2.Attributes["Date"]);  
        if (item1 is DirectoryItem)  
        {  
            if (item2 is DirectoryItem)  
            {  
                return DateTime.Compare(date1, date2);  
            }  
            else  
            {  
                return -1;  
            }  
        }  
        else  
        {  
            if (item2 is DirectoryItem)  
            {  
                return 1;  
            }  
            else  
            {  
                return DateTime.Compare(date1, date2);  
            }  
        }  
    }  
 
    public void Archive(string VirtualPath, string DocType, string DocumentPath)  
    {  
        string physicalTargetPath = DocumentPath.Substring(0,DocumentPath.IndexOf("SharedDocument")).Replace("\\","/") + VirtualPath;  
        if (DocType == "Folder")  
            FileSystem.ArchiveFolder(physicalTargetPath, VirtualPath);  
        else  
            FileSystem.ArchiveFile(physicalTargetPath, VirtualPath);  
 
        Response.Redirect("DocumentManagementSystem.aspx");  
    }  
 
    protected void DocumentsRadFileExplorer_GridPopulated(object sender, RadFileExplorerGridEventArgs e)  
    {  
        //implement sorting for the custom Date column  
        string CreatedDateColumn = e.SortColumnName;  
        string ModifiedDatesortingColumn = e.SortColumnName;  
        if (CreatedDateColumn == "Created Date")  
        {  
            e.List.Sort(DateComparer);  
            if (e.SortDirection.IndexOf("DESC") != -1)  
            {  
                //reverse order  
                e.List.Reverse();  
            }  
 
        }  
 
 
        if (ModifiedDatesortingColumn == "Modified Date")  
        {  
            e.List.Sort(DateComparer);  
            if (e.SortDirection.IndexOf("DESC") != -1)  
            {  
                //reverse order  
                e.List.Reverse();  
            }  
        }  
 
    }  
 
 
    //public class CustomColumnsContentProvider : FileSystemContentProvider  
    //{  
 
 
    //}  
 
 
}  
 

While for CUSTOMCOLUMNSCONTENT PROVIDER , I have used the code in the separate file as shown below :-
using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Web;  
using Telerik.Web.UI.Widgets;  
using System.Configuration;  
using System.IO;  
using System.Security.Permissions;  
using System.Security;  
using System.Xml;  
using System.Text.RegularExpressions;  
 
 
/// <summary> 
/// Summary description for CustomFileSistemProvider  
/// </summary> 
public class CustomFileSystemProvider : FileBrowserContentProvider  
{  
    GetMappedPath GMP = new GetMappedPath();  
    private string _itemHandlerPath;  
    public string ItemHandlerPath  
    {  
        get  
        {  
            return this._itemHandlerPath;  
        }  
    }  
 
    private PathPermissions fullPermissions = PathPermissions.Read | PathPermissions.Delete | PathPermissions.Upload;  
    private Dictionary<string, string> mappedPathsInConfigFile;  
 
    /// <summary> 
    /// Returns the mappings from the configuration file ;   
    /// </summary> 
    public Dictionary<string, string> MappedPaths  
    {  
        get { return mappedPathsInConfigFile; }  
    }  
 
    public CustomFileSystemProvider(HttpContext context, string[] searchPatterns, string[] viewPaths, string[] uploadPaths, string[] deletePaths, string selectedUrl, string selectedItemTag)  
        :  
        base(context, searchPatterns, viewPaths, uploadPaths, deletePaths, selectedUrl, selectedItemTag)  
    {  
        // The paths look like "C:\Foder_1\Folder_2" or "C:\Foder_1\Folder_2\"   ;  
        this.mappedPathsInConfigFile = GMP.GetMappingsFromConfigFile(); ;  
        this._itemHandlerPath = GMP.GetPathToGenericHandler();  
    }  
 
    public override DirectoryItem ResolveRootDirectoryAsTree(string path)  
    {  
        string physicalPath;  
        string virtualPath = string.Empty;  
 
        if (this.IsPhysicalPath(path))  
        {// The path is a physical path ;  
            physicalPath = path;  
 
            foreach (KeyValuePair<string, string> mappedPath in MappedPaths)  
            {  
                // Check whether a mapping exists for the current physical paths ;  
                if (GMP.AddSlashAtEndOfPhysicalPath(physicalPath).ToLower().StartsWith(mappedPath.Value.ToLower()))  
                {// Exists   
                    virtualPath = Regex.Replace(GMP.AddSlashAtEndOfPhysicalPath(physicalPath), Regex.Escape(mappedPath.Value), mappedPath.Key, RegexOptions.IgnoreCase);  
                    virtualPathvirtualPath = virtualPath.Replace('\\', '/');  
                    virtualPath = GMP.AddSlashAtEndOfVirtualPath(virtualPath);  
                    break;// Exit the 'foreach' loop ;  
                }  
            }  
 
            // Mappind does not exist ;  
        }  
        else  
        {// Virtual path ;  
            virtualPath = GMP.AddSlashAtEndOfVirtualPath(path);  
            physicalPath = this.GetPhysicalFromVirtualPath(path);  
            if (physicalPath == null)  
                return null;  
        }  
 
        DirectoryItem result = new DirectoryItem(this.GetDirectoryName(physicalPath), string.Empty, virtualPath, string.Empty, fullPermissions, null, GetDirectories(virtualPath));  
        foreach (DirectoryItem dirItem in result.Directories)  
        {  
            // Get the information from the physical directory  
            DirectoryInfo dInfo = 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("Created Date", dInfo.LastWriteTime.ToString());  
            dirItem.Attributes.Add("Modified Date", dInfo.LastAccessTime.ToString());  
             
        }  
 
 
        return result;  
    }  
 
    public override DirectoryItem ResolveDirectory(string virtualPath)  
    {  
        string physicalPath;  
        physicalPath = this.GetPhysicalFromVirtualPath(virtualPath);  
 
        if (physicalPath == null)  
            return null;  
 
        DirectoryItem result = new DirectoryItem(this.GetDirectoryName(physicalPath), virtualPath, virtualPath, virtualPath, fullPermissions, GetFiles(virtualPath), null);  
 
        foreach (FileItem fileItem in result.Files)  
        {  
            // Get the information from the physical file  
            FileInfo fInfo = new FileInfo(Context.Server.MapPath(VirtualPathUtility.AppendTrailingSlash(result.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("Created Date", fInfo.CreationTime.ToString());  
            fileItem.Attributes.Add("Modified Date", fInfo.CreationTime.ToString());  
 
            // Type targetType = typeof(System.Security.Principal.NTAccount);  
            // string value = fInfo.GetAccessControl().GetOwner(targetType).Value.Replace("\\", "\\\\");  
            //string ownerName = "Telerik";  
            //fileItem.Attributes.Add("Owner", ownerName);  
        }  
 
 
 
        return result;  
    } 
My application does not return any error.
I dont know where is Iam doing mistake ???

Please help ??

Ajay Jamwal

 

3 Answers, 1 is accepted

Sort by
0
Fiko
Telerik team
answered on 23 Oct 2009, 03:22 PM
 Hello Ajay,

I am sorry but I cannot reproduce the scenario on our side. Could you, please, open a new support ticket and send me a simple running application which demonstrates your scenario (including the JavaScript code used)? I will take a closer look at your code, test it on my side, investigate the issues and do my best to help you. Also please provide a detailed explanation of the desired behavior, because I am not quite sure that I understood your requirements based on the information we have now.
Additionally, the RadFileExplorer's GridPopulated event does not exist in the official release of the control. This event is renamed to ExplorerPopulated. If you use an internal build, I recommend you update to the latest official release - Q2 2009 SP1.


Greetings,
Fiko
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Anu
Top achievements
Rank 1
answered on 12 Sep 2011, 12:22 PM
Hi,

We are using radEditor in our sharepoint 2010 enviroment.  RadEditor has an 'Image Manager' button which opens up the radfileExplorer. This file explorer only shows 'FileName' and 'Size' in the grid. I would also like to add' Created Date' as an extra column here so that the users can sort the files based on the created date. This will be very useful when there are 1000s of files in the folder. Can someone kindly help me please?

Many thanks,

Anu
0
Rumen
Telerik team
answered on 14 Sep 2011, 01:03 PM
Hello Anu,

Please, see my response in this forum thread: Show File Last Modified Date.

Kind regards,
Rumen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
FileExplorer
Asked by
Ajay
Top achievements
Rank 2
Answers by
Fiko
Telerik team
Anu
Top achievements
Rank 1
Rumen
Telerik team
Share this question
or