Reputation: 399
I am trying to create a text file by a loop data .each loop data i have send to another method and creating the text file as blow .
//another method each and every for loop time this method will run.
public void TextFileGen1(string pdate, string oPno, string supCode, string supName, string cur, string docTotal, string glAct, string glName, string pType, string jRemark, string rmk)
{
if (pType == "CEFT")
{
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"E:\filename.txt", true))
{
file.Write(pdate, oPno, supCode);
}
}
else
{
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"E:\DFCC\filename.txt", true))
{
file.Write(pdate, oPno, supCode);
}
}
}
Current output is like this:
20201228 20201229
But I expected this output:
20201229,hgfd,gfd
20201228,yhgtfr,hygtfr
Please could anyone tell me how to do it.
Upvotes: -3
Views: 530
Reputation: 971
You don't seem to be using the Write function correctly.
I think the call you want is:
file.Write("{0},{1},{2}", pdate, oPno, supCode);
The first argument is the 'format string' and its followed by the arguments.
https://learn.microsoft.com/en-us/dotnet/api/system.io.streamwriter.write?view=net-5.0
Upvotes: 2
Reputation: 4163
Change:
file.Write(pdate, oPno, supCode);
to:
file.WriteLine(pdate + "," + oPno + "," + supCode);
Upvotes: 1