locked
How to map to the images folder in project RRS feed

  • Question

  • How to map to the images\delete.png in project.

    Currently i am getting image from file system but I want to find a way to get it from images folder in project

       Images.Add("Delete", Image.FromFile("C:\Delete.png"))

    Tuesday, August 2, 2016 1:43 PM

Answers

  • Getting File not found exception

         Images.Add("Delete", Image.FromFile(My.Application.Info.DirectoryPath & "\Images\Delete.png"))

    You have to move the Images folder to the correct location. Set a Debug breakpoint on the above line and check the value of My.Application.Info.DirectoryPath to see where your assembly is executing. The Images folder should be moved under this folder.

     

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Tuesday, August 2, 2016 6:17 PM

All replies

  • Easy enough,

    • add a Resources\Images directory in your project directory QuickCheckPoint\QuickCheckPoint\Resources\Images
    • copy your image files in there
    • Add the directories to your project (right click on project, then  Add, then  New Folder): add Resources and Images under Resources
    • then use the Resources interface to add existing files, pointing to the images in Resources\Images in your project directory...

    The Images then will be available to your project from your Resources... and in your project directory.

    • Proposed as answer by Cor Ligthert Tuesday, August 2, 2016 3:25 PM
    • Unproposed as answer by Cor Ligthert Tuesday, August 2, 2016 3:40 PM
    Tuesday, August 2, 2016 2:00 PM
  • I want to know relative path what to use inside Image.FromFile instead of "C:\Delete.png"
    Tuesday, August 2, 2016 2:02 PM
  • Well it just depends on where it is...

    just click on the image and the properties will tell you where it is physically located.

    On the other hand, having a directory for resources and images in your project is a good way to keep track of your project's stuff.


    Tuesday, August 2, 2016 2:08 PM
  • If you move the Images folder under the folder where the application assembly executes, you can use

    My.Application.Info.DirectoryPath & "\Images\Delete.png"

    When working from Visual Studio the folder would probably be one your bin folders.


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Tuesday, August 2, 2016 2:57 PM
  • Getting File not found exception

         Images.Add("Delete", Image.FromFile(My.Application.Info.DirectoryPath & "\Images\Delete.png"))

    Tuesday, August 2, 2016 3:32 PM
  • What kind of project are you using?

    Windows Forms, WPF, ASP or whatever


    Success
    Cor

    Tuesday, August 2, 2016 3:52 PM
  • Windows Forms
    Tuesday, August 2, 2016 3:54 PM
  • Check the directory location and if the file is really there, get the path from the file properties and paste it into your code.

    BTW theMy.Application.Info.DirectoryPath  points to the directory where it executes...that is most likely bin\debug.... ie: C:\Users\UserName\ProjectDirectory\ProjectName\bin\Debug

    so no wonders you get the file not found!

    I do recommend you get on with using Resources to add the image files into your project.

    Tuesday, August 2, 2016 4:13 PM
  • Getting File not found exception

         Images.Add("Delete", Image.FromFile(My.Application.Info.DirectoryPath & "\Images\Delete.png"))

    You have to move the Images folder to the correct location. Set a Debug breakpoint on the above line and check the value of My.Application.Info.DirectoryPath to see where your assembly is executing. The Images folder should be moved under this folder.

     

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Tuesday, August 2, 2016 6:17 PM