im developing an application where i need to provide two upload file options one for the image and one is for video, i have this code Ref
foreach (string file in Request.Files)
{
HttpPostedFile hpf = Request.Files[file] as HttpPostedFile;
if (hpf.ContentLength == 0)
continue;
string savedFileName = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
Path.GetFileName(hpf.FileName));
hpf.SaveAs(savedFileName);
}
and in the view
<input type="file" id="fileUpload1" name="fileUpload1" size="23" class="image" />
<input type="file" id="fileUpload2" name="fileUpload2" size="23" class="video" />
it works fine the files get uploaded but the problem is how can i determine which file comes from which input type so to differentiate between the image and the video because i have to then assign separate unique names to them and save to the database.
You could identify the image using the content type of the HttpPostedFileBase
If you just have the one image you are sorted, you could also check for your video content type for validation. If you had two images we’d probably have to think of something else.