Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Stream s;
- byte[] b;
- using (BinaryReader br = new BinaryReader(s))
- {
- b = br.ReadBytes(s.Length);
- }
- public static byte[] ReadFully(Stream input)
- {
- byte[] buffer = new byte[16*1024];
- using (MemoryStream ms = new MemoryStream())
- {
- int read;
- while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
- {
- ms.Write(buffer, 0, read);
- }
- return ms.ToArray();
- }
- }
- public static byte[] ReadFully(Stream input)
- {
- using (MemoryStream ms = new MemoryStream())
- {
- input.CopyTo(ms);
- return ms.ToArray();
- }
- }
- public static byte[] StreamToByteArray(Stream stream)
- {
- if (stream is MemoryStream)
- {
- return ((MemoryStream)stream).ToArray();
- }
- else
- {
- // Jon Skeet's accepted answer
- return ReadFully(stream);
- }
- }
- MemoryStream ms = new MemoryStream();
- file.PostedFile.InputStream.CopyTo(ms);
- var byts = ms.ToArray();
- ms.Dispose();
- Stream s;
- byte[] b;
- if (s.Length > int.MaxValue) {
- throw new Exception("This stream is larger than the conversion algorithm can currently handle.");
- }
- using (var br = new BinaryReader(s)) {
- b = br.ReadBytes((int)s.Length);
- }
Add Comment
Please, Sign In to add comment