How do I best generate a CSV (comma-delimited text file) for download with ASP.NET?

后端 未结 8 1177
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-14 18:46

This is what I\'ve got. It works. But, is there a simpler or better way?

One an ASPX page, I\'ve got the download link...



        
8条回答
  •  萌比男神i
    2020-12-14 19:10

    I pass all my CSV data through a function like this:

    Function PrepForCSV(ByVal value As String) As String
        return String.Format("""{0}""", Value.Replace("""", """"""))
    End Function
    

    Also, if you're not serving up html you probably want an http handler (.ashx file) rather than a full web page. If you create a new handler in Visual Studio, odds are you could just copy past your existing code into the main method and it will just work, with a small performance boost for your efforts.

提交回复
热议问题