Link to home
Start Free TrialLog in
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

asked on

StreamWriter not working

Hello Experts,
I am trying to generate an output file using StreamWriter in C# which contains Credit Card (CC) numbers.  As long as the CC Number is 15 digits long, the StreamWriter works just fine.  But when the CC Number length is 16 digits long, the StreamWriter replaces the last digit with 0 (zero).  Any idea how to fix it?  Please try to help.

Thank you very much in advance!
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

Can you post your code?
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

ASKER

Hello Shaun,
Unfortunately I am not allowed to post the code here.  But the code is not different from other codes.  There is no parsing.  Just writing the data as it is.  This code in use for the last 15 years.  It happens only if the CC Number is more than 15 digits long.  So up to 15 digits I am not getting any issue.  Any digits more than 15 are replaced with 0s.  Hope that helps.  I think there is some limitation with the StreamWriter.

Thank you!
Are you using the StreamWriter with the correct size buffer size, one that will have the correct number of bytes. This is the only thing I can think of.
I really don't think that it is a limitation of the streamwriter, it has to come from your code.

I totally get that you cannot post all of your code here but can you at least post a dummy sample that replicates the issue?
Hello Eric Moreau,
Here is the code attached.

Thank you!
xxDummy.txt
Hello Fernando Soto,

How to set the buffer size of the  StreamWriter?

It is able to write even greater strings without any problem.  Only problem is with number longer than 15 digits.  How come it is possible?

Thank you!
Which part of your code is not working properly? The WriteItem method?  I suspect your CreditCardEncrypt class to be the issue.  Add breakpoints to your code and debug it. You will be able to find out exactly where the value is transformed.
You are not using the StreamWriter method that specifically uses a defined buffer size. Seeming that you state that you can write less then or more then 16 characters I would tend to thing that maybe your code is manipulating the data.
ASKER CERTIFIED SOLUTION
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It wasn't clear to me that you were using Excel in here. Most of us told that the issue was not the StreamWriter but it had to come from elsewhere.
Well it would of help if you would have given us the background info that you were getting the data from Excel. As I stated in my last post that I did not believe it was the StreamWriter but somehow cause by program manipulating the data well Excel was just doing that.
Fernando Soto and Eric Moreau, Data is not coming from Excel.  The C# program is creating an output file, which is and Excel file.  My apology for not mentioning about the Excel file.  Probably that would have fixed my issue earlier.  Thank you for your help.