0

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);

1 Answer 1

1

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=???" />

Sign up to request clarification or add additional context in comments.

1 Comment

cannot means that there is no such possibility at all

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.