本文介绍了System.FormatException:Base-64 char数组或字符串的长度无效。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个代码来上传pdf文档。运行代码时会出错 -

\ System.FormatException:Base的长度无效-64 char数组或字符串。



我的代码:

  byte  [] bDoccontent =  null ; 
HttpWebRequest hwrProg =(HttpWebRequest)WebRequest.Create(URL);
HttpWebResponse hwrpProg =(HttpWebResponse)hwrProg.GetResponse();
StreamReader sr = new StreamReader(hwrpProg.GetResponseStream(),Encoding.ASCII);
bDoccontent = Convert.FromBase64String(sr.ReadToEnd());
sr.Close();
Response.Clear();
Response.ContentType = Application / pdf;
Page.Response.AddHeader( Content-Disposition inline; filename = wei.pdf);
Response.AddHeader( content-length,bDoccontent.Length.ToString()) ;
Response.BinaryWrite(bDoccontent);
Response.Flush();
Response.Close();



请帮帮我:(

解决方案



Hi,
I have a code to upload the pdf document.While running the code it gives error-
\System.FormatException: Invalid length for a Base-64 char array or string.

My code:

byte[] bDoccontent = null;
HttpWebRequest hwrProg = (HttpWebRequest)WebRequest.Create(URL);
HttpWebResponse hwrpProg = (HttpWebResponse)hwrProg.GetResponse();
StreamReader sr = new StreamReader(hwrpProg.GetResponseStream(), Encoding.ASCII);
bDoccontent = Convert.FromBase64String(sr.ReadToEnd());
sr.Close();
Response.Clear();
Response.ContentType = "Application/pdf";
Page.Response.AddHeader("Content-Disposition", "inline;filename=wei.pdf");
Response.AddHeader("content-length", bDoccontent.Length.ToString());
Response.BinaryWrite(bDoccontent);
Response.Flush();
Response.Close();


Please help me :(

解决方案




这篇关于System.FormatException:Base-64 char数组或字符串的长度无效。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-23 12:46