开发者

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?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜