Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an upload interface where I upload images, the link to the image is saved in a column in Oracle, and Image is saved on the file system. I am having challenges viewing the image on my form.

Find below code snippets that handle saving image:

if (AsyncUploadFront.HasFile == false && AsyncUploadBack.HasFile == false)
       {
            divMsg.Visible = true;
            lblMsg.Text = "Please select files to upload";
            return;
       }

if (!checkFileType(AsyncUploadFront.FileName))
       {
            divMsg.Visible = true;
            lblMsg.Text = "Invalid file format. Allowed formats are png, jpg & gif.";
            return;
       }

if (!checkFileType(AsyncUploadBack.FileName))
       {
             divMsg.Visible = true;
             lblMsg.Text = "Invalid file format. Allowed formats are png, jpg & gif.";
             return;
       }


var frontImage = string.Format("{0}_{1}_front{2}", txtAccountNo.Text.Trim(), dateString, frontExt);
var backImage = string.Format("{0}_{1}_back{2}", txtAccountNo.Text.Trim(), dateString,backExt);


//upload images
if (!UploadImage(AsyncUploadFront, frontImage))
   {
         divMsg.Visible = true;
         lblMsg.Text = "Unable to upload cheque front image.";
         return;
   }

if (!UploadImage(AsyncUploadBack, backImage))
   {
          divMsg.Visible = true;
          lblMsg.Text = "Unable to upload cheque back image.";
          return;
   }


private bool UploadImage(FileUpload file, string name)
   {
       string filePath;
       string folder = ConfigurationManager.AppSettings["ImagefileLocation"];

       // Save the uploaded file to the server.
          filePath = folder + name;

      if (File.Exists(filePath))
         {
             return false;
         }
         else
         {
            file.PostedFile.SaveAs(filePath);
            return true;
         }
   }


View to view image
private void loadgrid()
        {
             imgFront.ImageUrl = "~/ChqImages/" + data.ImageFront;
             imgBack.ImageUrl = "~/ChqImages/" + data.ImageBack;
        }


<tr>
<td><asp:Label ID="lblImageFront" ForeColor="Black" runat="server" Visible="true" Text ="Image Front"></asp:Label></td>
<td><asp:Image ID="imgFront" runat="server" Width="218px"/>
</td>
</tr>
<tr>
<td><asp:Label ID="lblimgBack" ForeColor="Black" runat="server" Visible="true" Text="Image Back"></asp:Label></td>
<td><asp:Image ID="imgBack" runat="server" Width="218px"/></td>
</tr>
Posted
Updated 12-Sep-14 4:02am
v2
Comments
V. 12-Sep-14 8:36am    
What are you having trouble with? #1 is the image saved? #2 is the path correct? #3 what do you use a object holder? Bitmap, Image, ... (it helps if you specify if you're using winforms or WPF). #4 I'm not sure what the loadgrid function is supposed to do -- what is the imgFront / imgBack object? # 5 did you debug? are the properties in each step correct? Do they contain values? etc ...
Jibo Oluleye 12-Sep-14 10:03am    
#1-#4 is fine, just trying to show what I have implemented. My challenge is #5, displaying the image, I have added the snippet from html page, where I need to view the image.
[no name] 12-Sep-14 10:20am    
Okay.... and? "My challenge" tells us nothing at all about what you think your problem is.
Nathan Minier 12-Sep-14 10:28am    
Just for giggles, have you tried changing:

private void loadgrid()
{
imgFront.ImageUrl = ConfigurationManager.AppSettings["ImagefileLocation"] + data.ImageFront;
imgBack.ImageUrl = ConfigurationManager.AppSettings["ImagefileLocation"] + data.ImageBack;
}

Jibo Oluleye 12-Sep-14 11:46am    
Yes, I have tried that also, but it doesnt still display the image.
This is what I have in my config file

add key="ImagefileLocation" value="E:\Projects\UBS\Dud_Cheque\DudCheque\ChqImages\" />

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900