Amin Safaei
Amin Safaei

Reputation: 23

How to set HTML input file value in code behind

I want to display an image in an input control with the file type. First I read var binary data from a database, then I convert it to a memory stream, but I can't pass a variable to the <input type="file" />. How can I do it?

<input type="file" name="images" id="images" runat=server />

SqlConnection con = new SqlConnection(stcon);
SqlCommand command = new SqlCommand();
command.CommandText = "select * from image where ImageId=4";
command.Connection = con;
SqlDataAdapter adapt = new SqlDataAdapter(command);
DataTable dt = new DataTable();
adapt.Fill(dt);
MemoryStream memStream = new MemoryStream((byte[])dt.Rows[0][1]);
Stream str;
memStream.CopyTo(str);

Upvotes: 0

Views: 1383

Answers (1)

Iłya Bursov
Iłya Bursov

Reputation: 24229

You cannot set value for <input type"file">, if you want to display image - write separate page which will fetch data from database, and post it with proper HTTP headers, in HTML it will be like <img src="/image.aspx?id=???" />

Upvotes: 1

Related Questions