Delete folder when empty

14 posts, 0 answers
  1. Fred
    Fred avatar
    53 posts
    Member since:
    Aug 2011

    Posted 14 Feb 2012 Link to this post

    Im using FileExplorer to display a directory in which the user can "file away" into our document management program. A request came in for us to delete the directory if it becomes empty. This is no problem but fileexplorer is still pointing at the directory that has now been removed. Any suggestions? Im using CustomFileSystemProvider as outlined in http://www.telerik.com/support/kb/aspnet-ajax/editor/physical-paths-and-different-content-types.aspx for the deletion of the directory i've tried several things including

    CustomFileSystemProvider myProvider = (CustomFileSystemProvider)Session["myCustomFileSystemProvider"];
    myProvider.DeleteDirectory(RadFileExplorer1.TreeView.SelectedValue);
  2. Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 16 Feb 2012 Link to this post

    Hi Fred,

    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
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Fred
    Fred avatar
    53 posts
    Member since:
    Aug 2011

    Posted 16 Feb 2012 Link to this post

    I used your code and got this error "Microsoft JScript runtime error: Object doesn't support property or method 'get_fileList'"

    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?
  5. Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 20 Feb 2012 Link to this post

    Hi Fred,

    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
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  6. Fred
    Fred avatar
    53 posts
    Member since:
    Aug 2011

    Posted 20 Feb 2012 Link to this post

    I upgraded but it caused a series of problems and UI ugliness. I was getting back from fileexplorer the virtual path where I was getting a physical path before. That was a big problem and where I was able to have a custom button in my RadTextBox by using a ButtonCssClass to override the skin no longer works. So I could not test this so called solution.
  7. Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 22 Feb 2012 Link to this post

    Hi Fred,

    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
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  8. Fred
    Fred avatar
    53 posts
    Member since:
    Aug 2011

    Posted 22 Feb 2012 Link to this post

    if this is going back to the original problem where I thought

    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. 

  9. Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 27 Feb 2012 Link to this post

    Hi Fred,

    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?

    Kind regards,
    Dobromir
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  10. Fred
    Fred avatar
    53 posts
    Member since:
    Aug 2011

    Posted 27 Feb 2012 Link to this post

    The CSS problem. This code produces the attached results. before.png is the v.2011.3.1115.40 and after.PNG is the v.2012.1.215.40. what it looks like is happening is that the skin is overiding the MyButton css
    .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>
  11. Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 29 Feb 2012 Link to this post

    Hi Fred,

    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
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  12. Fred
    Fred avatar
    53 posts
    Member since:
    Aug 2011

    Posted 29 Feb 2012 Link to this post

    what worked was setting it to false
  13. Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 29 Feb 2012 Link to this post


    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
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  14. Fred
    Fred avatar
    53 posts
    Member since:
    Aug 2011

    Posted 10 May 2012 Link to this post

    so we finnaly updated telerik to the latest version and in testing out this code the .deleteitem is not deleting the directory. Is there something i'm forgetting to do in this statement? The variables are all correct and it is executing the statement.

    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 = "";
    }
  15. Fred
    Fred avatar
    53 posts
    Member since:
    Aug 2011

    Posted 11 May 2012 Link to this post

    nevermind found the problem
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017