您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何在ASP.NET Web窗体中将视图作为CSV提供

如何在ASP.NET Web窗体中将视图作为CSV提供

您可以遍历数据集,但是无需在服务器上创建CSV文件,只需通过HTTP响应将其返回即可。以下功能可以解决问题。

Public Shared Sub ExportTextFile(ByVal response As System.Web.HttpResponse, ByVal text As String, ByVal fileName As String)

    response.Clear()
    response.addheader("content-disposition", String.Format("attachment;filename={0}", fileName))
    response.Charset = ""
    response.Cache.SetCacheability(HttpCacheability.NoCache)
    response.ContentType = "application/vnd.text"

    Dim stringWrite As New System.IO.StringWriter
    Dim htmlWrite = New HtmlTextWriter(stringWrite)
    response.Write(text.ToString)
    response.End()

End Sub
dotnet 2022/1/1 18:31:06 有423人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶