c# - 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 中的路径 - 该选项对我不起作用。
解决方案
对于任何有类似问题的人,我最终自己解决了。我在我的 winforms 上贴了一个标签,这样我就可以打印出发布的程序运行的位置,并通过反射找出哪条路径可以让我到达正确的位置。
public string img_path = System.Windows.Forms.Application.StartupPath + "\\Resources\\" + "LOGO.jpg";
推荐阅读
- python - 如何使用 python/osx 在按键上退出循环?
- python - Tweepy:忽略以前的推文以改进优化
- r - 更改 lm() 中用冒号指定的交互项的对比
- callback - 如何知道我的消息已在 MQTT 上收到
- jquery - 如何在 ionic 3 中使用 shepherd 和 jquery?
- ruby-on-rails - 如何在 XML 中定义多次出现
- python - 是否可以使用步长大于 1 的 pandas.DataFrame.rolling?
- excel - VBA复制和粘贴部分单元格
- css - HTML 表格标记内的条形码字体无法正确呈现。但外面工作完美
- regex - 如何在正则表达式中区分具有相同格式的捕获组