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!
RadhaKrishnaKiJayaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun VermaakTechnical SpecialistCommented:
Can you post your code?
RadhaKrishnaKiJayaAuthor Commented:
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!
Fernando SotoRetiredCommented:
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.
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Éric MoreauSenior .Net ConsultantCommented:
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?
RadhaKrishnaKiJayaAuthor Commented:
Hello Eric Moreau,
Here is the code attached.

Thank you!
xxDummy.txt
RadhaKrishnaKiJayaAuthor Commented:
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!
Éric MoreauSenior .Net ConsultantCommented:
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.
Fernando SotoRetiredCommented:
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.
RadhaKrishnaKiJayaAuthor Commented:
First of all thank you all for your time and trying to help.  Here is the solution.

https://support.microsoft.com/en-us/help/269370/last-digits-are-changed-to-zeroes-when-you-type-long-numbers-in-cells

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Éric MoreauSenior .Net ConsultantCommented:
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.
Fernando SotoRetiredCommented:
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.
RadhaKrishnaKiJayaAuthor Commented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.