469,341 Members | 7,790 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,341 developers. It's quick & easy.

App_GlobalResources & Resources namespace

I've upgraded a .Net 1.1 web app to 2.0 and am having a heck of a time
getting resources to work again. From what I understand if I move my
strings.resx file into the App_GlobalResources folder I should magically be
able to reference my strings using the syntax Resources.strings.string1.
This isn't working for me. Is there something I'm missing other than moving
the file itself and rebuilding? I get this error:

"The type or namespace name 'strings' does not exist in the namespace
'System.Resources' (are you missing an assembly reference?)"

-Brett-

Mar 21 '06 #1
6 23481


Hi,

Thanks for posting at the newsgroup!

ASP.net 2.0 has introduced one code compilation model, very different from
the ASP.net 1.1. For the resource management, ASP.net 2.0 will generate one
namespace Resources for the resources located under the folder
"App_GlobalResources". For each resource (string, image etc) at the
resource file, ASP.net will dynamically generate the static property for
each.

For example, we can add one Resource.resx file at the web application
project located under App_GlobalResources. Then we define one string called
"MySiteTitle" at the resoruce designer. Then we can write the code below to
access this string resource:
String mysitename = Resources.Resource.MySiteTitle;

The Resources namespace is dynamically generated by ASP.net 2.0. And the
second part of the resource name is the resx file name. If we chnage the
resource name to HappyANiceDayResource.resx, ASP.net 2.0 will dynamically
the correspond name and we can access the string resource as below:
String mysitename = Resources.HappyANiceDayResource.MySiteTitle;

This design will be quite easy for us to locate the resource. For your
application migrated from ASP.net 1.1, I'd suggest please change the code
to locate the resources.

In addition, I'd suggest please this article will be of great help for you
to migrate the application from ASP.net 1.1 to ASP.net 2.0:
ASP.NET 2.0 Migration Overview
http://msdn2.microsoft.com/en-us/library/ms227549.aspx

Please feel free to let me know if you have any further question on this
issue.

Have a nice day!

Best Regards,
Wei-Dong XU
Microsoft Support
---------------------------------------------------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
---------------------------------------------------------------------------
It is my pleasure to be of any assistance.
Mar 21 '06 #2
I appreciate the effort to help me here, but frankly if you'd read my post
you'd see I am aware of how this is supposed to work. I'm saying it is not
working for me. I'm looking for a little assistance on what I might be
doing wrong. Let me give a little more detail.

When VS05 converted my ASP.Net 1.1 app to 2.0 it created the
App_GlobalResources folder and moved my one string resource (resx) file into
it. For some reason I was unable to open the resx file in the designer so I
went ahead and created a new one and copied all of my strings into it (then
deleted the original). My resx file is named strings.en.resx and is located
in the App_GlobalResources subfolder.

In my code-behind file if I try to use the syntax:
Resources.strings.en.mystring I am getting compilation errors stating
'Resources' does not exist in the current context.

So is there something I'm missing here? VS05 does not appear to be creating
the typed dataset for my string file.

-Brett-

""Wei-Dong XU [MSFT]"" <v-****@online.microsoft.com> wrote in message
news:FM**************@TK2MSFTNGXA03.phx.gbl...


Hi,

Thanks for posting at the newsgroup!

ASP.net 2.0 has introduced one code compilation model, very different from
the ASP.net 1.1. For the resource management, ASP.net 2.0 will generate
one
namespace Resources for the resources located under the folder
"App_GlobalResources". For each resource (string, image etc) at the
resource file, ASP.net will dynamically generate the static property for
each.

For example, we can add one Resource.resx file at the web application
project located under App_GlobalResources. Then we define one string
called
"MySiteTitle" at the resoruce designer. Then we can write the code below
to
access this string resource:
String mysitename = Resources.Resource.MySiteTitle;

The Resources namespace is dynamically generated by ASP.net 2.0. And the
second part of the resource name is the resx file name. If we chnage the
resource name to HappyANiceDayResource.resx, ASP.net 2.0 will dynamically
the correspond name and we can access the string resource as below:
String mysitename = Resources.HappyANiceDayResource.MySiteTitle;

This design will be quite easy for us to locate the resource. For your
application migrated from ASP.net 1.1, I'd suggest please change the code
to locate the resources.

In addition, I'd suggest please this article will be of great help for you
to migrate the application from ASP.net 1.1 to ASP.net 2.0:
ASP.NET 2.0 Migration Overview
http://msdn2.microsoft.com/en-us/library/ms227549.aspx

Please feel free to let me know if you have any further question on this
issue.

Have a nice day!

Best Regards,
Wei-Dong XU
Microsoft Support
---------------------------------------------------------------------------
This posting is provided "AS IS" with no warranties, and confers no
rights.
---------------------------------------------------------------------------
It is my pleasure to be of any assistance.

Mar 21 '06 #3
Hi Brett,

As for the ASP.NET 2.0 localization and resource handling, it hasn't change
much from the original one. For the resource file, e.g .resx or .txt file,
their file name should not contain any cultureInfo name(such as "en",
"fr-Fr", this is used for the runtime to idenitity them as the same
resource for a specific language/culture.

For example, if we have the following resource files:

MyResources.strings.resx

MyResources.strings.en.resx

MyResources.strings.fr.resx
They're actually a single resource item, just of different
culture/language. At runtime in the code, we just use the following
statement to retrieve value from the above resource file:
Response.Write(Resources.MyResources.strings.XXXXX )

(no prefix like "en" or "fr" or....)

and which file to use depend on the current thread's UICulture.

For example, if we add the following code to manually set the thread's
CurrentUICulture:

============
protected void Page_Load(object sender, EventArgs e)
{

System.Threading.Thread.CurrentThread.CurrentUICul ture = new
System.Globalization.CultureInfo("fr-FR");

Response.Write(Resources.MyResources.strings.XXXXX )

============

the above code will read the resource string from the
MyResource.strings.fr.resx file.

You can also get some further description in the MSDN document on ASP.NET
global/localization:
#ASP.NET Globalization and Localization
http://msdn2.microsoft.com/en-us/library/c6zyy3s9.aspx

#Walkthrough: Using Resources for Localization with ASP.NET
http://msdn2.microsoft.com/en-us/library/fw69ke6f.aspx

Hope all these help you.
Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Mar 22 '06 #4
It turns out my problem came down to the fact that my resource file was
named simply 'strings.en.resx'. For some reason Visual Studio doesn't deal
with that as documented (in generating the typesafe dataset). If I change
the name to something like MyResources.string.en.resx then everything works
as documented.

This was just one of those crazy bang your head against the wall kindof
problems. I was doing everything as documented but apparently chose a name
that either has special meaning or is involved in a bug of some sort.

Thanks for the help...

-Brett-

"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:tr**************@TK2MSFTNGXA03.phx.gbl...
Hi Brett,

As for the ASP.NET 2.0 localization and resource handling, it hasn't
change
much from the original one. For the resource file, e.g .resx or .txt file,
their file name should not contain any cultureInfo name(such as "en",
"fr-Fr", this is used for the runtime to idenitity them as the same
resource for a specific language/culture.

For example, if we have the following resource files:

MyResources.strings.resx

MyResources.strings.en.resx

MyResources.strings.fr.resx
They're actually a single resource item, just of different
culture/language. At runtime in the code, we just use the following
statement to retrieve value from the above resource file:
Response.Write(Resources.MyResources.strings.XXXXX )

(no prefix like "en" or "fr" or....)

and which file to use depend on the current thread's UICulture.

For example, if we add the following code to manually set the thread's
CurrentUICulture:

============
protected void Page_Load(object sender, EventArgs e)
{

System.Threading.Thread.CurrentThread.CurrentUICul ture = new
System.Globalization.CultureInfo("fr-FR");

Response.Write(Resources.MyResources.strings.XXXXX )

============

the above code will read the resource string from the
MyResource.strings.fr.resx file.

You can also get some further description in the MSDN document on ASP.NET
global/localization:
#ASP.NET Globalization and Localization
http://msdn2.microsoft.com/en-us/library/c6zyy3s9.aspx

#Walkthrough: Using Resources for Localization with ASP.NET
http://msdn2.microsoft.com/en-us/library/fw69ke6f.aspx

Hope all these help you.
Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

Mar 22 '06 #5
Thanks for your followup Brett,

Yes, I admit that the document still need much improvement since it lacks
good and complete samples or explanation on some common scenario. Anyway,
if you meet any problem, please feel free to post here, we will be happy to
be of assistance.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may

learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 23 '06 #6
Hi,
I migrated a web application that was created in VS2003 to VS2005.
I am trying to access migrated resources using Resources.Resurce.Resourcemanager.GetString(resour ceName), but it says "The name 'Resources' does not exist in the current context"

I have encountered this error before, when i migrated a website to VS2005.
But when i add a resx file to project, it automatically added "resources referance" to my website project. And i was able to use my old resx files, with resources namespace.

But when i do this in the new project i migrated, it does not add "resources referance"

From where and how can i add "resources referance" to my project?
May 2 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Geoff Cox | last post: by
4 posts views Thread by António Pinho | last post: by
reply views Thread by Jody Gelowitz | last post: by
1 post views Thread by kurt sune | last post: by
reply views Thread by C. Moya | last post: by
4 posts views Thread by nils.harrison | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.