Hi guys!
What is the purpose of FileItem.Extension property?
I'd like to show files without extensions with proper icons. So my original thought was to use FileItem.Extension but after debugging I have discovered that only file extension is used as additional class name.
Is this an issue that Extension property is ignored and how can I show files with proper icons?
What is the purpose of FileItem.Extension property?
I'd like to show files without extensions with proper icons. So my original thought was to use FileItem.Extension but after debugging I have discovered that only file extension is used as additional class name.
Is this an issue that Extension property is ignored and how can I show files with proper icons?
6 Answers, 1 is accepted
0
Hello Michael,
My suggestion is to add custom columns as in the "Add Custom Columns" example - all you need to do is to add a column with filename(without file extension) and hide the original fileName column. The code below illustrates how to show files without their extensions:.
Codebehind:
Please note that I'm using fInfo.Extension property and everything is fine.
Hope this helps.
Best wishes,
Petio Petkov
the Telerik team
My suggestion is to add custom columns as in the "Add Custom Columns" example - all you need to do is to add a column with filename(without file extension) and hide the original fileName column. The code below illustrates how to show files without their extensions:.
Codebehind:
public partial class DefaultCS : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//be sure to set content provider first before doing anything involving paths (e.g. set InitialPath)
RadFileExplorer1.Configuration.ContentProviderTypeName = typeof(CustomColumnsContentProvider).AssemblyQualifiedName;
RadFileExplorer1.InitialPath = Page.ResolveUrl("~/FileExplorer/Examples/Default/Images/Northwind/Customers/");
}
AddDateAndOwnerColumns();
}
private void AddGridColumn(string name, string uniqueName, bool sortable)
{
// 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;
RadFileExplorer1.Grid.Columns.Add(gridTemplateColumn1);
}
private void AddDateAndOwnerColumns()
{
AddGridColumn("Creation Date", "Date", true);
AddGridColumn("Owner Name", "Owner", false);
AddGridColumn("FileWithoutExt", "FileWithoutExt", false);
}
protected void RadFileExplorer1_ExplorerPopulated(object sender, RadFileExplorerPopulatedEventArgs e)
{
//implement sorting for the custom Date column
string sortingColumn = e.SortColumnName;
if (sortingColumn == "Date")
{
DateComparer dc = new DateComparer();
e.List.Sort(dc);
if (e.SortDirection.IndexOf("DESC") != -1)
{
//reverse order
e.List.Reverse();
}
}
}
public class DateComparer : IComparer<
FileBrowserItem
>
{
int IComparer<
FileBrowserItem
>.Compare(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 class CustomColumnsContentProvider : FileSystemContentProvider
{
public CustomColumnsContentProvider(HttpContext context, string[] searchPatterns, string[] viewPaths, string[] uploadPaths, string[] deletePaths, string selectedUrl, string selectedItemTag)
: base(context, searchPatterns, viewPaths, uploadPaths, deletePaths, selectedUrl, selectedItemTag)
{
// Declaring a constructor is required when creating a custom content provider class
}
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());
fileItem.Attributes.Add("FileWithoutExt", fInfo.Name.Remove(fInfo.Name.LastIndexOf(fInfo.Extension)) );
// 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;
}
public override DirectoryItem ResolveRootDirectoryAsTree(string path)
{
// Update all directory items with the additional information (date, owner)
DirectoryItem oldItem = base.ResolveRootDirectoryAsTree(path);
foreach (DirectoryItem dirItem in oldItem.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("Date", dInfo.LastWriteTime.ToString());
//Type targetType = typeof(System.Security.Principal.NTAccount);
//string value = dInfo.GetAccessControl().GetOwner(targetType).Value.Replace("\\", "\\\\");
string ownerName = "Telerik";
dirItem.Attributes.Add("Owner", ownerName);
}
return oldItem;
}
}
}
}
Hope this helps.
Best wishes,
Petio Petkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Michael
Top achievements
Rank 1
answered on 02 Aug 2010, 08:05 AM
Hi Petio!
Ok, thank you. I'll try this approach.
Ok, thank you. I'll try this approach.
0
grant
Top achievements
Rank 1
answered on 18 Aug 2010, 06:45 AM
Hi Petio
it's a great direction you provide.
however, Could you tell me how to add image icon before the name?
thank you very much!
it's a great direction you provide.
however, Could you tell me how to add image icon before the name?
thank you very much!
0
grant
Top achievements
Rank 1
answered on 18 Aug 2010, 06:48 AM
hi Michael
have you solve your problem?
the problem is to show files without extensions with proper icons.
if yes, could you tell me how?
i have the same problem. it really freak me out.
thank you very much!
have you solve your problem?
the problem is to show files without extensions with proper icons.
if yes, could you tell me how?
i have the same problem. it really freak me out.
thank you very much!
0
Michael
Top achievements
Rank 1
answered on 18 Aug 2010, 08:56 AM
Hi grant!
I was scared by the number of lines of code proposed by Petio, so decided to show files with extensions.
If file name includes extension- everything works fine and I can see proper icons.
I was scared by the number of lines of code proposed by Petio, so decided to show files with extensions.
If file name includes extension- everything works fine and I can see proper icons.
0
Hello Guys,
In case that you need to override the icon for the unknown files (used when a file does not have any extension, for example) then you need to change the sprite fileextensionsprites.png. (icon number 22). More details how to do that can be found in this forum thread.
Kind regards,
Fiko
the Telerik team
In case that you need to override the icon for the unknown files (used when a file does not have any extension, for example) then you need to change the sprite fileextensionsprites.png. (icon number 22). More details how to do that can be found in this forum thread.
Kind regards,
Fiko
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items