Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I want to use strings from my resx-files in my application pages. How can I refer to my resource file?

<h2><%$Resources:MyProject,Test_String_Heading%></h2> results in page crash.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

I don't think you can reference it statically like that. Try this instead:

<h2><asp:Literal runat="server" ID="Literal1" Text="<%$Resources:MyProject,Test_String_Heading%>"></asp:Literal></h2>

EDIT: it's $Resources versus &Resources. Thanks for picking that up Bojan!

UPDATE: As noted below the $Resources method of referencing a resource is for global resources. The following should work for resources associated with your solution (...no manual copy of resource files required).

<h2><%=SharePointTest.MyResources.String1%></h2>

All you have to do to make this work is ensure that your resx has its Access Modifier set to Public and use the fully qualified resource name (i.e. namespace.class.resourceid).

share|improve this answer
    
Correct syntax is to use "$" instead of "&". Hence: <h2><asp:Literal runat="server" ID="Literal1" Text="<%$Resources:MyProject,Test_String_Heading%>"></asp:Literal></h2> –  bojan Jul 26 '11 at 13:44
    
When I do so, I get an error: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Resources.MyProject.resources" was correctly embedded or linked into assembly "App_GlobalResources" at compile time, or that all the satellite assemblies required are loadable and fully signed. –  Anatoly Mironov Jul 26 '11 at 14:24
    
Here is a tip how to solve it manually (by copiing resx file to iis virtual dir). But isn't there a way to do it automatically while deploying? –  Anatoly Mironov Jul 26 '11 at 14:33
    
Without seeing the code/project it's hard to say exactly what the problem is. Common issues are namespace mismatches and/or the resoruce file is set to "no code generation". –  Rob D'Oria Jul 26 '11 at 14:35
    
You have to copy it to <iis virtual directory>\App_GlobalResources manually or with a timer job. Infowise and jonleon.blogspot.com provide a solution for that. But you can't replace the mapped resources folder with it. –  Anatoly Mironov Jul 26 '11 at 15:06
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.