How to convert varBinary into image or video when retrieved from database in C#

前端 未结 4 1845
孤街浪徒
孤街浪徒 2021-01-16 06:31

I am using visual studio 2010, (desktop application) and using LINQ to SQL to save image/video or audio files to database in dataType VarBinary (MAX). This I ca

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-16 07:38

    If you already have the bytes, to verify that what you saved is correct you can save the bytes to a file and open it....

    string tempFile = Path.GetTempFileName();
    MemoryStream ms = new MemoryStream(bytes); //bytes that was read from the db
    //Here I assume that you're reading a png image, you can put any extension you like is a file name
    FileStream stream = new FileStream(tempFile + ".png", FileMode.Create);
    ms.WriteTo(stream);
    ms.Close();
    stream.Close();
    //And here we open the file with the default program
    Process.Start(tempFile + ".png");
    

    And later you can use the answer of Dillie-O and stream....

提交回复
热议问题