none
Adding folders in Project RRS feed

  • Question

  • Hallo

    Hope somebody can help, probably simple question but might be a better way to handling folders.

    We got images stored on a local drive, we want to create a folder in the VS Project and copy the images into the folder by adding new folder under the project. But do we still need to create the resource pointing to the folder to be embedded in the project once deployed?

    Same question regarding folders, we are using TXT files for some local user configuration how can we create the folders, and ensure it's created once the user install the application?

    Hope above makes sense..

    Any assistance will be appreciated.

    Regards,


    labjac

    Monday, October 8, 2018 6:17 PM

Answers

  • "We got images stored on a local drive, we want to create a folder in the VS Project and copy the images into the folder by adding new folder under the project."

    You can create the folder in the project and then drag and drop the files from the file system into the folder in Solution Explorer and it'll copy the files into there.

    "But do we still need to create the resource pointing to the folder to be embedded in the project once deployed?"

    That depends upon how you want to deploy them. If you want the files sitting on disk and your app retrieve them directly from disk then you don't need a resource. However that means the folder structure is part of your app's deployment and a user can change/delete said files. If you go this route then be sure to mark each file as Content via the Build Action on the file's properties.

    If you want the contents embedded in your assembly so that you don't have to ship extra files then ensure each file's Build Action is set to Embedded Resource. At build time they will be converted to resources in your assembly. You don't need to create a resource for this either.

    The question comes up though, how do you intend to get access to these files at runtime? If you're using an embedded resource then you would need to use ResourceManager to find the resource in your assembly. That is what the Resources helper class is for. By using this class to add the files to your project the designer will auto-generate the code to extract them when you need them. You don't have to work with ReourceManager directly.

    "Same question regarding folders, we are using TXT files for some local user configuration how can we create the folders, and ensure it's created once the user install the application?"

    It doesn't matter what type of file you store in a resource. They all work the same way. But you mentioned you want to create the file at installation. Installation-time questions would be dependent upon your installer technology. In general per-user settings are generated when the user runs the app the first time and that data is stored in the user's personal directory (generally under Documents). If you want to seed this file then your app should look for the file in the user's directory. If it is not found then extract it from your resource just like you would any other file. Then save a copy to the user's directory.

    Note also that for small sets of data you might also consider just using the Settings provider which handles this automatically. You'd only want to move up to your own file if your app has some data stored that a config file wouldn't be sufficient for.


    Michael Taylor http://www.michaeltaylorp3.net

    • Proposed as answer by Cherkaoui.Mouad Monday, October 8, 2018 8:55 PM
    • Marked as answer by labjac Wednesday, October 10, 2018 3:56 PM
    Monday, October 8, 2018 7:18 PM
    Moderator

All replies

  • Hi,

    you can choose, in the property window of your file, what to do with it(content, resource, compile ...). In the same window you can choose if you want to copy the file to the output folder(always copy, copy if newer, do not copy).

    Sounds like you need to add the folders to your project, copy the files there and choose "do nothing" and "copy if newer" for every file.

    Greetings, Chris


    • Edited by DerChris88 Monday, October 8, 2018 7:13 PM
    Monday, October 8, 2018 7:13 PM
  • Monday, October 8, 2018 7:18 PM
  • "We got images stored on a local drive, we want to create a folder in the VS Project and copy the images into the folder by adding new folder under the project."

    You can create the folder in the project and then drag and drop the files from the file system into the folder in Solution Explorer and it'll copy the files into there.

    "But do we still need to create the resource pointing to the folder to be embedded in the project once deployed?"

    That depends upon how you want to deploy them. If you want the files sitting on disk and your app retrieve them directly from disk then you don't need a resource. However that means the folder structure is part of your app's deployment and a user can change/delete said files. If you go this route then be sure to mark each file as Content via the Build Action on the file's properties.

    If you want the contents embedded in your assembly so that you don't have to ship extra files then ensure each file's Build Action is set to Embedded Resource. At build time they will be converted to resources in your assembly. You don't need to create a resource for this either.

    The question comes up though, how do you intend to get access to these files at runtime? If you're using an embedded resource then you would need to use ResourceManager to find the resource in your assembly. That is what the Resources helper class is for. By using this class to add the files to your project the designer will auto-generate the code to extract them when you need them. You don't have to work with ReourceManager directly.

    "Same question regarding folders, we are using TXT files for some local user configuration how can we create the folders, and ensure it's created once the user install the application?"

    It doesn't matter what type of file you store in a resource. They all work the same way. But you mentioned you want to create the file at installation. Installation-time questions would be dependent upon your installer technology. In general per-user settings are generated when the user runs the app the first time and that data is stored in the user's personal directory (generally under Documents). If you want to seed this file then your app should look for the file in the user's directory. If it is not found then extract it from your resource just like you would any other file. Then save a copy to the user's directory.

    Note also that for small sets of data you might also consider just using the Settings provider which handles this automatically. You'd only want to move up to your own file if your app has some data stored that a config file wouldn't be sufficient for.


    Michael Taylor http://www.michaeltaylorp3.net

    • Proposed as answer by Cherkaoui.Mouad Monday, October 8, 2018 8:55 PM
    • Marked as answer by labjac Wednesday, October 10, 2018 3:56 PM
    Monday, October 8, 2018 7:18 PM
    Moderator
  • I'm sorry, my vs is german :/ but I think you will find it ;)
    Monday, October 8, 2018 7:23 PM
  • Hallo

    Thanks for the answer, this is what I was looking for.

    I would like to embedded the images which now makes sense, I copy all the images and items I want to use in the folder for easy access and when using it just embedded it.

    Thanks for the help again.

    Regards,


    labjac

    Wednesday, October 10, 2018 4:23 PM