Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 44805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:42:35+00:00 2026-05-10T15:42:35+00:00

This is what I’ve got. It works. But, is there a simpler or better

  • 0

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…

<asp:HyperLink ID='HyperLinkDownload' runat='server' NavigateUrl='~/Download.aspx'>Download as CSV file</asp:HyperLink> 

And then I’ve got the Download.aspx.vb Code Behind…

Public Partial Class Download     Inherits System.Web.UI.Page      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load         'set header         Response.Clear()         Response.ContentType = 'text/csv'         Dim FileName As String = 'books.csv'         Response.AppendHeader('Content-Disposition', 'attachment;filename=' + FileName)          'generate file content         Dim db As New bookDevelopmentDataContext         Dim Allbooks = From b In db.books _                        Order By b.Added _                        Select b         Dim CsvFile As New StringBuilder         CsvFile.AppendLine(CsvHeader())         For Each b As Book In Allbooks             CsvFile.AppendLine(bookString(b))         Next          'write the file         Response.Write(CsvFile.ToString)         Response.End()     End Sub      Function CsvHeader() As String         Dim CsvLine As New StringBuilder         CsvLine.Append('Published,')         CsvLine.Append('Title,')         CsvLine.Append('Author,')         CsvLine.Append('Price')         Return CsvLine.ToString     End Function      Function bookString(ByVal b As Book) As String         Dim CsvLine As New StringBuilder         CsvLine.Append(b.Published.ToShortDateString + ',')         CsvLine.Append(b.Title.Replace(',', '') + ',')         CsvLine.Append(b.Author.Replace(',', '') + ',')         CsvLine.Append(Format(b.Price, 'c').Replace(',', ''))         Return CsvLine.ToString     End Function  End Class 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T15:42:35+00:00Added an answer on May 10, 2026 at 3:42 pm

    CSV formatting has some gotchas. Have you asked yourself these questions:

    • Does any of my data have embedded commas?
    • Does any of my data have embedded double-quotes?
    • Does any of my data have have newlines?
    • Do I need to support Unicode strings?

    I see several problems in your code above. The comma thing first of all… you are stripping commas:

    CsvLine.Append(Format(b.Price, 'c').Replace(',', '')) 

    Why? In CSV, you should be surrounding anything which has commas with quotes:

    CsvLine.Append(String.Format('\'{0:c}\'', b.Price)) 

    (or something like that… my VB is not very good). If you’re not sure if there are commas, but put quotes around it. If there are quotes in the string, you need to escape them by doubling them. ' becomes ''.

    b.Title.Replace('\'', '\'\'') 

    Then surround this by quotes if you want. If there are newlines in your string, you need to surround the string with quotes… yes, literal newlines are allowed in CSV files. It looks weird to humans, but it’s all good.

    A good CSV writer requires some thought. A good CSV reader (parser) is just plain hard (and no, regex not good enough for parsing CSV… it will only get you about 95% of the way there).

    And then there is Unicode… or more generally I18N (Internationalization) issues. For example, you are stripping commas out of a formatted price. But that’s assuming the price is formatted as you expect it in the US. In France, the number formatting is reversed (periods used instead of commas, and vice versa). Bottom line, use culture-agnostic formatting wherever possible.

    While the issue here is generating CSV, inevitably you will need to parse CSV. In .NET, the best parser I have found (for free) is Fast CSV Reader on CodeProject. I’ve actually used it in production code and it is really really fast, and very easy to use!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 51k
  • Answers 51k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The insert statement actually has a syntax for doing just… May 11, 2026 at 6:28 am
  • added an answer Thanks for the answers. I ended up implementing a mix… May 11, 2026 at 6:28 am
  • added an answer You can't and shouldn't use F5 key - it's reserved… May 11, 2026 at 6:28 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.