Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio: cannot access resources from code

I added several files (HTML, CSS, etc.) as resources to my Visual Studio project. According to MSDN, I should be able to access these resources via

MyProjectName.Properties.Resources.Filename

Unfortunately, IntelliSense doesn't even know the Properties property behind MyProjectName. If I type "MyProjectName.", IntelliSense offers me several things but no properties. I already built the project, but nothing changed.

If this is important: that project is not the main/startup project of my Visual Studio solution.

like image 846
alapeno Avatar asked Apr 28 '12 22:04

alapeno


People also ask

How do I add embedded resources to Visual Studio?

Open Solution Explorer add files you want to embed. Right click on the files then click on Properties . In Properties window and change Build Action to Embedded Resource . After that you should write the embedded resources to file in order to be able to run it.

How do I open a .resource file?

If you cannot open your RESOURCE file correctly, try to right-click or long-press the file. Then click "Open with" and choose an application. You can also display a RESOURCE file directly in the browser: Just drag the file onto this browser window and drop it.

Where is the resource file in Visual Studio?

At the top right corner you have a searchbox, try typing it there and see if it finds anything. It should now open the new file with the resources designer. Now open the properties pane for that file (right click it in the solution explorer) and make sure it has the following set: Build Action: Embedded resource.


2 Answers

You need to add them here:

  1. Project menu
  2. MyProjectName Properties
  3. Resources tab
  4. "Click here to create resources" (if necessary)
  5. Select Files menu
  6. Add Resource

Now you can access them using MyProjectName.Properties.Resources.Filename

like image 62
jb. Avatar answered Oct 11 '22 20:10

jb.


Make the file as a resource from its properties as:

BuildAction=Compile
like image 41
Kishore Kumar Avatar answered Oct 11 '22 21:10

Kishore Kumar