J'ai des images qui sont stockés dans SQL-Server.
Et j'aimerais pouvoir remettre mes fichiers sur le disque dur.
J'arrive à visualiser mes images en ASP .NET.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 Response.Clear(); string sSQL ="SELECT binfichier FROM vignette WHERE idvignette=@idvignette"; SqlConnection oCon = new SqlConnection(ConnString); SqlCommand oComm = new SqlCommand(sSQL, oCon); oComm.CommandType=CommandType.Text; oComm.Parameters.Add("@idvignette", SqlDbType.Int).Value = vignetteId; SqlDataAdapter sqlDA = new SqlDataAdapter(oComm); DataSet DS=new DataSet(); sqlDA.Fill(DS); oComm.Dispose(); sqlDA.Dispose(); Byte[] byteBLOBData = new Byte[0]; byteBLOBData = (Byte[])(DS.Tables[0].Rows[0]["binfichier"]); MemoryStream stmBLOBData = new MemoryStream(byteBLOBData); MemoryStream memImg =stmBLOBData; if(memImg != null) { byte[] imageContent = new Byte[memImg.Length]; memImg.Position = 0; memImg.Read(imageContent, 0, (int)memImg.Length); Response.AddHeader("Content-Disposition", "inline; filename=image/pjpeg"); Response.BinaryWrite(imageContent); } Response.End(); }
Partager