4

How do I gain access to .Properties.Resources in a console application? This is to use resource files attached to the solution.

Here's exactly what I can see: everything about the program

The first syntax error isn't the one I'm concerned with (Only assignment, call, increment, decrement, and new object expressions can be used as a statement).

The one that I'm trying to fix is the second: The name 'Properties' does not exist in the current context

Joe
  • 3,804
  • 7
  • 35
  • 55
  • use test.Properties; then it will work; – Jatin Khurana May 20 '13 at 18:31
  • `test.Properties` has exactly the same error. – Joe May 20 '13 at 18:32
  • @Joe.......... u haven't added the Resource file(as I have seen in your Solution Explorer). IN Order to add the Resource file right click on Project file and click on Properties and then Click on Resource from left pane. Click on create Default Resource file – Jatin Khurana May 20 '13 at 18:39

3 Answers3

13

Edited answer (after your edit):

You don't have resources.

Right-Click on 'test' in Solution Explorer -> Add -> New Item -> Resources File

Then double-click on the created file (e.g. Resource1.resx), and take it from there.

Then use it:

string s = Resource1.String1;

Original answer:

Text = Properties.Resources.String1;

For example.

EDIT:

Click on the little triangle next to Properties in Solution Explorer, then do the same for Resources. Then double click Resources.Designer.cs.

Then copy the namespace there like this:

TheNameSpace.Properties.Resources.String1;
ispiro
  • 26,556
  • 38
  • 136
  • 291
  • Typing `Properties` gives me this error: The type or namespace name 'Properties' could not be found (are you missing a using directive or an assembly reference?) – Joe May 20 '13 at 18:15
  • @Joe Is the namespace of the file you're typing in - the default one for that project? – ispiro May 20 '13 at 18:19
  • @Joe Did you type a dot after the word Properties? - Don't just type **Properties** , type all of what I wrote in the answer. – ispiro May 20 '13 at 18:23
  • In `Solution Explorer`, within `Properties`, there's only one file: `AssemblyInfo.cs`. There is no folder called `Resources`. – Joe May 20 '13 at 18:25
  • It's usually a file named "Resources.resx". If you don't have one, then you don't have any resources. – Roger Lipscombe May 20 '13 at 18:27
  • @Joe OK. So you can't access any resource because it doesn't exist! What type of solution are you using? Windows Forms application? If so, it _should_ have one. – ispiro May 20 '13 at 18:28
  • Take a look at the picture above, maybe that will explain more clearly what's going on? – Joe May 20 '13 at 18:29
1

Your application does not appear to have any resources.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • The `example.txt` in the Solution Explorer -- is that a resource? That's what I'm trying to access in code. – Joe May 20 '13 at 18:39
  • Why are you asking _me_ if that's a resource? It's _your_ project! Do you _want_ it to be a resource? – John Saunders May 20 '13 at 18:40
  • 1
    I'm trying to figure out if I'm understanding C# terminology correctly. – Joe May 20 '13 at 18:48
  • It's a file. It would only have anything to do with resources if the "Build Action" in solution explorer was set to "Embedded resource". – John Saunders May 20 '13 at 18:52
0

You need add your file as Resource, open project's Properties, select Resources tab. Then Press Add Resource > Add Existing file. Select your file.

Make sure added resource file has Build Action = Resource

Uzzy
  • 550
  • 3
  • 14