Search code examples
sqlsql-serverlinqattachmentlinqpad

Reading Images, Pdf from SQL Database via LINQPad


I have a table in a database that contains all kind of attachments, images, pdf, excel, and other formats. creating an application is not an option, so I googled other options and I found this related question that mentioned LINQPad I downloaded it but I still do not know how exactly it works. Anyone please explain that to me? I can query the attachments using sql query but not sure how to dump them and preview them via the mentioned tools.


Solution

  • Following on from Dan's answer, once you have the data context set up you can dump the images from the database. I use this snippet for checking an image I've written to the database, you should be able to edit as required to match your scenario:-

    var ii = ItemImages.Where (v => v.Id == 10).FirstOrDefault();
    using (var ms = new MemoryStream(ii.Image.ToArray()))
    {
        System.Drawing.Image.FromStream(ms).Dump();
    }