转发器中的imagebutton问题...无法下载文件 [英] issue with imagebutton in repeater…cant get file to download

查看:68
本文介绍了转发器中的imagebutton问题...无法下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在转发器中使用图像按钮编码了文件下载...传递了命令参数并从类文件中调用了方法...所有代码都正常执行但是没有出现下载对话框....



以下是.asp文件中的代码......





I have coded for file download in repeater with image button... passed command argument and called method from class file... all code executes normally but download dialog doesn't appears....

following is code... in .asp file...


<asp:Repeater ID="rptmaterial" runat="server" OnItemCommand="rptmaterial_ItemCommand" >
                <HeaderTemplate>
                    <div class="all_mat_datagrid">
                        <table>
                            <thead>
                                <tr>
                                    <th class="all_mat_first_col">Title</th>
                                    <th class="all_mat_second_col">Author</th>
                                    <th class="all_mat_third_col">Date Uploaded</th>
                                    <th>Download</th>
                                </tr>
                            </thead>
                </HeaderTemplate>
                <ItemTemplate>
                    <tbody>
                        <tr>
                            <td><%#Eval("FileName") %></td>
                            <td><%#string.Concat(Eval("FName")," ",Eval("LName")) %></td>
                            <td><%# Convert.ToDateTime(Eval("DateCreated")).ToShortDateString() %></td>
                            <td>
                                   <asp:ImageButton ID="btn_dwnld" runat="server" CommandArgument='<%# Eval("MaterialID") %>' CommandName="download_material" Height="30px" ImageUrl="~/images/download.jpg" Width="35px" />

                                   </td>
                        </tr>
                    </tbody>


                </ItemTemplate>
                <FooterTemplate>
                    </table>
                    </div>
                </FooterTemplate>
            </asp:Repeater>










and in cs file...













protected void rptmaterial_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    if (!string.IsNullOrEmpty(Convert.ToString(Session["name"])))
    {
        int MatID = Convert.ToInt32(e.CommandArgument);
        if (e.CommandName == "download_material")
        {
            Operation op2 = new Operation();
            DataSet ds = new DataSet();

            ds = op2.GetMaterialByID(MatID);

            string fileName = Convert.ToString(ds.Tables[0].Rows[0]["Title"]);
            string path = Server.MapPath("Materials/");
            path = path + fileName;
            string contenttype = string.Empty;
            string swfilter = Convert.ToString(ds.Tables[0].Rows[0]["FileType"]);


            switch (swfilter.ToLower())
            {
                case ".docx":
                    contenttype = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                    break;
                case ".doc":
                    contenttype = "application/msword";
                    break;
                case ".ppt":
                    contenttype = "application/vnd.ms-powerpoint";
                    break;
                case ".pptx":
                    contenttype = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
                    break;
                case ".ppsx":
                    contenttype = "application/vnd.openxmlformats-officedocument.presentationml.slideshow";
                    break;

            }


            System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
            response.ClearContent();
            response.Clear();
            response.ContentType = contenttype;
            response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ";");
            response.TransmitFile(path);
            response.Flush();
            response.End();
        }



    }
    else
    {

        Response.Redirect("login.aspx");
    }


}









现在该做什么???





what to do now???

推荐答案

这篇关于转发器中的imagebutton问题...无法下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆