how disable preview window when opening a file?

8 posts, 3 answers
  1. Wild
    Wild avatar
    10 posts
    Member since:
    Mar 2016

    Posted 27 Mar Link to this post

    I am handling opening file by myself in browser, but this empty, small preview window also opens when file is double-clicked.

    how to disable, hide it or close it?   I don't want to disable fileopen event though.

    thank you

  2. Answer
    Vessy
    Admin
    Vessy avatar
    1383 posts

    Posted 28 Mar Link to this post

    Hi Wild,

    Cancelling the ClientFileOpen event of the control is actually the only way to prevent the showing of an empty preview window in FileExplorer. Can you elaborate on the exact reason you do not want to do that?

    Please note that even if you are canceling the event you can use all data from its arguments in order to open the file into separate window:
    <telerik:RadFileExplorer ID="RadFileExplorer1" runat="server" EnableCopy="true" OnClientFileOpen="OnClientFileOpen">
        <Configuration ViewPaths="~/Images" DeletePaths="~/Images" UploadPaths="~/Images" />
    </telerik:RadFileExplorer>
    <script>
        function OnClientFileOpen(fileExplorer, args) {
            window.open(args.get_path(), "_blank");
            args.set_cancel(true);
        }
    </script>


    Regards,
    Vessy
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Wild
    Wild avatar
    10 posts
    Member since:
    Mar 2016

    Posted 28 Mar in reply to Vessy Link to this post

    Hi Vessy,

    problem is I am opening this file from handler.ashx, I use custom database content provider.

    Opening my file like this:

    public void ProcessRequest(HttpContext context)
    {
    Context = context;
    if (context.Request.QueryString["path"] == null)
    {
        return;
    }
    string path = Context.Server.UrlDecode(Context.Request.QueryString["path"]);
    var item = DataServer.GetItem(path);
    if (item == null) return;

    System.Diagnostics.Process.Start(item["sourcePath"].ToString());
    }
     

     

    Any way to close that preview window in OnClientFileOpen?

     

    thanks

  5. Answer
    Vessy
    Admin
    Vessy avatar
    1383 posts

    Posted 31 Mar Link to this post

    Hi Wild,

    The approach you should use is the same, with the only difference that you will need to pass the item's path to your custom handler:
    function OnClientFileOpen(fileExplorer, args) {            
        window.open("Handler.ashx?path=" + args.get_path(), "_blank");
        args.set_cancel(true);
    }

    A similar approach (with a custom handler implementation) is demonstrated in the following online demo:
    http://demos.telerik.com/aspnet-ajax/fileexplorer/examples/applicationscenarios/filteranddownloadfiles/defaultcs.aspx

    Regards,
    Vessy
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  6. Wild
    Wild avatar
    10 posts
    Member since:
    Mar 2016

    Posted 31 Mar Link to this post

    great!   the only problem is now OnClientFileOpen is called also when opening folders, and I don't want to

    why is folder treated as file?

    almost working :)

  7. Answer
    Vessy
    Admin
    Vessy avatar
    1383 posts

    Posted 01 Apr Link to this post

    Hi Wild,

    Yes, the Client FileOpen event is raised both for files and folders. You can determine the type of the opened item through its isDirectory() method:
    function OnClientFileOpen(fileExplorer, args) {
        if (!args.get_item().isDirectory()) {
            window.open("Handler.ashx?path=" + args.get_path(), "_blank");
            args.set_cancel(true);
        }
    }


    Regards,
    Vessy
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  8. Wild
    Wild avatar
    10 posts
    Member since:
    Mar 2016

    Posted 01 Apr Link to this post

    thanks a lot, works fine. BTW if I wanted to use this built in small preview window, is there any way to resize it to be bigger?
  9. Vessy
    Admin
    Vessy avatar
    1383 posts

    Posted 05 Apr Link to this post

    Hi Wild,

    Yes, you can increase the size of the file preview window in FileExplore, but it will affect the size of all dialogs in the control as well. Please note that this can be done earlier in the Page_PreRenderComplete event handler:
    protected void Page_PreRenderComplete(object sender, EventArgs e)
    {
        RadFileExplorer1.WindowManager.Width = Unit.Pixel(1000);
        RadFileExplorer1.WindowManager.Height = Unit.Pixel(1000);
    }


    Regards,
    Vessy
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017