[英]c# visual studio - find absolute path of image after publishing the project
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上贴了一个标签,以便可以打印出已发布程序正在运行的位置,并弄清楚通过Reflection哪个路径可以将我带到正确的位置。
public string img_path = System.Windows.Forms.Application.StartupPath + "\\Resources\\" + "LOGO.jpg";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.