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

download a file from ajaxified controll

4 Answers 237 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Mohammad
Top achievements
Rank 1
Mohammad asked on 29 Apr 2013, 08:48 AM
Dears , 
i am trying to download a file from ajaxified control , my problem is the file is saved in server network path ex(//sharedFile/Folder/File.extention).
i tried the below link but it did not work with no errors occurred
http://www.telerik.com/help/aspnet-ajax/ajax-download.html

any idea how is can be done ?!

4 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 01 May 2013, 12:36 PM
Hello Mohammad,

Could you please share your page markup as well as the related code behind so that we could investigate on your implementation and advise you further?

Greetings,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Mohammad
Top achievements
Rank 1
answered on 05 May 2013, 07:56 AM
hello maria 
sorry for late replay but i was in vacation ,, 

I created new solution just to isolate any other issue becuase i am working in sharepoint 2010 enviroment,, i got new error ,

HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Detailed Error Information:
Module   IIS Web Core
Notification   MapRequestHandler
Handler   StaticFile
Error Code   0x80070002
Requested URL   http://localhost:17360/SERV-BAKRITMSFiles81system1.pdf
Physical Path   C:\Projects\Delete\WebApplication1\WebApplication1\SERV-BAKRITMSFiles81system1.pdf
Logon Method   Anonymous
Logon User   Anonymous
Request Tracing Directory

here is the new code ,, 

<
form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
        <div>
            <div id="Div1" runat="server">
                <radscriptblock id="RadScriptBlock1" runat="server">
<script language="javascript" type="text/javascript">
 
    function OnClientBlurHandler(sender, eventArgs) {
        var textInTheCombo = sender.get_text();
        var item = sender.findItemByText(textInTheCombo);
        //if there is no item with that text
        if (!item) {
            sender.set_text("");
        }
    }
 
</script>
<script language="javascript" type="text/javascript">
 
 
    function AddNewFields(radUpload, args) {
        var FildNameLable = 'neField';
        var curLiEl = args.get_row();
        var firstInput = curLiEl.getElementsByTagName("input")[0];
        var input = CreateInput("Title", "text");
        input.className = "copyOfRADTextCSS";
        input.id = input.name = radUpload.getID(input.name);
        var label = CreateLabel(FildNameLable, input.id);
        var fileInputSpan = curLiEl.getElementsByTagName("span")[0];
        var firstNode = curLiEl.childNodes[0];
        curLiEl.insertBefore(label, fileInputSpan.nextSibling);
        curLiEl.insertBefore(input, label.nextSibling);
    }
 
    function CreateLabel(text, associatedControlId) {
        var label = document.createElement("label");
        label.innerHTML = text;
        label.setAttribute("for", associatedControlId);
        label.style.fontSize = 12;
 
        return label;
    }
    function CreateInput(inputName, type) {
        var input = document.createElement("input");
        input.type = type;
        input.name = inputName;
        return input;
    }
    function ConfirmMessage(MessageID) {
        var messageBody = '';
        if (MessageID == "TaskParticipateDelete")
            messageBody = 'TaskDetails_TaskParticipateDeleteConfirmation';
        else if (MessageID == "AttachmentDelete")
            var messageBody = 'tachmentDeleteConfirmation';
        else if (MessageID == "EndTask")
            var messageBody = 'EndTakConfirmatio';
 
    return confirm(messageBody);
}
</script>
<script type="text/javascript">
    //On insert and update buttons click temporarily disables ajax to perform upload actions
    function conditionalPostback(e, sender) {
        var theRegexp = new RegExp("\.ImageButton1", "ig");
        if (sender.EventTarget.match(theRegexp)) {
            alert(sender.EventTarget.match(theRegexp));
            var upload = $find(window['UploadId']);
            alert(upload.toString());
            //AJAX is disabled only if file is selected for upload
            if (upload.getFileInputs()[0].value != "") {
                sender.EnableAjax = false;
                alert("EnableAjax = false");
            }
        }
    }
</script>
 </radscriptblock>
            </div>
            <style type="text/css">
                .DetailsTable {
                    padding: 10px;
                }
 
                .rgCommandCell .td {
                    direction: rtl !important;
                    text-align: right !important;
                    color: Red !important;
                }
            </style>
            <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
            </telerik:RadAjaxLoadingPanel>
            <telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All"
                EnableRoundedCorners="false" />
            <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
                <script type="text/javascript">
                    var uploadedFilesCount = 0;
                    var isEditMode;
                    function validateRadUpload(source, e) {
                        // When the RadGrid is in Edit mode the user is not obliged to upload file.
                        if (isEditMode == null || isEditMode == undefined) {
                            e.IsValid = false;
 
                            if (uploadedFilesCount > 0) {
                                e.IsValid = true;
                            }
                        }
                        isEditMode = null;
                    }
 
                    function OnClientFileUploaded(sender, eventArgs) {
                        uploadedFilesCount++;
                    }
 
                </script>
            </telerik:RadCodeBlock>
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="MasterRadGrid">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="MasterRadGrid"></telerik:AjaxUpdatedControl>
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>
            <div id="Messages">
                <asp:Label ID="lblMessages" CssClass="PageMainMessages" Visible="false" runat="server" />
 
            </div>
            <div id="Form" runat="server">
                <telerik:RadAjaxPanel ID="RadAjaxPanel1" ClientEvents-OnRequestStart="conditionalPostback" runat="server">
                    <div>
                        <telerik:RadTabStrip ID="rtsTaskContent" runat="server" EnableDragToReorder="true"
                            Skin="Office2010Silver" MultiPageID="rmpTaskDetails" SelectedIndex="0">
                            <Tabs>
                                <telerik:RadTab Text="lblTaskDetailsTitle">
                                </telerik:RadTab>
                                <telerik:RadTab Text="ParticipantTitle">
                                </telerik:RadTab>
 
                            </Tabs>
                        </telerik:RadTabStrip>
                        <telerik:RadMultiPage ID="rmpTaskDetails" runat="server" SelectedIndex="0">
                            <telerik:RadPageView ID="rpvTaskDetails" runat="server" Style="overflow: hidden">
                                <div class="MainDev">
                                    <div class="BoxedDiv">
                                        <table>
                                            <tr>
                                                <td style="width: 80%">
                                                    <telerik:RadGrid ID="rgAttachments" runat="server" AutoGenerateColumns="False" AutoGenerateDeleteColumn="false"
                                                        CellSpacing="0" GridLines="None" ShowHeadersWhenNoRecords="true" OnNeedDataSource="rgAttachments_NeedDataSource"
                                                        OnItemDataBound="rgAttachments_ItemDataBound" AllowPaging="true" Width="100%"
                                                        PageSize="5">
                                                        <SortingSettings EnableSkinSortStyles="false"></SortingSettings>
                                                        <PagerStyle Mode="slider" PageSizeLabelText="صفحة رقم" ShowPagerText="false" NextPagesToolTip="تالي"
                                                            PrevPagesToolTip="سابق" FirstPageToolTip="الاولى" LastPageToolTip="الاخيرة" />
                                                        <MasterTableView>
                                                            <SortExpressions>
                                                                <telerik:GridSortExpression FieldName="ParticipantName" SortOrder="Ascending" />
                                                            </SortExpressions>
                                                            <NoRecordsTemplate>
                                                                <table>
                                                                    <tr>
                                                                        <td align="right" style="text-align: right !important">
                                                                            <asp:Label ID="lblNoRecordsFound" runat="server" CssClass="rgNoRecordsFound" Text="lblNoRecordsFound" />
                                                                        </td>
                                                                    </tr>
                                                                </table>
                                                            </NoRecordsTemplate>
                                                            <Columns>
                                                                <telerik:GridBoundColumn DataField="ParticipantName" HeaderText="gvUploadedBy"
                                                                    UniqueName="ParticipantName" />
                                                                <telerik:GridBoundColumn DataField="Title" HeaderText="gvAttachmentName"
                                                                    UniqueName="Title" />
                                                                <telerik:GridBoundColumn DataField="AttachmentID" Display="false" HeaderText="gvAttachmentID"
                                                                    UniqueName="AttachmentID" />
                                                                <telerik:GridBoundColumn DataField="DownloadURL" Display="false" HeaderText="DownloadURL"
                                                                    UniqueName="DownloadURL" />
                                                                <telerik:GridBoundColumn DataField="LoginUserName" Display="false" HeaderText="LoginUserName"
                                                                    UniqueName="LoginUserName" />
                                                                <telerik:GridTemplateColumn HeaderText="gvOptionsHeaderTitle"
                                                                    UniqueName="OptionItems">
                                                                    <ItemTemplate>
                                                                        <asp:LinkButton ID="lbAttachmentDownload" CommandArgument='<%#Eval("DownloadURL") %>'
                                                                            runat="server" Text="ttachmentDownload"
                                                                            OnClick="lbAttachmentDownload_Click"></asp:LinkButton>
                                                                        <asp:Label ID="lblSeperator1" runat="server" Text="-" />
                                                                        <asp:LinkButton ID="lbAttachmentDelete" OnClientClick="return ConfirmMessage('AttachmentDelete');"
                                                                            CommandArgument='<%# Container.ItemIndex %>' runat="server" Text="gvlbAttachmentDelete"
                                                                            OnClick="lbAttachmentDelete_Click"></asp:LinkButton>
                                                                    </ItemTemplate>
                                                                </telerik:GridTemplateColumn>
                                                            </Columns>
                                                        </MasterTableView>
                                                        <FilterMenu EnableImageSprites="False">
                                                        </FilterMenu>
                                                    </telerik:RadGrid>
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                </div>
                            </telerik:RadPageView>
                        </telerik:RadMultiPage>
                    </div>
                </telerik:RadAjaxPanel>
 
            </div>
 
        </div>
    </form>

and here is the code behind 
LinkButton attachment = sender as LinkButton;
               RadAjaxPanel1.ResponseScripts.Add(String.Format(@"window.location.href = ""{0}"";", @"\\SERV-BAKRI\TMSFiles\81\system\t1.pdf"));



0
Mohammad
Top achievements
Rank 1
answered on 05 May 2013, 07:56 AM
hello maria 
sorry for late replay but i was in vacation ,, 

I created new solution just to isolate any other issue becuase i am working in sharepoint 2010 enviroment,, i got new error ,

HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Detailed Error Information:
Module    IIS Web Core
Notification    MapRequestHandler
Handler    StaticFile
Error Code    0x80070002
Requested URL    http://localhost:17360/SERV-BAKRITMSFiles81system1.pdf
Physical Path    C:\Projects\Delete\WebApplication1\WebApplication1\SERV-BAKRITMSFiles81system1.pdf
Logon Method    Anonymous
Logon User    Anonymous
Request Tracing Directory

here is the new code ,, 

<
form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
        <div>
            <div id="Div1" runat="server">
                <radscriptblock id="RadScriptBlock1" runat="server">
<script language="javascript" type="text/javascript">
 
    function OnClientBlurHandler(sender, eventArgs) {
        var textInTheCombo = sender.get_text();
        var item = sender.findItemByText(textInTheCombo);
        //if there is no item with that text
        if (!item) {
            sender.set_text("");
        }
    }
 
</script>
<script language="javascript" type="text/javascript">
 
 
    function AddNewFields(radUpload, args) {
        var FildNameLable = 'neField';
        var curLiEl = args.get_row();
        var firstInput = curLiEl.getElementsByTagName("input")[0];
        var input = CreateInput("Title", "text");
        input.className = "copyOfRADTextCSS";
        input.id = input.name = radUpload.getID(input.name);
        var label = CreateLabel(FildNameLable, input.id);
        var fileInputSpan = curLiEl.getElementsByTagName("span")[0];
        var firstNode = curLiEl.childNodes[0];
        curLiEl.insertBefore(label, fileInputSpan.nextSibling);
        curLiEl.insertBefore(input, label.nextSibling);
    }
 
    function CreateLabel(text, associatedControlId) {
        var label = document.createElement("label");
        label.innerHTML = text;
        label.setAttribute("for", associatedControlId);
        label.style.fontSize = 12;
 
        return label;
    }
    function CreateInput(inputName, type) {
        var input = document.createElement("input");
        input.type = type;
        input.name = inputName;
        return input;
    }
    function ConfirmMessage(MessageID) {
        var messageBody = '';
        if (MessageID == "TaskParticipateDelete")
            messageBody = 'TaskDetails_TaskParticipateDeleteConfirmation';
        else if (MessageID == "AttachmentDelete")
            var messageBody = 'tachmentDeleteConfirmation';
        else if (MessageID == "EndTask")
            var messageBody = 'EndTakConfirmatio';
 
    return confirm(messageBody);
}
</script>
<script type="text/javascript">
    //On insert and update buttons click temporarily disables ajax to perform upload actions
    function conditionalPostback(e, sender) {
        var theRegexp = new RegExp("\.ImageButton1", "ig");
        if (sender.EventTarget.match(theRegexp)) {
            alert(sender.EventTarget.match(theRegexp));
            var upload = $find(window['UploadId']);
            alert(upload.toString());
            //AJAX is disabled only if file is selected for upload
            if (upload.getFileInputs()[0].value != "") {
                sender.EnableAjax = false;
                alert("EnableAjax = false");
            }
        }
    }
</script>
 </radscriptblock>
            </div>
            <style type="text/css">
                .DetailsTable {
                    padding: 10px;
                }
 
                .rgCommandCell .td {
                    direction: rtl !important;
                    text-align: right !important;
                    color: Red !important;
                }
            </style>
            <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
            </telerik:RadAjaxLoadingPanel>
            <telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All"
                EnableRoundedCorners="false" />
            <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
                <script type="text/javascript">
                    var uploadedFilesCount = 0;
                    var isEditMode;
                    function validateRadUpload(source, e) {
                        // When the RadGrid is in Edit mode the user is not obliged to upload file.
                        if (isEditMode == null || isEditMode == undefined) {
                            e.IsValid = false;
 
                            if (uploadedFilesCount > 0) {
                                e.IsValid = true;
                            }
                        }
                        isEditMode = null;
                    }
 
                    function OnClientFileUploaded(sender, eventArgs) {
                        uploadedFilesCount++;
                    }
 
                </script>
            </telerik:RadCodeBlock>
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="MasterRadGrid">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="MasterRadGrid"></telerik:AjaxUpdatedControl>
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>
            <div id="Messages">
                <asp:Label ID="lblMessages" CssClass="PageMainMessages" Visible="false" runat="server" />
 
            </div>
            <div id="Form" runat="server">
                <telerik:RadAjaxPanel ID="RadAjaxPanel1" ClientEvents-OnRequestStart="conditionalPostback" runat="server">
                    <div>
                        <telerik:RadTabStrip ID="rtsTaskContent" runat="server" EnableDragToReorder="true"
                            Skin="Office2010Silver" MultiPageID="rmpTaskDetails" SelectedIndex="0">
                            <Tabs>
                                <telerik:RadTab Text="lblTaskDetailsTitle">
                                </telerik:RadTab>
                                <telerik:RadTab Text="ParticipantTitle">
                                </telerik:RadTab>
 
                            </Tabs>
                        </telerik:RadTabStrip>
                        <telerik:RadMultiPage ID="rmpTaskDetails" runat="server" SelectedIndex="0">
                            <telerik:RadPageView ID="rpvTaskDetails" runat="server" Style="overflow: hidden">
                                <div class="MainDev">
                                    <div class="BoxedDiv">
                                        <table>
                                            <tr>
                                                <td style="width: 80%">
                                                    <telerik:RadGrid ID="rgAttachments" runat="server" AutoGenerateColumns="False" AutoGenerateDeleteColumn="false"
                                                        CellSpacing="0" GridLines="None" ShowHeadersWhenNoRecords="true" OnNeedDataSource="rgAttachments_NeedDataSource"
                                                        OnItemDataBound="rgAttachments_ItemDataBound" AllowPaging="true" Width="100%"
                                                        PageSize="5">
                                                        <SortingSettings EnableSkinSortStyles="false"></SortingSettings>
                                                        <PagerStyle Mode="slider" PageSizeLabelText="صفحة رقم" ShowPagerText="false" NextPagesToolTip="تالي"
                                                            PrevPagesToolTip="سابق" FirstPageToolTip="الاولى" LastPageToolTip="الاخيرة" />
                                                        <MasterTableView>
                                                            <SortExpressions>
                                                                <telerik:GridSortExpression FieldName="ParticipantName" SortOrder="Ascending" />
                                                            </SortExpressions>
                                                            <NoRecordsTemplate>
                                                                <table>
                                                                    <tr>
                                                                        <td align="right" style="text-align: right !important">
                                                                            <asp:Label ID="lblNoRecordsFound" runat="server" CssClass="rgNoRecordsFound" Text="lblNoRecordsFound" />
                                                                        </td>
                                                                    </tr>
                                                                </table>
                                                            </NoRecordsTemplate>
                                                            <Columns>
                                                                <telerik:GridBoundColumn DataField="ParticipantName" HeaderText="gvUploadedBy"
                                                                    UniqueName="ParticipantName" />
                                                                <telerik:GridBoundColumn DataField="Title" HeaderText="gvAttachmentName"
                                                                    UniqueName="Title" />
                                                                <telerik:GridBoundColumn DataField="AttachmentID" Display="false" HeaderText="gvAttachmentID"
                                                                    UniqueName="AttachmentID" />
                                                                <telerik:GridBoundColumn DataField="DownloadURL" Display="false" HeaderText="DownloadURL"
                                                                    UniqueName="DownloadURL" />
                                                                <telerik:GridBoundColumn DataField="LoginUserName" Display="false" HeaderText="LoginUserName"
                                                                    UniqueName="LoginUserName" />
                                                                <telerik:GridTemplateColumn HeaderText="gvOptionsHeaderTitle"
                                                                    UniqueName="OptionItems">
                                                                    <ItemTemplate>
                                                                        <asp:LinkButton ID="lbAttachmentDownload" CommandArgument='<%#Eval("DownloadURL") %>'
                                                                            runat="server" Text="ttachmentDownload"
                                                                            OnClick="lbAttachmentDownload_Click"></asp:LinkButton>
                                                                        <asp:Label ID="lblSeperator1" runat="server" Text="-" />
                                                                        <asp:LinkButton ID="lbAttachmentDelete" OnClientClick="return ConfirmMessage('AttachmentDelete');"
                                                                            CommandArgument='<%# Container.ItemIndex %>' runat="server" Text="gvlbAttachmentDelete"
                                                                            OnClick="lbAttachmentDelete_Click"></asp:LinkButton>
                                                                    </ItemTemplate>
                                                                </telerik:GridTemplateColumn>
                                                            </Columns>
                                                        </MasterTableView>
                                                        <FilterMenu EnableImageSprites="False">
                                                        </FilterMenu>
                                                    </telerik:RadGrid>
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                </div>
                            </telerik:RadPageView>
                        </telerik:RadMultiPage>
                    </div>
                </telerik:RadAjaxPanel>
 
            </div>
 
        </div>
    </form>

and here is the code behind 
LinkButton attachment = sender as LinkButton;
               RadAjaxPanel1.ResponseScripts.Add(String.Format(@"window.location.href = ""{0}"";", @"\\SERV-BAKRI\TMSFiles\81\system\t1.pdf"));



0
msigman
Top achievements
Rank 2
answered on 06 May 2013, 03:46 PM
You have to do file downloads as full PostBacks, not AJAX.  However, you can leave the rest of the page AJAXifiied and add some JavaScript so that only this link is full PostBack.  You can follow the instructions here: http://www.telerik.com/help/aspnet-ajax/ajax-force-controls-to-postback.html

AJAX Manager configuration:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <ClientEvents OnRequestStart="RequestStart" />
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="Button1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="Panel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
        <telerik:AjaxSetting AjaxControlID="Panel1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="Panel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:Panel ID="Panel1" runat="server">
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    <asp:Button ID="Button2" runat="server" Text="Button" />
</asp:Panel>


JavaScript that cancels PostBack if "Button2" was clicked:
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function RequestStart(sender, eventArgs) {
            var eventTarget = eventArgs.get_eventTarget();
            if (eventTarget.indexOf("Button2") != -1) {
                eventArgs.set_enableAjax(false);
            }
        }
    </script>
</telerik:RadCodeBlock>
Tags
Ajax
Asked by
Mohammad
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Mohammad
Top achievements
Rank 1
msigman
Top achievements
Rank 2
Share this question
or