filenotfoundexception未被c#中的用户代码处理 [英] filenotfoundexception was unhandled by user code in c#

查看:110
本文介绍了filenotfoundexception未被c#中的用户代码处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  protected   void  btn1_click(对象发​​件人,EventArgs e)
{
// string Location = Server.MapPath(images)+\\+image4.bmp;
float opacityvalue = float .Parse(txtb1.Text)/ 100 ;

// 图片img = Image.FromFile(位置);
// 新位图(位置);

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



}





执行上述代码我收到错误

filenotfoundexception未被c#中的用户代码处理

这个

解决方案

Image img = System.Drawing.Image.FromFile(Image1.ImageUrl);

根据错误,它看起来像你想要的文件这里指的是在指向的位置丢失。



请确保文件位置和文件出现在您指向的位置。

根据注释代码,它看起来像一个相对路径问题。



有一种方法可以处理URL''。阅读: ResolveUrl [ ^ ]。



我建议您在设置控件/图像源之前使用此提示并正确解析路径:解决多文件夹网站中的路径 [ ^ ]


如果Image1是你的图像控制,更改:

图像img = System.Drawing.Image.FromFile(  Image1.ImageUrl); 



to

图片img = System.Drawing.Image.FromFile(Image1.ImageUrl); 


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

解决方案

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[^]


If Image1 is your image control, change :

Image img = System.Drawing.Image.FromFile("Image1.ImageUrl");


to

Image img = System.Drawing.Image.FromFile(Image1.ImageUrl);


这篇关于filenotfoundexception未被c#中的用户代码处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆