0

バイナリ列に多数のファイルが保存されたデータベースがあります。linq を使用してそれらを取得したいと思います。

データベース内のファイルが .tif ファイルの場合に正常に動作する次のコードがあります。

var Bytes = TblBriefingImages.Where(si => si.ImageName == t.FileName 
                                            && si.ImageType == t.ImageType 
                                            && "B" + si.SourceDocumentNumber == t.BriefingNumber)
                                            .Select(si => si.Image.ToArray())
                                            .SingleOrDefault();

            File.WriteAllBytes(t.FullPath,Bytes);

データベース内のファイルが別の形式 (pdf、doc、jpg) の場合、破損しています。

ファイルをデータベースに書き込んだアプリケーションは VB6 であり、動作しています。

   ' Copy the bitmap to the temporary file chunk by chunk:
    Dim buffer() As Byte                    'used to avoid UNICODE string
    intHandle = FreeFile
    Open strTempFileName For Binary Access Write As #intHandle

    For i = 0 To lngBuffers
        buffer() = !Image.GetChunk(BUFFER_SIZE)
        Put #intHandle, , buffer()
    Next i

    Close #intHandle

コメント:

'UNICODE文字列を避けるために使用

エンコーディングの問題である可能性があると思われますが、使用しているエンコーディングを特定できません。

また、file.WriteAllBytes の代わりに filestream を使用してみましたが、結果は同じファイルになります。

var fs = File.Create(t.FullPath,Bytes.Length);
fs.Write(Bytes,0,Bytes.Length);
fs.Close();
4

1 に答える 1