下载word文档

简介: 来源:http://www.cnblogs.com/damonlan/archive/2012/04/28/2473525.html 作者:浪迹天涯 protected void GridView1_RowDeleting(object sender, GridViewDeleteEvent...

来源:http://www.cnblogs.com/damonlan/archive/2012/04/28/2473525.html

作者:浪迹天涯

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();

首先需要说明的是,在gridview控件中放一个button 按钮,如下:

<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>

 

作者:Lanny兰东才
出处:http://www.cnblogs.com/damonlan
Q Q:*********
E_mail:Damon_lan@163.com or Dongcai.lan@hp.com

本博文欢迎大家浏览和转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,在『参考』的文章中,我会表明参考的文章来源,尊重他人版权。若您发现我侵犯了您的版权,请及时与我联系。

 

相关文章
|
6月前
|
Python
python获取pdf和word文档页数
python获取pdf和word文档页数
160 0
|
8月前
|
Python
Word 批量转 PDF
Word 批量转 PDF
140 0
Word 批量转 PDF
|
12月前
|
XML Java Apache
python文档Word助手转换pdf目录页码获取统计等源码
在PyCharm中运行《Word助手》即可进入如图1所示的系统主界面。在该界面中,通过顶部的工具栏可以选择所要进行的操作。
129 0
|
索引
NoteExpress的Word插件出现报错问题解决
NoteExpress的Word插件出现报错问题解决
479 0
NoteExpress的Word插件出现报错问题解决
|
Python
Python批量提取多目录下多个word文档中的图片
Python批量提取多目录下多个word文档中的图片
168 0
|
Web App开发 XML Java
通过freemarker生成一个word,解决生成的word用wps打开有问题的问题,解决出word时中文文件名乱码问题,解决打开出word时打开的word出现问题的问题,出图片,解决动态列表
 通过freemarker制作word比较简单 步骤:制作word模板。制作方式是:将模板word保存成为xml----在xml的word模板中添加相应的标记----将xml的word文件的后缀名改成ftl文件(要注意的是生成xml格式要是2003格式的xml,也就是说拿到的word模板得是2003格式的,否则用wps打开word将会出现问题)   详细步骤如下: 模板制作(将要动态显示的
4521 0