2014-09-14 3 views
0

SQL Server에서 반환 된 바이트 배열을 C#의 스트림 개체로 변환 할 수 있습니까? 은 내가 VARBINARY (MAX) 형식으로보다 SQL 서버 다른 그것을 저장하는 다른 방법이 있나요바이트 배열을 스트림으로 변환

FileStream fs = new FileStream(@"C:\Users\sample\sample\sample.txt", FileMode.Open, FileAccess.Read); 
fs.Seek(0, SeekOrigin.Begin); 
BinaryReader br = new BinaryReader(fs); 
Byte[] bytes = br.ReadBytes((Int32)fs.Length); 
//bytes array will be saved in the database 
//The following will be returned from the database and i need it to be in a stream 
Stream s = (Stream)bytes; 

아래 같은 것을 할 수 있도록하려면?

답변

2

쉽습니다. 이것을 변환하려면 MemoryStream을 사용하십시오.

Stream S = new MemoryStream(bytes); 

또는 이에 해당합니다.

static void Write(Stream s, Byte[] bytes) 
    { 
     using (var writer = new BinaryWriter(s)) 
     { 
      writer.Write(bytes); 
     } 
    } 
0

당신은 Stream 객체

Stream st = new MemoryStream(bytes); 
에 바이트 배열을 변환 할 MemoryStream 클래스를 사용할 수 있습니다
관련 문제