[CLOSED] Treepanel / leaf click / download file

  1. #1

    [CLOSED] Treepanel / leaf click / download file

    Hi

    I am having some trouble downloading a file on a click on a treepanel leaf.

    What I have so far is the listener on the panel
    <Listeners>
                    <ItemClick Handler="if (record.data.leaf) { App.direct.onDownload({buffer:300, isUpload:true, method:GET}); }"></ItemClick>
                </Listeners>
    do I need this formProxyArg? And if yes, what if I have a treepanel instead of a form?

    and the direct method
    [DirectMethod]
        public void onDownload()
        {
            Response.Clear();
            Response.ContentType = "application/octet-stream";
    
            //Response.ContentEncoding = System.Text.Encoding.Default;
            Response.AddHeader("content-disposition", "filename=" + "test.pdf");
            Response.TransmitFile(@"c:\\temp\test.pdf");
            Response.End();
        }
    Thank you very much for your insight.
    Last edited by Daniil; May 13, 2014 at 4:16 PM. Reason: [CLOSED]
  2. #2
    Hi @tMp,

    Yes, it needs to set up
    formProxyArg: "form1"
    <form id="form1" style="display: none;"></form>
  3. #3
    @Daniil

    Thanks, unfortunately I am still fighting. Somehow I am missing something:

    <%@ Page Language="C#" %>
     
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
     
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                try
                {
    
                }
                catch (Exception err)
                {
                    throw err;
                }
            }
        }
    
        // load new node data
        protected void NodeLoad_ReadData(object sender, NodeLoadEventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(e.NodeID))
                {
                    string parentDirectory = e.NodeID;
                    foreach (var directory in System.IO.Directory.GetDirectories(parentDirectory))
                    {
                        string directoryname = System.IO.Path.GetFileName(directory);
                        Node asyncNode = new Node();
                        asyncNode.Text = directoryname;
                        asyncNode.NodeID = directory.ToString();
                        e.Nodes.Add(asyncNode);
                    }
    
                    foreach (var file in System.IO.Directory.GetFiles(parentDirectory))
                    {
                        string filename = System.IO.Path.GetFileName(file);
                        Node treeNode = new Node();
                        treeNode.Text = filename;
                        treeNode.NodeID = file.ToString();
                        treeNode.Leaf = true;
                        e.Nodes.Add(treeNode);
                    }
                }
            }
            catch (Exception err)
            {
                string errMessage = err.Message;
                X.Msg.Alert("Fehlermeldung", "File: downloads.aspx.cs<br>Function: NodeLoad_ReadData<br>Message: " + errMessage).Show();
            }
        }
    
        // file download
        [DirectMethod]
        public void onDownload()
        {
            Response.Clear();
    
            Response.ContentType = "application/octet-stream";
    
            //Please rename test file in c:\temp accordingly
            string testFile = "mr.m";
            Response.AddHeader("content-disposition", "filename=" + testFile);
            Response.TransmitFile(@"c:\\temp\" + testFile);
            Response.End();
        }
     
    </script>
     
    <!DOCTYPE html>
     
    <html>
    <head id="Head" runat="server">
        <title></title>
     
    </head>
    <body>
        <form id="Form" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" Locale="de-CH" />
     
            <ext:TreePanel runat="server" ID="TP_DOWNLOADS" Title="Dokument-Vorlagen" Height="700">
                <Store>
                    <ext:TreeStore ID="TreeStore" runat="server" OnReadData="NodeLoad_ReadData">
                        <Proxy>
                            <ext:PageProxy></ext:PageProxy>
                        </Proxy>
                    </ext:TreeStore>
                </Store>
                <Root>
                    <ext:Node NodeID="\\localhost\temp" Text="temp"></ext:Node>
                </Root>
                <Listeners>
                    <ItemClick Handler="if (record.data.leaf) { App.direct.onDownload({buffer:300, isUpload:true, method:GET, formProxyArg:'hiddenForm'}); }"></ItemClick>
                </Listeners>
            </ext:TreePanel>
            <ext:FormPanel runat="server" ID="hiddenForm" StyleSpec="display:none;"></ext:FormPanel>
        </form>
    </body>
    </html>
    When I try it with an empty App.direct.onDownload() the onDownload gets called but no file download. As soon as I but the {}-stuff in not even the onDownload gets called. Or is there a better way to download the file a user click on?

    Thank you very much.
  4. #4
    Currently, there is a JavaScript error: "GET is not defined". You should define it as a string.
    method: 'GET'
    Also you don't need this
    <ext:FormPanel runat="server" ID="hiddenForm" StyleSpec="display:none;"></ext:FormPanel>
    as you already have
    <form id="Form" runat="server">
    So:
    formProxyArg:'Form'
  5. #5
    Btw, this setting doesn't make sense:
    method: 'GET'
    because POST will be forced, it is required for download.

    Also please use:
    formId:'Form'
    instead of
    formProxyArg:'Form'
    I forgot that it has been renamed.
  6. #6
    Hi Daniil,

    thank you very much. It seems to work. I really have to take a look at javascript debugging :(

    I omitted the "method" now entirely. What about the buffer? Is it nescessary? Why excatly 300? Can I read somewhere what this kind of config stuff is and what I can/must/shouldn't use?

    best regards.
  7. #7
    Quote Originally Posted by tMp View Post
    I omitted the "method" now entirely. What about the buffer? Is it nescessary? Why excatly 300?

    Quote Originally Posted by tMp View Post
    Can I read somewhere what this kind of config stuff is and what I can/must/shouldn't use?
    See #6:
    https://examples2.ext.net/#/Events/D...hods/Overview/

    It explains the config options you can use. You decide you should/must use it or not:) I don't think there is a doc article more about that.
  8. #8
    Nice! Pefect. Thank you. Don't know why I have never seen that part... ;)

    PS: Haven't found the buffer option yet... I must be blind... but I am still looking for it.
    Last edited by tMp; May 06, 2014 at 1:13 PM.
  9. #9
    Quote Originally Posted by tMp View Post
    PS: Haven't found the buffer option yet... I must be blind... but I am still looking for it.
    Hmm, I guess there is no a buffer option for a DirectMethod...

Similar Threads

  1. [CLOSED] How to get Leaf ID from TreePanel Node.
    By extnetuser in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Apr 25, 2013, 4:19 PM
  2. [CLOSED] Not able to drag drop leaf to leaf in TreeGrid
    By legaldiscovery in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 15, 2011, 1:47 PM
  3. [CLOSED] Download file in grid command column click
    By Pablo_Azevedo in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Aug 31, 2010, 12:08 PM
  4. [CLOSED] [1.0] How to make only leaf nodes clickable in TreePanel
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Aug 20, 2010, 3:26 PM
  5. Default TreePanel Leaf Icon
    By t0ny in forum 1.x Help
    Replies: 1
    Last Post: Jan 06, 2009, 10:57 AM

Posting Permissions