Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can I get the value of the loaded image in the image control in asp?
Posted
Updated 23-Dec-14 4:13am
v2
Comments
CHill60 23-Dec-14 10:47am    
What do you mean by the value?
Member 11316934 23-Dec-14 14:44pm    
I want to save the jpeg file of the image control in my folder "Barcode_images". Can you please help me? Thanks.
This is my code
string strImageURL = "GenerateBarcodeImage.aspx?d=" + initial_barcode + generate + "&il=" + this.chkGenerateLabel.Checked.ToString();
this.BarcodeImage.ImageUrl = strImageURL;
this.BarcodeImage.Width = 300;
this.BarcodeImage.Height = 150;
this.BarcodeImage.Visible = true;

Your Slution is very simple!

C#
void SaveImageImage()
{


        FileStream fs = File.OpenRead(Server.MapPath(Image1.ImageUrl));  //in aspx page Image ID="Image1"
        byte[] photo = new byte[fs.Length];

        for (int i = 0; i < fs.Length; i++)
        {
            photo[i] = (byte)fs.ReadByte();
        }

        fs.Close();

        File.WriteAllBytes(Server.MapPath("BarcodeImages/myImage.jpg"),photo);


        lbllabel.Text = "Saved";




}
 
Share this answer
 
Comments
Member 11316934 28-Dec-14 6:26am    
Hi. I have tried your code but I got this error 'Illegal characters in path.'
if you add control like this
VB
<asp:Image
runat="server"
AlternateText="W3Schools" Id="img1"
ImageUrl="img_w6.gif"/>



you can access in code behind file Like

string s=img1.ImageUtrl;
 
Share this answer
 

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