Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void btn1_click(object sender, EventArgs e)
      {
         //string   Location = Server.MapPath("images") + "\\" + "image4.bmp";
          float opacityvalue = float.Parse(txtb1.Text) / 100;

          //Image img = Image.FromFile(Location);
              //new Bitmap(Location);

              //System.Drawing.Image.FromFile(Location);
          //var location = Server.MapPath("images") + "\\" + "image4.bmp";
          ///string imgpath = Image1.ImageUrl;
          Image img = System.Drawing.Image.FromFile("Image1.ImageUrl");
          ChangeOpacity(img, opacityvalue);



      }


while executing the above code i am getting the error
filenotfoundexception was unhandled by user code in c#
what is the solution for this
Posted

Image img = System.Drawing.Image.FromFile("Image1.ImageUrl");
Based on the error, it looks like the file that you want to refer here is missing at the location pointed to.

Please make sure that the file location and the file is present at the location you point to.
Based on the commented code, it looks like a relative path issue.

There is a method exposed to handle URL's. Have a read: ResolveUrl[^].

I would suggest you to use this Tip and resolve the path correctly before setting the control/image source: Resolving Paths in a Multi-Folder WebSite[^]
 
Share this answer
 
If Image1 is your image control, change :
C#
Image img = System.Drawing.Image.FromFile("Image1.ImageUrl");

to
C#
Image img = System.Drawing.Image.FromFile(Image1.ImageUrl);
 
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