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
You could use the StreamWriter object http://msdn.microsoft.com/en-us/library/system.io.streamwriter.aspx
Have a look here as well
Comments
If you are using StreamWriter Class then simply call Write method each time you want to write value to file.
Comments
Here is a full demo for creating a text file, including a function for appending strings to it after creation.
Comments
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
Darren Young
Why are you creating an email?