Dim ext As String = System.IO.Path.GetExtension(FileUpload1.FileName.ToString)
path = Server.MapPath(".\\Profile\\")
If FileUpload1.HasFile = False Then
Info.UpdatePanelInfo("กรุณาเลือกไฟล์", Me.Page)
Else
If (ext = ".jpg" Or ext = ".png" Or ext = ".bmp") Then
'*** Read Binary Data ***'
Dim imbByte(FileUpload1.PostedFile.InputStream.Length) As Byte
FileUpload1.PostedFile.InputStream.Read(imbByte, 0, imbByte.Length)
'***insert database ***'
Dim db As New OfficerdbDataContext
Dim img = From p In db.Officers _
Where p.OfficerCode.ToString = Session("OfficerCodeSearch").ToString
img.Single.Pic = imbByte
db.SubmitChanges()
Else
Info.UpdatePanelInfo("อัพโหลดเฉพาะรูปภาพ .jpeg หรือ .png หรือ gif เท่านั้น", Me.Page)
End If
End If
ทีนี้ จาก link ดังกล่าว จะมีบรรทัดนี้เพื่อให้ Add parameter น่ะครับ
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class WebImage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["id"] != null)
{
Page.Controls.Clear();
byte[] image = (from i in db.MyTable
where i.ID == Convert.Int32(Request.QueryString["id"])
select i).Select(i => i.Content).First();
Response.ContentType = "image/png";
Response.BinaryWrite(image);
}
}
}