[英]FileUpload control - error in display file content
I m trying read binary file and save to a variable but I received 0 as reply in byte[] buffer
why?我正在尝试读取二进制文件并保存到变量中,但我在
byte[] buffer
中收到 0 作为回复,为什么?
Stream FileContent = FileUpload.FileContent;
int size = Int32.Parse(Request.Headers["Content-Length"]);
byte[] buffer = new Byte[size];
FileContent.Read(buffer, 0, size);
string bin = System.Text.Encoding.ASCII.GetString(buffer);
FileContent.Close();
thanks!谢谢!
I don't have .net near me but I used successfully something like this:我附近没有 .net 但我成功地使用了这样的东西:
Get the file length:获取文件长度:
fileLength = FileUpload1.PostedFile.ContentLength;
Get the stream:获取 stream:
stream = FileUpload1.FileContent;
Read the content:阅读内容:
stream.Read(byteArray, 0, fileLength);
Hope this helps.希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.