Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I desperately need help with an issue I am having while trying load an image or unload an image using ASP/C#. The problem I am having is the first time I run the code and Load the image into the thumbnail, I have no problem but the minute I try to remove the picture or load a second or third image, it takes very very long to hit the event and I get an Out of Memory error. I think something is getting locked and takes a while to get unlocked but I am not sure.

Here is the code I am using:

C#
protected void btnUploadImgPicture1_ServerClick(object sender, EventArgs e)
        {
            using (filePicture1)
            {
                if (filePicture1.PostedFile.FileName != "")
                {
                    imageUtil = new ImageUtility();
                    string realPhysicalPath = Path.Combine(Server.MapPath("~/upload/"), filePicture1.PostedFile.FileName);
                    filePicture1.PostedFile.SaveAs(realPhysicalPath);
                    //imgVehiclePicture1.Src = realPhysicalPath;
                    using (imgVehiclePicture1)
                    {
                        imgVehiclePicture1.Attributes["src"] = imageUtil.getBase64String(realPhysicalPath);
                        Session.Add("Image1", realPhysicalPath);
                        imageUtil = null;
                    }

                }
            }
        }

public  string getBase64String(string path)
        {
            Image img = Image.FromFile(path);
            byte[] imageBytes = imageToByteArray(img);
            string base64String = Convert.ToBase64String(imageBytes, 0, imageBytes.Length);
            return "data:image/png;base64," + base64String;
        }


I am using this code on 3 times for 3 different events and then I am using similar code to remove the selected image from the upload.

Please help

thanks
Posted
Comments
ZurdoDev 29-Oct-13 15:26pm    
What is btnUploadImgPicture1and what is a ServerClick event?
mou7866 29-Oct-13 15:32pm    
The btnUploadImgPicture1 is the button I am using to load the Image selected in the File Input Control. Here is the ASP code:

<div class="profile-photo">
<img runat="server" id="imgVehiclePicture1" src="img/blog/blog-thumb-1.jpg" alt="" height="150" width="150" />

</div>
<input type="file" class="default" runat="server" id="filePicture1" />
<br/>
Please click the green button to upload the picture
<br />
<span>
<button class="btn btn-success" runat="server" id="btnUploadImgPicture1" önserverclick="btnUploadImgPicture1_ServerClick"></button>

<button class="btn btn-danger" runat="server" id="btnRemoveImgPicture1" önserverclick="btnRemoveImgPicture1_ServerClick"></button>
</span>

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