本文介绍了binaray阅读器问题,二进制阅读器不读取字节。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码运行良好

会话[  fileUpl] = fileUpl; lblFileUpload.Text = fileUpl.FileName; 
会话[ 图像] = fileUpl.PostedFile;
Stream fs = fileUpl.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
byte [] bytes = br.ReadBytes(( Int32 )fs.Length);
string base64String = Convert.ToBase64String(bytes, 0 ,bytes.Length);
Image1.ImageUrl = data:image / png; base64, + base64String;





但是下面这段代码不起作用,fs.length显示文件长度但是bites数组显示0字节。这意味着二进制阅读器不开心有什么。我不知道为什么请帮忙。



 fileUpl =(FileUpload)Session [  fileUpl]; lblFileUpload.Text = fileUpl.FileName; 
HttpPostedFile postedFile =(HttpPostedFile)Session [ Image];
Stream fs = postingFile.InputStream;
BinaryReader br = new BinaryReader(fs);
byte [] bytes = br.ReadBytes(( Int32 )fs.Length);
string base64String = Convert.ToBase64String(bytes, 0 ,bytes.Length);
Image1.ImageUrl = data:image / png; base64, + base64String;
解决方案

This code works perfectly well

Session["fileUpl"] = fileUpl; lblFileUpload.Text = fileUpl.FileName;
            Session["Image"] = fileUpl.PostedFile;
            Stream fs = fileUpl.PostedFile.InputStream;
            BinaryReader br = new BinaryReader(fs);
            byte[] bytes = br.ReadBytes((Int32)fs.Length);
            string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
            Image1.ImageUrl =  + base64String;



but this code below does not works ,fs.length shows file lenght but bites array shows 0 bytes .that means binary reader is not happy with something .i dont know why please help.

fileUpl = (FileUpload)Session["fileUpl"]; lblFileUpload.Text = fileUpl.FileName;
           HttpPostedFile postedFile = (HttpPostedFile)Session["Image"];
           Stream fs = postedFile.InputStream;
           BinaryReader br = new BinaryReader(fs);
           byte[] bytes = br.ReadBytes((Int32)fs.Length);
           string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
           Image1.ImageUrl =  + base64String;
解决方案


这篇关于binaray阅读器问题,二进制阅读器不读取字节。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 05:27