So I'm working on a site that is going to need a file upload control where the user would be able to upload an image, and then the page would postback causing the image to appear for their viewing (before they submit the data to the database, the image is being stored as type image). What I do now is have my own private web form where people send me their image, I format it accordingly and use the following simple code to upload it:

byte[] newimage = fileUpImgFile.FileBytes;
var myDataTable = (from item in context.TypeSet where item.Number == txtBxNumber.Text.Trim() select item).ToList();

foreach (Type item in myDataTable)
    item.Photo = newimage;

Which works, but in this case, it would only work if the record exists already in the database so the person would have to save the data, then go back in and upload the image (inconvenient and inefficient). Is there a way to upload it, store it in memory, and then display it, without saving it to the database?

No correct solution


Once you have the uploaded bytes, you can do anything you want with it.

The approach that immediately jumps to mind is storing the bytes in Session for that user.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow