网络错误将Excel文件保存到客户端asp.net [英] network error saving Excel file to client asp.net

查看:130
本文介绍了网络错误将Excel文件保存到客户端asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

   Protected Sub btnExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExcel.Click

        Dim sValue As String = [String].Empty
        Dim dt As DataTable = DirectCast(ViewState("CurrentTable"), DataTable).Copy()
        Dim HTMLContent As New StringBuilder()
        sValue = vbTab
        For Each dcolumn As DataColumn In dt.Columns
            HTMLContent.Append(dcolumn.ColumnName + sValue)
            sValue = vbTab
        Next
        HTMLContent.Append(vbLf)
        Dim cnt As Integer
        For Each dRow As DataRow In dt.Rows
            sValue = ""
            For cnt = 0 To dt.Columns.Count - 1
                HTMLContent.Append(sValue & dRow(cnt).ToString())
                sValue = vbTab
            Next
            HTMLContent.Append(vbLf)
        Next
        HttpContext.Current.Response.Clear()
        HttpContext.Current.Response.ClearContent()
        HttpContext.Current.Response.ClearHeaders()
        HttpContext.Current.Response.Charset = ""
        HttpContext.Current.Response.Buffer = True
        HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
        HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=PastureCnt.xls")
        HttpContext.Current.Response.Write(HTMLContent)
        HttpContext.Current.Response.Flush()
        HttpContext.Current.Response.Close()
        lblMessage.Visible = True
    End Sub


我正在使用上面的代码,它在我测试时很有效,将PastureCnt.xls放在我的下载文件夹中。  但是,当我在服务器上发布并从云服务器在Chrome中运行时,它会向我显示"Pasture.cnt",并显示消息
"Failed.Network error"    我已阅读大量说明​​,表明它应该提示我下载。    我错过了什么?  有没有办法使用MapPath转到我的客户端机器?  我很乐意将
放在C:\ Data文件夹中。   

I am using the code above and it works great when I am testing, placing the PastureCnt.xls in my downloads folder.   However, when I publish on the server,  and run in Chrome from the cloud server, it shows me "Pasture.cnt below with the message "Failed.Network error"    I have read numerous instructions that indicate it should prompt me to download.    What am I missing?   Is there a way to use MapPath to go to my client machine?   I would be happy to have it placed in C:\Data folder.   

推荐答案

您好,

请在此处提出您的问题 

Please ask your question here 

https://forums.asp.net/


这篇关于网络错误将Excel文件保存到客户端asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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