Home Forums SQL Server 2008 T-SQL (SS2K8) Extracting files from "binary" stored in TEXT datatype RE: Extracting files from "binary" stored in TEXT datatype

  • The object is using the deprecated Text datatype, and reading the string directly from the database shows a text header like ÿØÿá6ªExif, which looks a lot like the EXIF headers if you read the contents of a jpeg file directly in notepad.

    I can use a stream to copy the contents of one jpeg file to another. Can I use that same stream to write directly to the text field in the vendor's SQL database? If so, how would this be done?

    Andre

    string fromPath = @"c:\temp\test1.jpg";

    string toPath = @"c:\temp\test2.jpg";

    using (Stream source = File.OpenRead(fromPath))

    using (Stream dest = File.Create(toPath))

    {

    byte[] buffer = new byte[1024];

    int bytes;

    while ((bytes = source.Read(buffer, 0, buffer.Length)) > 0)

    {

    dest.Write(buffer, 0, bytes);

    }

    }