This is a migrated thread and some comments may be shown as answers.

How to display.download a File

2 Answers 92 Views
ToolTip
This is a migrated thread and some comments may be shown as answers.
Stéphane
Top achievements
Rank 1
Stéphane asked on 18 Feb 2011, 05:14 PM

Hello,

I would like to open/download a file saved like a Blob in a database.

There is the code. But It doesn't work !

Could you help me ?

Regards,

Bernard

<
asp:Content ID="Content2" ContentPlaceHolderID="cphMenu" runat="server">

    <telerik:RadToolBar ID="toolBar" runat="server" Width="100%" AutoPostBack="True"

        OnButtonClick="toolBar_ButtonClick">

        <Items>

            ……

            <telerik:RadToolBarButton runat="server" Value="DOC" ImageUrl="~/images/DocNumeriques.gif"

                Enabled="False">

            </telerik:RadToolBarButton>

        </Items>

    </telerik:RadToolBar>

</asp:Content>

 

 

 

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

<script type="text/javascript">

function openDoc()

{

      ajaxManager = $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>");

ajaxManager.set_enableAJAX(false);

setTimeout(function()

{

   ajaxManager.set_enableAJAX(true);

}, 0);

ajaxManager.ajaxRequest();

}

</script>

</telerik:RadCodeBlock>

CODE BEHIND

 


protected
void toolBar_ButtonClick(object sender, RadToolBarEventArgs e)

 

{

 

    try

 

    {

 

            switch (e.Item.Value)

 

            {

 

                  ……

 

                  case @"DOC":

 

                ScriptManager.RegisterStartupScript(this, this.GetType(), @"openDoc", @"openDoc();"true);

 

break;

 

……

 

}

 

}

 

      catch (Exception err)

 

      {

 

            ……

 

}

 

}

 

 

 

protected void manager_AjaxRequest(object sender, AjaxRequestEventArgs e)

 

{

 

    try

 

    {

 

           Byte[] aBlob = new Byte[…];

 

            ……

 

            Response.Clear();

 

            Response.ContentType = "application/octet-stream";

 

            Response.AddHeader("Content-Disposition", "attachment; filename=" + aFileName);

 

            Response.Flush();

 

            Response.BinaryWrite(aBlob);

 

            Response.End();

 

    }

 

      catch (Exception err)

 

      {

 

        ……

 

        }

 

}

2 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 24 Feb 2011, 11:01 AM
Hi Stéphane,

It seems that openDoc() method is called too early before the ajax manager is created, please modify the following code:

ScriptManager.RegisterStartupScript(this, this.GetType(), @"openDoc", @"setTimeout(function(){ openDoc();}, 100);", true);

it fixes the issue at our side. Try it and let us know how it goes.

Greetings,
Yana
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Stéphane
Top achievements
Rank 1
answered on 24 Feb 2011, 03:43 PM
Hello Yana,

It works !

Many thanks ...

Bernard
Tags
ToolTip
Asked by
Stéphane
Top achievements
Rank 1
Answers by
Yana
Telerik team
Stéphane
Top achievements
Rank 1
Share this question
or