I know this is stupid question but please tell me how to publish application with images? I am using
this.BackgroundImage = Image.FromFile("../../images/Blue/Blue_Style1.jpg");
it works fine in visual studio but when I publish application images doesn't include and application gives error
Solution 1: Create a dedicated folder for storing the
images
in your projectdebug/release
folder.Ex:
project/bin/Release/Images/
Access the Images from that folder as below:
Solution 2: accessing
Images
fromResources
file.Note: first you need to add the
Images
intoResources
.Here i have added
Blue_Style1.jpg
file toResources
.See here for adding images to Resources
This works in Visual Studio because you load the file from two folders above. When running in VS, you usually work in the bin\Debug subfolder, so ..\..\FileName.jpg refers to the file in the project folder.
In order to copy the file to your project output, change the "Copy to output directory" setting to Copy If Newer or Copy Always in the file properties. After that, changet the path of the file as follows:
When you deploy your application, you have to also copy the images folder.
For each image you'll need to check the Build Action property to ensure it is copied to the target directory.
Setting the Build Action to Content should work.