Search code examples
asp.netteleriktelerik-gridtelerik-mvc

How to Add Custom Columns to RadExplorer


How to Add Custom Columns to RadExplorer I Added Two Columns Date And Owner To the RadExplorer. URL For Demo.

http://demos.telerik.com/aspnet-ajax/fileexplorer/examples/applicationscenarios/customgridcolumns/defaultcs.aspx
 

Previous I am Getting FileName And Size When I added Two coloumn Headings By

 private void AddGridColumn(string name, string uniqueName, bool sortable)
          {
         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;
        Aspx_RadFileExplorer.Grid.Columns.Add(gridTemplateColumn1);
         }
        
Function For ResolveRootDirectoryAsTree 
    <pre>
     public override DirectoryItem ResolveRootDirectoryAsTree ( string xszPath )
     {
    PathPermissions zPathPermission = FullPermissions;
    if ( xszPath.Equals ( "Document/Private" ) )
    zPathPermission = PathPermissions.Read;
    else if ( xszPath.Equals ( "Document/Public" ) )
    zPathPermission = PathPermissions.Read | PathPermissions.Upload;
         return new DirectoryItem(GetName(xszPath), GetDirectoryPath(xszPath), xszPath, GetDate(xszPath), zPathPermission, GetChildFiles(xszPath), GetChildDirectories(xszPath));
   }
</pre>

Function For ResolveDirectory

    public override DirectoryItem ResolveDirectory(string xszPath )
    {
    PathPermissions zPathPermission = FullPermissions;
    if ( xszPath.Equals ( "Document/Private" ) )
    zPathPermission = PathPermissions.Read;
    else if ( xszPath.Equals ( "Document/Public" ) )
    zPathPermission = PathPermissions.Read | PathPermissions.Upload;

DirectoryItem[] zdlDirectories = GetChildDirectories ( xszPath );
                   return new DirectoryItem ( GetName ( xszPath ), EndWithSlash ( GetDirectoryPath ( xszPath ) ), string.Empty, string.Empty, zPathPermission, GetChildFiles ( xszPath ), zdlDirectories );
}
private string GetName ( string xszPath )
{
if ( xszPath == null )
{
    return string.Empty;
}
 return xszPath.Substring ( xszPath.LastIndexOf ( '/' ) + 1 );
}

In This Function I Will Get OwnerID And Date as strings LoadDocuments().How to Display Owner ID to Owner Custom Field,And Date To Date Field

        private void SafeLoadDocument ( string xszUserID )
        {
        try
        {
         DataTable zdtReturn = new DataTable();
        if ( ViewState["m_DocumentTable"] == null )
        ViewState["m_DocumentTable"] = EMSBLCRM.LoadDocuments( xszUserID );
         zdtReturn = (DataTable)ViewState["m_DocumentTable"];
         foreach (DataRow dr in zdtReturn.Rows)
         {
             double zdbFileSize = Convert.ToDouble(dr["fld_document_latest_attachment_size"]);
        string zsztest = String.Format("{0:#,##0}", zdbFileSize);
         dr["fld_document_latest_attachment_size"] = zsztest;
                             Convert.ToDouble(dr["fld_document_created_on"]);
        string date = dr["fld_document_created_on"].ToString();
        string date2 = date.Substring(0, 10);
        }
        Session["sesDocumentTable"] = ViewState["m_DocumentTable"];
        }
        catch ( Exception e )
        {
            Utilities.SendCrashEMail ( ref e );
        }
        }
        


Solution

  • Here's a link to the documentation and following is the code.

    // Add a new 'custom column for the file owner'
    GridTemplateColumn gridTemplateColumn2 = new GridTemplateColumn();
    gridTemplateColumn2.HeaderText = "Owner Name";
    gridTemplateColumn2.SortExpression = "Owner";
    gridTemplateColumn2.UniqueName = "Owner";
    gridTemplateColumn2.DataField = "Owner";
    RadFileExplorer1.Grid.Columns.Add(gridTemplateColumn2);// Add the second column
    
    //And the code for adding value for the file entry for the custom column.
    public override DirectoryItem ResolveDirectory(string path)
    {
        // Update all file items with the additional information (date, owner)
        DirectoryItem oldItem = base.ResolveDirectory(path);
        foreach (FileItem fileItem in oldItem.Files)
        {
            // Get the information from the physical file
            FileInfo fInfo = 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("\\", "\\\\");
            string ownerName = "Telerik";
            fileItem.Attributes.Add("Owner", ownerName);
        }
        return oldItem;
    }
    

    Hope this will be helpful for you.