开发者

reading file binary received of fileUpload control

I m looking for an code example as read file binary received of fileUpload control.

HTML

<form id="f" runat="server">
<asp:Label ID="label1" runat="server"></asp:Label>
<asp:Fi开发者_开发百科leUpload ID="FileUpload" runat="server"  />
<p>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Go" />
</p>
</form>

C# code(not working)

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();
Response.Write(bin); //output 0???

Any help would be appreciated. and feel free to suggest a completely different way of solving the problem. Thanks in advance!


Check this out:

How do I safely read from a stream in asp.net?


I may be missing something obvious here, but why not just use the FileUpload.SaveAs Method on the FileUpload control to save the file locally?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜