We help IT Professionals succeed at work.

StreamWriter not working

103 Views
Last Modified: 2018-11-12
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!
Comment
Watch Question

Shaun VermaakSenior Consultant
CERTIFIED EXPERT
Awarded 2017
Distinguished Expert 2019

Commented:
Can you post your code?

Author

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 SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
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.
Éric MoreauSenior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016

Commented:
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?

Author

Commented:
Hello Eric Moreau,
Here is the code attached.

Thank you!
xxDummy.txt

Author

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 Consultant
CERTIFIED EXPERT
Top Expert 2016

Commented:
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 SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
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.
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Éric MoreauSenior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016

Commented:
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 SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
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.

Author

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.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions