下载每个文件的链接

时间:2015-09-29 11:45:11

标签: c# asp.net for-loop hyperlink download

关于gridview的下载链接存在问题。

这是我的gridview:

<asp:GridView ID="GridView1" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged1" AutoGenerateColumns="False" EmptyDataText = "No files uploaded" style="margin-left: 4px; margin-top: 231px" Width="1021px" Height="323px" AllowSorting="True">
            <columns>
                <asp:boundfield datafield="ID" headerText  ="Rec Id"/>
                <asp:boundfield datafield="Center" headertext  ="Work Center"/>
                <asp:boundfield datafield="Model" headertext="Model"/>
                <asp:boundfield datafield="No" headertext="Order No"/>
                <asp:boundfield datafield="Name" headertext="Part Name"/>
                <asp:boundfield datafield="Description" headertext="Occurance Description"/>
                <asp:boundfield datafield="Rate" headertext="Def Rate"/>
                <%-- <asp:boundfield datafield="Files" headertext="Files"/> --%> 
                <asp:TemplateField HeaderText="Files">
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%# Eval("Files" + " " + " ") %>' CommandName="Download" Text='<%# Eval("Files" + " ") %>' OnClick = "lnkDownload_Click"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </columns>
</asp:GridView>

这是我的.cs代码:

 protected void lnkDownload_Click(object sender, EventArgs e)
    {

        //string filePath = (sender as LinkButton).CommandArgument;
        string filePath = (sender as LinkButton).CommandArgument;
        //string[] directories =filePath.Split(Path.DirectorySeparatorChar);
        Response.ContentType = ContentType;
        Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filePath));
        Response.WriteFile(filePath);
        Response.End();
    }

当我尝试一次下载多个文件时出现错误。我想为数据库中具有相同ID的多个文件创建下载链接。文件存储在一个文件夹中! 我想拆分有关文件的链接! 谢谢你的帮助!

0 个答案:

没有答案