Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. resource files in VS .NET

resource files in VS .NET

Scheduled Pinned Locked Moved C#
questioncsharpvisual-studiotutoriallearning
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Senkwe Chanda
    wrote on last edited by
    #1

    Hi guys, simple question, how do you use resource files in C#? For example, suppose I create an icon using the editor in VS .NET and the file is named icon1.ico, how would I the go about referencing that file from my code? Currently I keep getting file not found errors (during debugging) because it seems the system checks for the file in the bin directory (I think). Also, what is the best way to set up a repository of resources for my project? For example, if I have alot of different icons that I would like to use dynamically in my app, how would I set that up? Regards, Senkwe Just another wannabe code junky

    J 1 Reply Last reply
    0
    • S Senkwe Chanda

      Hi guys, simple question, how do you use resource files in C#? For example, suppose I create an icon using the editor in VS .NET and the file is named icon1.ico, how would I the go about referencing that file from my code? Currently I keep getting file not found errors (during debugging) because it seems the system checks for the file in the bin directory (I think). Also, what is the best way to set up a repository of resources for my project? For example, if I have alot of different icons that I would like to use dynamically in my app, how would I set that up? Regards, Senkwe Just another wannabe code junky

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      Senkwe Chanda wrote: Hi guys, simple question, how do you use resource files in C#? For example, suppose I create an icon using the editor in VS .NET and the file is named icon1.ico, how would I the go about referencing that file from my code? In VS.NET click on your icon in the Solution Explorer then in the properties box change the Build Action to "Embedded Resource". Now when you build your project you can get a stream to the file from the assembly.

      System.Reflection.Assembly asm = GetType().Assembly;
      System.IO.Stream = asm.GetManifestResourceStream("myDefaultNamespace.myFolder.Icon1.ico"));

      The string that is passed in is a tad difficult to understand at first. myDefaultNamespace is the namespace that is assigned by default to new classes that are added to your project. You can see what this is by going into the properties for your project. If you create a folder within your project and place icons in there, then you also append the folder names to the namespace (if you haven't noticed it -- when you create a folder, any classes created inside that folder have the folder name appended to the default namespace); finally append the filename. In the example above i have an icon named Icon1.ico located in a folder called myFolder in my project with a default namespace of myDefaultNamespace. It is possible to set the default namespace to nothing, in which case you use the folder (if any) and the filename. HTH, James Sonork ID: 100.11138 - Hasaki "My words but a whisper -- your deafness a SHOUT. I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups