首页 > 解决方案 > c#visual studio - 发布项目后查找图片的绝对路径

问题描述

 private static string img = System.Reflection.Assembly.GetExecutingAssembly().Location;
 private static string[] imgs = img.Split(new string[] {"\\ProgramName"},StringSplitOptions.None);
 private  string img_path = imgs[0] + "\\Resources\\LOGO.jpg";//

以上在我的电脑上调试时有效 - 一旦我发布程序(我将把它交给我的妻子在工作中使用)然后路径不匹配并且图像丢失(我需要绝对路径,因为我是在报告中使用它 - 通过代码以 html 格式格式化,然后推送到 pdf)。

我想我确实有一个问题:

private string img_path = System.Windows.Forms.Application.StartupPath + "\\Resources\\" + "LOGO.jpg";

非常感谢,如果你能帮忙!我试图加载图像本身,但因为我使用的是 html 中的路径 - 该选项对我不起作用。

标签: c#

解决方案


对于任何有类似问题的人,我最终自己解决了。我在我的 winforms 上贴了一个标签,这样我就可以打印出发布的程序运行的位置,并通过反射找出哪条路径可以让我到达正确的位置。

 public string img_path = System.Windows.Forms.Application.StartupPath + "\\Resources\\" + "LOGO.jpg";

推荐阅读