Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

String to byte not working and generate PDF

When

byte[] bytes = {105,122,101,32 ......... 105,122,101,32}
System.IO.File.WriteAllBytes("E:\\hello-" + DateTime.Now.ToString("yyyyMMddhhmmssff") + ".pdf", bytes);

this work


string data = "105,122,101,32 ......... 105,122,101,32"
byte[] bytes = Encoding.ASCII.GetBytes(data );
System.IO.File.WriteAllBytes("E:\\hello-" + DateTime.Now.ToString("yyyyMMddhhmmssff") + ".pdf", bytes);

not work

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

why can’t i convert string to byte well?
Thanks

>Solution :

OK; so the problem here is that for whatever reason, you have a comma-separated string that contains the bytes as integers, and you need to parse that into bytes. Horrible (base-64 would be a far better choice), but: fine: simply do that. This is not pretty, but should work fine:

string data = ...
var bytes = Array.ConvertAll(data.Split(','), byte.Parse);
System.IO.File.WriteAllBytes("E:\\hello-" + DateTime.Now.ToString("yyyyMMddhhmmssff") + ".pdf", bytes);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading