1
업로드 된 콘텐츠를보기 위해 HttpPostedBaseFile의 바이트를보고 싶습니다. 그래도 난 스트림을 열 때, 데이터 I는 HttpPostedFileBase의의 InputStream을 보존하거나 보존되었음을 모양을주고 싶은 버퍼를 지우지 않고 httppostedbase 메모리 스트림을 엿보기
private bool IsAWordDocument(HttpPostedFileBase httpPostedFileBase)
{
....
byte[] contents = null;
using (var binaryReader = new BinaryReader(httpPostedFileBase.InputStream))
{
contents = binaryReader.ReadBytes(10);
//binaryReader.BaseStream.Position = 0;
}
//InputStream is empty when I get to here!
var properBytes = contents.Take(8).SequenceEqual(DOC) || contents.Take(4).SequenceEqual(ZIP_DOCX);
httpPostedFileBase.InputStream.Position = 0; //reset stream position
...
}
을 취소 나타납니다. 어떻게하면 InputStream을 보존하면서 많은 바이트를 읽거나 엿볼 수 있습니까?
편집
: 나는 다른 접근 방식을 데리고 스트림 데이터를 읽고, 그리고 마시고에 메타 데이터를 스트리밍. 그런 다음 POCO를 지나쳤습니다.public class FileData
{
public FileData(HttpPostedFileBase file)
{
ContentLength = file.ContentLength;
ContentType = file.ContentType;
FileExtension = Path.GetExtension(file.FileName);
FileName = Path.GetFileName(file.FileName);
using (var binaryReader = new BinaryReader(file.InputStream))
{
Contents = binaryReader.ReadBytes(file.ContentLength);
}
}
public string FileName { get; set; }
public string FileExtension { get; set; }
public string ContentType { get; set; }
public int ContentLength { get; set; }
public byte[] Contents { get; set; }
}