C# 如何将字节数组转换为 Stream

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9918692/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 11:13:38  来源:igfitidea点击:

How to convert a byte array to Stream

c#

提问by priyanka.sarkar

Possible Duplicate:
How do I convert byte[] to stream in C#?

可能的重复:
如何将 byte[] 转换为 C# 中的流?

I need to convert a byte array to a Stream . How to do so in C#?

我需要将字节数组转换为 Stream 。如何在 C# 中做到这一点?

It is in asp.net application.

它在asp.net 应用程序中。

FileUpload Control Name: taxformUpload

文件上传控件名称:taxformUpload

Program

程序

byte[] buffer = new byte[(int)taxformUpload.FileContent.Length];
taxformUpload.FileContent.Read(buffer, 0, buffer.Length);

Stream stream = ConvertToStream(buffer);

采纳答案by Etienne de Martel

Easy, simply wrap a MemoryStreamaround it:

很简单,只需将MemoryStream它包裹起来即可:

Stream stream = new MemoryStream(buffer);

回答by Icarus

In your case:

在你的情况下:

MemoryStream ms = new MemoryStream(buffer);

回答by priyanka.sarkar

I am using as what John Rasch said:

我正在使用 John Rasch 所说的:

Stream streamContent = taxformUpload.FileContent;