Dec 26, 2008, 12:58 PM
[CLOSED] Open file from grid
Hi all,
I have to download/open file from grid. I click in ID cell of the record grid to get the ID of my business object and then server side open file. The file is directly saved in DB. I saw example exporting grid via AjaxEvent, so I did the same.
The problem is that sometimes I successfully download file, sometimes get Error AjaxEvent!
Here is my code:
Second: I tried different CellClick properties, where can I find docs about Type, IsUpload, Buffer, CleanRequest ect. properties?
Thanx
Matteo
I have to download/open file from grid. I click in ID cell of the record grid to get the ID of my business object and then server side open file. The file is directly saved in DB. I saw example exporting grid via AjaxEvent, so I did the same.
The problem is that sometimes I successfully download file, sometimes get Error AjaxEvent!
Here is my code:
<AjaxEvents>
<CellClick OnEvent="OpenDoc" IsUpload="true" Failure="Ext.MessageBox.alert('Load failed', 'Error during ajax event!');">
<ExtraParams>
<ext:Parameter Name="idDoc" Value="params[0].getStore().getAt(params[1]).id" Mode="Raw" />
</ExtraParams>
</CellClick>
</AjaxEvents>
Code behind
// inside AjaxEvent block
...
Response.Clear();
object _objDoc = _documento.FileDocumento;
if (_objDoc == null) return;
byte[] _document = (byte[])_objDoc;
object _objContentType = _documento.ContentTypeDoc;
if (_objContentType == null) return;
object _objNomeDoc = _documento.NomeDocumento;
if (_objNomeDoc == null) return;
using (MemoryStream stream = new MemoryStream())
{
stream.Write(_document, 0, _document.Length);
byte[] buffer = stream.GetBuffer();
Response.Buffer = false;
Response.AppendHeader("Content-Type", _objContentType.ToString());
Response.AppendHeader("Content-Transfer-Encoding", "binary");
Response.AppendHeader("Content-Disposition", "attachment; filename=" + _objNomeDoc.ToString());
Response.BinaryWrite(buffer);
}
Response.End();
First: is my code wrong? Do I miss anything?Second: I tried different CellClick properties, where can I find docs about Type, IsUpload, Buffer, CleanRequest ect. properties?
Thanx
Matteo