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

Function to download a file from a folder

4 Answers 223 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Jaime
Top achievements
Rank 1
Jaime asked on 06 Dec 2012, 09:14 PM
I found an example but with a gridview, can anyone help me to use it with RadGrid???


protected void lnkDownload_Click(object sender, EventArgs e)
    {
        LinkButton lnkbtn = sender as LinkButton;
        GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
        string filePath = gvDetails.DataKeys[gvrow.RowIndex].Value.ToString();
        Response.ContentType = "application/vnd.ms-excel, application/pdf, application/vnd.ms-excel";
        Response.AddHeader("Content-Disposition", "attachment;filename=\"" + filePath + "\"");
        Response.TransmitFile(Server.MapPath(filePath));
        Response.End();
    }


where gvDetails is a Gridview.

Thanks.

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 07 Dec 2012, 04:11 AM
Hi,

Please try the following code snippet.

C#:
protected void lnkDownload_Click(object sender, EventArgs e)
{
    LinkButton lnkbtn = sender as LinkButton;
    GridDataItem item = (GridDataItem)lnkbtn.NamingContainer;
    string filePath = item.OwnerTableView.DataKeyValues[item.ItemIndex]["DataKeyName"].ToString();
    Response.ContentType = "application/vnd.ms-excel, application/pdf, application/vnd.ms-excel";
    Response.AddHeader("Content-Disposition", "attachment;filename=\"" + filePath + "\"");
    Response.TransmitFile(Server.MapPath(filePath));
    Response.End();
}


Thanks,
Princy.
0
Jaime
Top achievements
Rank 1
answered on 07 Dec 2012, 04:36 AM
Thanks a lot!!!!
0
Mayur
Top achievements
Rank 1
answered on 20 Dec 2013, 06:08 AM
Hi Princy,
               Hope you would be doing well. I am having an issue in TelerikRad Grid. I am having a TelerikRadAsynchUpload and RadBinaryImage inside a Telerikgrid. What i have to do is to upload and display a thumbnail of that Image/PDF/TXT or whatever may be the file type in RadBinaryImage after download.

I have added a CustomHandler in RadGrid for uploading. Now the problem is when i remove CustomHandler uploading don't happens and when i put CustomHandler then the image preview not works.....

What i have to do is both should work. Please find attached code snippet along with screenshot of issue below.

Awaiting for your prompt reply. Looking forward to speak with you.

Code Snippet:

aspx
------
<MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="CD_SRNO" CommandItemSettings-AddNewRecordText="Add New File">
                                <Columns>
                                    <telerik:GridTemplateColumn HeaderText="Remarks" UniqueName="Description" DataField="Description">
                                        <ItemTemplate>
                                            <asp:Label ID="lblDescription" Width="400px" runat="server" Text='<%#Eval("Description") %>'></asp:Label>
                                        </ItemTemplate>
                                        <EditItemTemplate>
                                            <telerik:RadTextBox ID="txbDescription" Width="400px" runat="server" TextMode="MultiLine"
                                                Text='<%# Eval("Description") %>' Height="30px">
                                            </telerik:RadTextBox>
                                            <asp:RequiredFieldValidator ID="Requiredfieldvalidator1" runat="server" ControlToValidate="txbDescription"
                                                ErrorMessage="*" Display="Dynamic" SetFocusOnError="true"></asp:RequiredFieldValidator>
                                        </EditItemTemplate>
                                        <ItemStyle VerticalAlign="Top"></ItemStyle>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn DataField="Data" HeaderText="Document" UniqueName="Upload">
                                        <ItemTemplate>
                                            <telerik:RadBinaryImage runat="server" ID="RadBinaryImage1" AutoAdjustImageControlSize="false"
                                                DataValue='<%#Eval("Data") %>' Height="42px" Width="80px"></telerik:RadBinaryImage>
                                        </ItemTemplate>
                                        <EditItemTemplate>
                                            <telerik:RadAsyncUpload runat="server" ID="AsyncUpload1" AllowedFileExtensions=".jpg,.jpeg,.png,.gif,.Pdf,.doc,.docx,.xls"
                                                MaxFileInputsCount="1" Skin="Outlook" PostbackTriggers="PerformInsertButton"
                                                MaxFileSize="1048576" OnClientFileUploaded="OnClientFileUploaded" HttpHandlerUrl="~/Conference/CustomHandler.ashx" />
                                            <asp:CustomValidator runat="server" ID="CustomValidator" Display="Dynamic" ClientValidationFunction="validateUpload"
                                                ErrorMessage="*" />
                                        </EditItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn DataField="Data" HeaderText="Download" UniqueName="Upload">
                                        <ItemTemplate>
                                            <asp:LinkButton runat="server" OnClick="lnkDownload_Click" CommandArgument='<%# Eval("CD_SRNO") %>'
                                                ID="lnkDownload" Text='<%# string.Concat("Document-", Eval("CD_SRNO"),Eval("DOCTYPE"))%>'></asp:LinkButton>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ButtonType="ImageButton">
                                        <HeaderStyle Width="36px"></HeaderStyle>
                                    </telerik:GridButtonColumn>
                                </Columns>
                                <EditFormSettings>
                                    <EditColumn ButtonType="ImageButton">
                                    </EditColumn>
                                </EditFormSettings>
                            </MasterTableView> 

CustomHandler
-------------------

Imports System
Imports System.Web
Imports Telerik.Web.UI


Public Class CustomHandler
    Inherits AsyncUploadHandler
    
    Protected Overrides Function Process(file As UploadedFile, context As HttpContext, configuration As IAsyncUploadConfiguration, tempFileName As String) As IAsyncUploadResult
        configuration.TimeToLive = TimeSpan.FromHours(4)
        Return MyBase.Process(file, context, configuration, tempFileName)
    End Function

End Class
0
Hristo Valyavicharski
Telerik team
answered on 24 Dec 2013, 02:50 PM
Hi Mayur,

What are you doing inside the OnClientFileUploaded event? As far as I see you don't need this custom handler, because it doesn't provide additional functionality.

Regards,
Hristo Valyavicharski
Telerik
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 the blog feed now.
Tags
AsyncUpload
Asked by
Jaime
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jaime
Top achievements
Rank 1
Mayur
Top achievements
Rank 1
Hristo Valyavicharski
Telerik team
Share this question
or