CustomFileSystemProvider myProvider = (CustomFileSystemProvider)Session[
"myCustomFileSystemProvider"
];
myProvider.DeleteDirectory(RadFileExplorer1.TreeView.SelectedValue);
13 Answers, 1 is accepted
The issue that you are experiencing is handled by the explorer itself, that is why in order to achieve the required functionality I would recommend you to use the control's built-in functionality but not methods of the content provider.
However, the control does not offer server-side functionality to delete items, you need to handle this case on the client, thus handle the ClientDelete client-side event, e.g.:
<telerik:RadFileExplorer ID=
"RadFileExplorer1"
runat=
"server"
OnClientDelete=
"explorerDelete"
>
<Configuration ViewPaths=
"~/ROOT"
DeletePaths=
"~/ROOT"
UploadPaths=
"~/ROOT"
/>
</telerik:RadFileExplorer>
<script type=
"text/javascript"
>
function
explorerDelete(explorer, args)
{
if
(explorer.get_fileList().get_items().length == 1) {
//check if the initially deleted file is only one
var
displayedItem = explorer.get_fileList().get_items()[0];
var
currentItem = args.get_item();
if
(displayedItem.Path == currentItem.get_path()) {
//check if the deleted item is the one that is currently visible
args.set_cancel(
true
);
$telerik.toFileExplorer(explorer).deleteItem(explorer.get_currentDirectory(),
false
);
}
}
}
</script>
All the best,
Dobromir
the Telerik team

my app looks at selected files in fileexplorer and on a buttonclick moves them to a directory chosen by the user. this is all in the code behind so how do I trigger the client side delete function?
You may experience this error if you are using version of RadControls for ASP.NET AJAX prior Q1 2012. In the last version RadFileExplorer received major improvement in its client-side API and get_fileList() method is a part of this improvement. If you are not using the latest version of RadControls I would recommend you to upgrade to it.
In order to manually trigger RadFileExplorer's Delete functionality, you need to use its client-side deleteItem() method. For example if you need to trigger delete from an external button you can use the following approach:
<
telerik:RadFileExplorer
ID
=
"RadFileExplorer1"
runat
=
"server"
OnClientDelete
=
"explorerDelete"
EnableCopy
=
"true"
>
<
Configuration
ViewPaths
=
"~/ROOT"
DeletePaths
=
"~/ROOT"
UploadPaths
=
"~/ROOT"
/>
</
telerik:RadFileExplorer
>
<
asp:Button
Text
=
"Delete"
runat
=
"server"
OnClientClick
=
"deleteExplorerSelectedItem(); return false;"
/>
<
script
type
=
"text/javascript"
>
function explorerDelete(explorer, args)
{
if (explorer.get_fileList().get_items().length == 1) { //check if the initially deleted file is only one
var displayedItem = explorer.get_fileList().get_items()[0];
var currentItem = args.get_item();
if (displayedItem.Path == currentItem.get_path()) { //check if the deleted item is the one that is currently visible
args.set_cancel(true);
$telerik.toFileExplorer(explorer).deleteItem(explorer.get_currentDirectory(), false);
}
}
}
function deleteExplorerSelectedItem()
{
var explorer = $find("<%=RadFileExplorer1.ClientID %>");
var selectedItem = explorer.get_selectedItem();
if (selectedItem) {
explorer.deleteItem(selectedItem, true);
}
}
</
script
>
More detailed information regarding RadFileExplorer's Client-Side API is available in our online documentation.
Kind regards,
Dobromir
the Telerik team

Actually, we found a bug in RadFileExplorer related to the custom content providers, could you please try to modify the GetFiles() method of the content provider to provide the path as value to the Location property of the FileItem and see if the problem will be fixed?
private
FileItem[] GetFiles(
string
virtualPath)
{
List<FileItem> filesItems =
new
List<FileItem>();
string
physicalPath =
this
.GetPhysicalFromVirtualPath(virtualPath);
if
(physicalPath ==
null
)
return
null
;
List<
string
> files =
new
List<
string
>();
// The files in this folder : 'physicalPath' ;
try
{
foreach
(
string
patern
in
this
.SearchPatterns)
{
// Applied flters in the 'SearchPatterns' property;
foreach
(
string
filePath
in
Directory.GetFiles(physicalPath, patern))
{
if
(!files.Contains(filePath))
files.Add(filePath);
}
}
foreach
(
string
filePath
in
files)
{
FileInfo fileInfo =
new
FileInfo(filePath);
string
url = ItemHandlerPath +
"?path="
+ virtualPath + fileInfo.Name;
FileItem fileItem =
new
FileItem(fileInfo.Name,
fileInfo.Extension,
fileInfo.Length,
virtualPath + fileInfo.Name,
url,
null
,
GetPermissions(filePath)
);
filesItems.Add(fileItem);
}
}
catch
(IOException)
{
// The parent directory is moved or deleted
}
return
filesItems.ToArray();
}
Regarding the second issue, I am not quite sure I understand it? Could you please elaborate on this?
All the best,
Dobromir
the Telerik team

CustomFileSystemProvider myProvider = (CustomFileSystemProvider)Session["myCustomFileSystemProvider"];
myProvider.DeleteDirectory(RadFileExplorer1.TreeView.SelectedValue);
would change the internal path in RadFileExplorer to reflex that the path no longer exist, the answer is sadly no. If there was a way from the code behind to do that would be great.
Like I said I'm on Q3 2011 and cant upgrade to Q1 2012 because certain CSS issues showed up after upgrading. I probably should report that as a seperate bug.
The bug that I mentioned in my previous answer was introduced in the latest version and is related to the content providers.
Regarding the original problem, unfortunately, it is not possible to achieve the required functionality with version of RadFileExplorer prior Q1 2012 because the old ClientSide API of the control is missing key features to achieve this.
Could you please elaborate on the CSS issues that you experiece with RadControls ver.Q1 2012, so we can try to provide workaround for them?
Dobromir
the Telerik team

.MyButton
{
background: url('images/glass.png') 0 0 no-repeat !important;
}
<
telerik:RadTextBox
ID
=
"SearchTextBox1"
runat
=
"server"
EmptyMessage
=
"System Search"
SelectionOnFocus
=
"SelectAll"
ShowButton
=
"true"
ButtonCssClass
=
"MyButton"
onkeyup
=
"KeyPressed(event)"
>
<
ClientEvents
OnButtonClick
=
"JS_searchGlobal_Click"
/>
</
telerik:RadTextBox
>
The difference in the RadInput between version that you are using and the latest official version (Q1 2012) is due to the fact that in the last version the default value of the EnableSingleInputRendering property is changed from True to False. To have the same behavior as in the previous version you can simply set this property to True.
You can find more information regarding this feature of RadInput in the following help article:
Single Input Rendering Mode
Regards,
Dobromir
the Telerik team

Yes Fred, you are correct, the default value is True and should be set to false. Please accept my sincere apologies for the misleading information.
Kind regards,
Dobromir
the Telerik team

var explorer = $find("<%=RadFileExplorer1.ClientID %>");
var currentDir = explorer.get_currentDirectory();
var filesCnt = explorer.get_fileList().get_items().length;
if (filesCnt == 0 && deleteThis == currentDir) {
$telerik.toFileExplorer(explorer).deleteItem(explorer.get_currentDirectory(), true);
deleteThis = "";
}
