1

In my C# windows forms application, I have an image that I used some where as part of requirement and I stored it in a folder named Images with in my solution.

But when I deployed it and installed the application on a user machine it threw me an error specified file not found

I used my image as follows

indexWorkSheet.Shapes.AddPicture(@"C:\Atlas Applications\AtlasPetroleumIndex\CLPetroleumIndex\Images\logo.jpg", MsoTriState.msoFalse, MsoTriState.msoCTrue, 155, 20, 180, 65).LockAspectRatio = MsoTriState.msoCTrue;
DoIt
  • 3,270
  • 9
  • 51
  • 103

2 Answers2

2

Create an Images folder in your solution in VS, then right click on it and go to Add -> Add Existing Item. Select the image you want, then once it's added to your project right click on the image and go to Properties and select Copy Always for Copy to Output Directory

Saggio
  • 2,212
  • 6
  • 33
  • 50
  • should I change anything in build action or keeo it none – DoIt Dec 10 '14 at 21:05
  • You can probably change it to `Resource` – Saggio Dec 10 '14 at 21:07
  • @Dev I saw that you had a comment saying that it wasn't compiling, but has since been removed. Were you able to get this working? – Saggio Dec 11 '14 at 16:05
  • Actually no, I had the image on a server and used that location. Still not sure how I can make that image resource available – DoIt Dec 11 '14 at 16:16
  • Did you try removing the directory in your build folder that you manually created and let VS create it? Since Images\Logo.jpg already existed it might be causing conflicts – Saggio Dec 11 '14 at 16:24
  • Yes, I did remove and actually used an absolute location instead – DoIt Dec 11 '14 at 16:32
1

If you want to prevent users from deleting your folder containing the logo file, you should definitely add this image to the Resources of your Project.

You can refer to the MSDN related page to do so. Your image will then be stored into the executable file of your application.

If you are also interested in storing other kind of user information, like general settings, preferences, user logo, etc... I suggest you take a look at this post.

Community
  • 1
  • 1
kamino
  • 395
  • 2
  • 11