如何将自定义列添加到 RadExplorer
How to Add Custom Columns to RadExplorer
如何向 RadExplorer 添加自定义列我向 RadExplorer 添加了两列日期和所有者。 URL 用于演示。
http://demos.telerik.com/aspnet-ajax/fileexplorer/examples/applicationscenarios/customgridcolumns/defaultcs.aspx
Previous 当我添加两个列标题时,我得到了文件名和大小
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>
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 );
}
在此函数中,我将获取所有者 ID 和日期作为字符串 LoadDocuments()。如何向所有者自定义字段显示所有者 ID,以及日期到日期字段
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 );
}
}
这是文档的a link,下面是代码。
// 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;
}
希望对您有所帮助。
如何向 RadExplorer 添加自定义列我向 RadExplorer 添加了两列日期和所有者。 URL 用于演示。
http://demos.telerik.com/aspnet-ajax/fileexplorer/examples/applicationscenarios/customgridcolumns/defaultcs.aspx
Previous 当我添加两个列标题时,我得到了文件名和大小
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>
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 ); }
在此函数中,我将获取所有者 ID 和日期作为字符串 LoadDocuments()。如何向所有者自定义字段显示所有者 ID,以及日期到日期字段
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 ); } }
这是文档的a link,下面是代码。
// 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;
}
希望对您有所帮助。