Read problem from Bytea column

From: orgilhp <orgilhp(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Read problem from Bytea column
Date: 2011-01-21 08:56:23
Message-ID: 19cee2aa-40f0-489a-82ad-8665a5cffd95@k14g2000pre.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,
I have postgresql 8.3.9 database. Now I am working on reading file
from bytea data and save to filesystem.
I am using Npgsql.dll on c#.net.

First I have using OpenERP to upload a file to postgres database in
bytea column. The original file size is 104,960 bytes and .doc
extension.
Then I read the bytea data and save it to file system, its size
becomes 141,790 bytes. This file cannot be opened however its
extension is .doc.

What is going on?

My c# code is below:

NpgsqlCommand cmd = new NpgsqlCommand("SELECT bytea_col
FROM TableTest LIMIT 1", Conn);
using (FileStream stream = new FileStream("c:\test.doc",
FileMode.Create))
{
byte[] rawbytes = (byte[])cmd.ExecuteScalar();
stream.Write(rawbytes, 0, rawbytes.Length);
stream.Close();
}

Browse pgsql-general by date

  From Date Subject
Next Message Ivan Voras 2011-01-21 12:17:03 Copying databases with extensions - pg_dump question
Previous Message Nick Rudnick 2011-01-21 08:16:58 Are there any projects interested in object functionality? (+ rule bases)