Hi fatihlinux,
Here i have created sample that full fill your requirement. You need to change as per your data saved in the database.
I have created the sample refering the below article.
SQL
CREATE TABLE Files(Id INT IDENTITY PRIMARY KEY,Name VARCHAR(500),FilePath VARCHAR(1000))
INSERT INTO Files VALUES('Chrysanthemum.jpg','C:\Users\Public\Pictures\Sample Pictures')
INSERT INTO Files VALUES('Desert.jpg','C:\Users\Public\Pictures\Sample Pictures')
INSERT INTO Files VALUES('Hydrangeas.jpg','C:\Users\Public\Pictures\Sample Pictures')
INSERT INTO Files VALUES('Jellyfish.jpg','C:\Users\Public\Pictures\Sample Pictures')
SELECT * FROM Files
HTML
Default.aspx
<div>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField HeaderText="Photo">
<ItemTemplate>
<asp:Image ImageUrl='<%# String.Format("ImageCSharp.aspx?FileName={0}&FilePath={1}", Eval("Name"),Eval("FilePath")) %>'
runat="server" Height="50px" Width="50px" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
Code
Default.aspx
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Files"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
GridView2.DataSource = dt;
GridView2.DataBind();
}
}
}
}
}
}
ImageCSharp.aspx
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["FileName"] != null && Request.QueryString["FilePath"] != null)
{
string filePath = Request.QueryString["FilePath"];
string filename = Request.QueryString["FileName"];
string contenttype = "image/" + Path.GetExtension(filename.Replace(".", ""));
FileStream fs = new FileStream(filePath + "\\" + filename, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
br.Close();
fs.Close();
Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = contenttype;
Response.AddHeader("content-disposition", "attachment;filename=" + filename);
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
}
Screenshot
