0

Howdy, Now I'm a complete newby to .Net and the likes of VB (I'm more of a Ruby/Rails, PHP kinda guy).

Anyway I currently have a sub that has a string builder that I'm wish to use as the content of a CSV which I will email later from a webpage. My stringbuilder is creating the content for the CSV but I don't know how to create the CSV dynamically (I don't want the CSV on disk).

  Private Shared Sub BuildClientTrustBalanceCSV(ByVal sb As StringBuilder, ByVal clientsWithTrustBalance As List(Of NonPaymentHistory))

    If clientsWithTrustBalance Is Nothing OrElse clientsWithTrustBalance.Count = 0 Then
      Exit Sub
    End If

    ' need to somewhere create the CSV then inject the StringBuilder into it?

    With sb

      ' create the CSV
      For Each zeroBalanceClient As NonPaymentHistory In clientsWithTrustBalance
        .AppendFormatLine("{0},", zeroBalanceClient.Number)
      Next zeroBalanceClient

    End With


  End Sub

Any ideas? I know I should be able to sort this but .NET just isn't my thing?

Mike Sav
  • 14,805
  • 31
  • 98
  • 143
  • CSV is a simple text format - what exactly are you having problems with? Getting the data? formatting it? – Oded Oct 19 '10 at 08:55
  • I just want to know how to create a CSV, getting the data and formatting are easy. There's loads of examples on how to create a CSV on a drive but I need it created in memory. – Mike Sav Oct 19 '10 at 08:58
  • If you put it in a string builder, it will be in memory. – Oded Oct 19 '10 at 09:01
  • I think this is what I need ' need to somewhere create the CSV then inject the StringBuilder into it? HttpContext.Current.Response.ContentType = "Application/x-msexcel" HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=clientsWithTrustBalance.csv") – Mike Sav Oct 19 '10 at 09:03
  • 1
    So, you want to return a CSV from a web page, without creating a file on the disk? If that's the question, you really should edit it and explain exactly what you are trying to do. The question as it stands does not say that's what you are trying to do. – Oded Oct 19 '10 at 09:06
  • Yes, that's what I'm trying to do, I'll edit the question – Mike Sav Oct 19 '10 at 09:07

1 Answers1

0

Here is a link that might be helpful, but I agree with Oded that the question is misleading.

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

Community
  • 1
  • 1
Wade73
  • 4,359
  • 3
  • 30
  • 46