PDA

View Full Version : [CLOSED] Treepanel / leaf click / download file



tMp
May 01, 2014, 9:32 AM
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.

Daniil
May 01, 2014, 10:36 PM
Hi @tMp,

Yes, it needs to set up

formProxyArg: "form1"


<form id="form1" style="display: none;"></form>

tMp
May 02, 2014, 7:38 AM
@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.

Daniil
May 02, 2014, 7:01 PM
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'

Daniil
May 02, 2014, 7:58 PM
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.

tMp
May 02, 2014, 8:18 PM
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.

Daniil
May 05, 2014, 5:50 AM
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?

See #6:
http://examples2.ext.net/#/Events/DirectMethods/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.

tMp
May 06, 2014, 2:08 PM
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.

Daniil
May 06, 2014, 2:49 PM
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...