开发者

FileUpload control - error in display file content

开发者 https://www.devze.com 2023-03-19 03:43 出处:网络
I m trying read binary file and save to a variable but I received 0 as reply in byte[] buffer why? Stream FileContent = FileUpload.FileContent;

I m trying read binary file and save to a variable but I received 0 as reply in byte[] buffer why?

Stream FileContent = FileUpload.FileContent;
开发者_Python百科                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:

Get the file length:

fileLength = FileUpload1.PostedFile.ContentLength;        

Get the stream:

stream = FileUpload1.FileContent;

Read the content:

stream.Read(byteArray, 0, fileLength);

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消