-1

I have a table like below

IMAGEID          COVERPAGEIMAGE       IMAGENAME
------------------------------------------------
LME111201908576  0x89504E470D0A1...   NULL

I want to convert all the COVERPAGEIMAGE is of varbinary(max) datatype to a png/jpeg image and update the name in IMAGENAME using a SQL query.

The table includes almost 10000 rows of data. I couldn't find a faster way to do it yet any help or guidance would be appreciated.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
marceloo1223
  • 95
  • 1
  • 10

1 Answers1

0

There is File.WriteAllBytes method that could help to create file from blob data. Example,

...
using (var r =  cmd.ExecuteReader())
{
    while (r.Read())
    {
         File.WriteAllBytes("C:\temp\" + (string)r["IMAGEID"]+ ".png",
              (byte[])r["COVERPAGEIMAGE"]);
     }

}

Assigning IMAGENAME will depend on how target file names will look like. If filename will be always equal to IMAGEID+".png" like in example above, you might not need that column at all.

Same can be done with only sql: fastest way to export blobs from table into individual files

user2316116
  • 6,726
  • 1
  • 21
  • 35