How to display.download a File

3 posts, 0 answers
  1. Stéphane
    Stéphane avatar
    5 posts
    Member since:
    Sep 2012

    Posted 18 Feb 2011 Link to this post

    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. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 24 Feb 2011 Link to this post

    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!
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Stéphane
    Stéphane avatar
    5 posts
    Member since:
    Sep 2012

    Posted 24 Feb 2011 Link to this post

    Hello Yana,

    It works !

    Many thanks ...

    Bernard
Back to Top