Hey guys,
For some reason I cannot get an image I have uploaded to display when I try to render it through an <img> tag within a response.write() API Call in C#. Here is my code:
protected void uploadFiles(object sender, EventArgs e)
{
HttpFileCollection allFiles = Request.Files;
for (int i = 0; i < allFiles.Count; i++)
{
HttpPostedFile singleFile = allFiles[i];
try
{
if (singleFile.ContentLength > 0)
{
//Get the name of the file
string fileName = singleFile.FileName.Substring(singleFile.FileName.LastIndexOf("\\") + 1);
//The name of the image with the Images
string image = "Images"; +"//" + fileName;
//Save it to the server
singleFile.SaveAs(Server.MapPath(image));
string htmlOutPut = "File Size: " +
singleFile.ContentLength + "kb<br>";
htmlOutPut += "File Name: " + fileName + "</ br>";
//SOURCE OF ERROR. The image is never displayed
htmlOutPut += "<img src=" + image + "/>";
Response.Write(htmlOutPut);
}
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
I'm basically uploading it and then saving it and just trying to display the image by using an image tag but the image I'm trying to upload does not show up. The only thing that shows up is the standard small image not found thumbnail. I've tried numerous things such as ResolveUrl and it still does not render the image. In addition I also made a static <img> tag within my form and was able to display an image from the same directory I'm uploading and saving the image to!
Can anyone give me some advice on how to get this working?