简体   繁体   中英

how to make a setup of c#.net project with relative image path

I am using avatar photos in my application , in my app I created an Image folder in which I kept those pics. And as a path used relative ie;

images\gravatar.png

Also , made Copy to Output Directory - Copy to

But when I am making a setup and installing it on client machines its not able to find the path and give Unhandled Exception error on the path. I tried researching only thing I got was how to use in development not in Deployment.

Thanks

If you want to use a relative path, set a constant for where the executable started from. Then the paths can be relative to that one.

public static readonly string APPLICATION_ROOT_PATH = Application.StartupPath + "\\";
public static readonly string IMAGES_PATH = APPLICATION_ROOT_PATH + "\\images";

Now you can use those constants like any other path. For example:

m_openFileDlg.InitialDirectory = className.IMAGES_PATH;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM