1

I want to build a CSV file from separate strings but since the size of the string is big I'm trying to avoid from joining the strings into a single string before writing to the file. Meaning, creating a file and than adding another string into it. can it be done?

5 Answers 5

4

Rather than using String go for StringBuilder to build your string.

than flush string in file.

Sign up to request clarification or add additional context in comments.

Comments

1

You could use the StreamWriter object http://msdn.microsoft.com/en-us/library/system.io.streamwriter.aspx

Have a look here as well

Comments

1

If you are using StreamWriter Class then simply call Write method each time you want to write value to file.

Comments

1

Here is a full demo for creating a text file, including a function for appending strings to it after creation.

Comments

0

Refer to this coding.

 StringBuilder Content1 = new StringBuilder();
 Content1.Append("MailFrom:" + FromAdd + Constants.vbCrLf);
 Content1.Append("MailTo:" + EmailID + Constants.vbCrLf);
 Content1.Append("MailCC:" + MailCC + Constants.vbCrLf);
 Content1.Append("MailBCC:" + MailBCC + Constants.vbCrLf);
 Content1.Append("MailSubject:" + MailSubject + RequestNumber + Constants.vbCrLf);
 Content1.Append("MailAttachment:" + MailAttachment + Constants.vbCrLf);
 Content1.Append("MailBody:" + "" + Constants.vbCrLf);
 if (!File.Exists(Application.StartupPath)) {
SW = File.CreateText(Application.StartupPath + "\\" + FinalPath);
using (fs) {
}
Thread.Sleep(1000);
  }
  using (SW) {
SW.Write(Content1.ToString);
 }

Use the above method for creating a text file and writing the content.

1 Comment

Why are you creating an email?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.