[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

Spaces in File

I am having trouble getting a text field from a database to display correctly in a csv file.

The ASP.NET application collects information from several database tables and returns it as one csv file. This works fine but there is one field called "Message" which is a text field in SQL Server, people use it to type in messages for deliveries with a certain product. The message field is the only one giving problems, if I replace it with any other field the format is fine.

I think that there must be line breaks (or similar) being inserted in the streamwriter when creating the csv file. How should I prepare the field for input into the file???
2 Solutions
You can remove the line breaks by removing either \n or \r\n. Web forms use \n and Windows uses \r\n.

Assuming data is a string containing the text, try either:

data = data.Replace("\n", "")
data = data.Replace("\r\n", "")
Try replacing the Carriage return or line breaks in the field with spaces before you output it to the csv

i.e. if you've got the data from the Message field into a variable called Msg you could do the following when outputting it to your csv file

Msg.Replace(VbCrLf, " ").Replace(VbCr, " ").Replace(VbLf, " ")


Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now