zoukankan      html  css  js  c++  java
  • 下载word文档

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string courseName = ((Label)GridView1.Rows[e.RowIndex].Cells[1].FindControl("Label1")).Text.ToString();//在GridView中文件名字
            string time = ((Label)GridView1.Rows[e.RowIndex].Cells[2].FindControl("Label2")).Text.ToString();//在GridView中找时间
            string tempPath = BusyworkManage.Path + tm.ReturnTeacherID(Request.Cookies["StudentID"].Value.ToString()) +BusyworkManage.TopicPath +
    courseName + "/" + courseName + "_" + time + ".doc";//这样做是为了不使下载后的文件的名字重复!~~。
            string path = Server.MapPath(tempPath);
            FileInfo fInfo = new FileInfo(path);
            string fname = fInfo.Name;
            Response.Clear();
            Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fname));
            Response.AddHeader("Content-Length", fInfo.Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.WriteFile(fInfo.FullName);
            Response.Flush();

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Height="139px"
            Width="100%" OnRowDeleting="GridView1_RowDeleting"
                onselectedindexchanged="GridView1_SelectedIndexChanged">
            <Columns>
            。。。。。。省略代码。。。。。
                <asp:BoundField DataField="成绩" HeaderText="成绩">
                    <ItemStyle HorizontalAlign="Center" />
                </asp:BoundField>
                <asp:CommandField ButtonType="Button" DeleteText="下作业载" ShowDeleteButton="True">
                    <ItemStyle HorizontalAlign="Center" />
                </asp:CommandField>
                <asp:HyperLinkField Text="提交作业" DataNavigateUrlFormatString="SubmitBusywork.aspx?course={0}&amp;time={1}" DataNavigateUrlFields="课程名称,作业次数">
                    <ItemStyle HorizontalAlign="Center" />
                </asp:HyperLinkField>
            </Columns>
        </asp:GridView>

  • 相关阅读:
    idea 添加不同的模板文件比如 . vm 文件
    Spring ioc及aop思想
    idea配置非maven项目配置及热部署配置
    AES对称式加密及https加密算法中数字证书(非对称加密)
    Solr(搜索引擎)简单介绍(不一定要会用但是要知道)
    回炉重造-基础规则之初识static关键字
    回炉重造-基础规则之初识IO流
    回炉重造-基础规则之类和对象
    回炉重造-基础规则之行为方法
    回炉重造-基础规则之Java的数组
  • 原文地址:https://www.cnblogs.com/fjzhang/p/2487513.html
Copyright © 2011-2022 走看看